# idm-bridge-postmsg

> The postMessage bridge to be used by both IDM Wallets and IDM Clients

Latest version **0.3.2** (published 2019-06-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install idm-bridge-postmsg
pnpm add idm-bridge-postmsg
yarn add idm-bridge-postmsg
bun add idm-bridge-postmsg
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.2 |
| Published | 2019-06-22 |
| First published | 2019-06-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 76.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | André Cruz |
| Maintainers | satazor |
| Keywords | idm, bridge, postmessage, post-message, postmsg, iframe, window |

## Links

- npm: https://www.npmjs.com/package/idm-bridge-postmsg
- Repository: https://github.com/ipfs-shipyard/js-idm-bridge-postmsg
- Homepage: https://github.com/ipfs-shipyard/js-idm-bridge-postmsg#readme
- Issues: https://github.com/ipfs-shipyard/js-idm-bridge-postmsg/issues
- npm.io page: https://npm.io/package/idm-bridge-postmsg

## Dependencies (5)

- [lodash](https://npm.io/package/lodash.md) ^4.17.11
- [p-timeout](https://npm.io/package/p-timeout.md) ^3.1.0
- [postmsg-rpc](https://npm.io/package/postmsg-rpc.md) ^2.4.0
- [p-cancelable](https://npm.io/package/p-cancelable.md) ^2.0.0
- [pico-signals](https://npm.io/package/pico-signals.md) ^1.0.0

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.3.2 (latest) — 2019-06-22
- 0.3.1 — 2019-06-22
- 0.3.0 — 2019-06-21
- 0.2.8 — 2019-06-20
- 0.2.7 — 2019-06-19
- 0.2.6 — 2019-06-19
- 0.2.5 — 2019-06-19
- 0.2.4 — 2019-06-18
- 0.2.3 — 2019-06-17
- 0.2.2 — 2019-06-17
- 0.2.1 — 2019-06-16
- 0.2.0 — 2019-06-15
- 0.1.0 — 2019-06-08

## README

# idm-bridge-postmsg

[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][codecov-image]][codecov-url] [![Dependency status][david-dm-image]][david-dm-url] [![Dev Dependency status][david-dm-dev-image]][david-dm-dev-url]

[npm-url]:https://npmjs.org/package/idm-bridge-postmsg
[downloads-image]:http://img.shields.io/npm/dm/idm-bridge-postmsg.svg
[npm-image]:http://img.shields.io/npm/v/idm-bridge-postmsg.svg
[travis-url]:https://travis-ci.org/ipfs-shipyard/js-idm-bridge-postmsg
[travis-image]:http://img.shields.io/travis/ipfs-shipyard/js-idm-bridge-postmsg/master.svg
[codecov-url]:https://codecov.io/gh/ipfs-shipyard/js-idm-bridge-postmsg
[codecov-image]:https://img.shields.io/codecov/c/github/ipfs-shipyard/js-idm-bridge-postmsg/master.svg
[david-dm-url]:https://david-dm.org/ipfs-shipyard/js-idm-bridge-postmsg
[david-dm-image]:https://img.shields.io/david/ipfs-shipyard/js-idm-bridge-postmsg.svg
[david-dm-dev-url]:https://david-dm.org/ipfs-shipyard/js-idm-bridge-postmsg?type=dev
[david-dm-dev-image]:https://img.shields.io/david/dev/ipfs-shipyard/js-idm-bridge-postmsg.svg

The [postMessage](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage) bridge to be used by both IDM Wallets and IDM Clients.


## Installation

```sh
$ npm install idm-bridge-postmsg
```

This library is written in modern JavaScript and is published in both CommonJS and ES module transpiled variants. If you target older browsers please make sure to transpile accordingly.


## Usage

**On the client-side of the bridge:**

```js
import { createClientSide } from 'idm-bridge-postmsg';

const app = {
    name: 'My app name',
    iconUrl: 'https://my.app.com/favicon.png',
    homepageUrl: 'https://my.app.com',
};

const idmWalletUrl = 'http://nomios.io';

await (async () => {
    const clientSide = await createClientSide(app, idmWalletUrl);
})();
```

**On the mediator-side of the bridge (operating on the wallet domain):**

```js
import { createMediatorSide } from 'idm-bridge-postmsg';

await (async () => {
    const options = {
        minWidth: 500 // Defaults to 620
        minHeight: 630 // Defaults to 700
    };

    const mediatorSide = await createMediatorSide(options);

    mediatorSide.setPrompts({
        unlock: ({ pristine, lockTypes, unlockFn }) => {
            // Show the lock screen and unlock with `unlockFn(lockType, input)`

            // response = { ok };
            return response;
        },
        authenticate: async ({ app, identities }) => {
            // Show a prompt to either accept or deny
            const response = await promptToAcceptAndChooseIdentity(app, identities);

            // response = { ok, identityId };
            return response;
        },
        sign: async ({ app, identity, data }) => {
            // Show a prompt to either accept or deny
            const response = await promptToAcceptSigning(app, identity, data);

            // response = { ok };
            return response;
        },
    });
})();
```

**On the wallet-side of the bridge:**

```js
import { createWalletSide } from 'idm-bridge-postmsg';
import createIdmWallet from 'idm-wallet';

await (async () => {
    const idmWallet = await createIdmWallet();
    const walletSide = await createWalletSide(idmWallet);
})();
```

*NOTE*: To know if you either must use `createMediatorSide` or `createWalletSide` you may use the `hasParent` function:

```js
import { hasParent } from 'idm-bridge-postmsg';

if (hasParent()) {
    // Create mediator side
} else {
    // Create wallet side
}
```


## API

This library is following closely the [IDM Wallet Specification](https://github.com/ipfs-shipyard/pm-idm/blob/master/docs/idm-spec.md).

We will be providing proper API documentation once the both this library and the specification mature.


## Tests

```sh
$ npm test
$ npm test -- --watch # during development
```


## License

Released under the [MIT License](http://www.opensource.org/licenses/mit-license.php).

---
_Source: https://npm.io/package/idm-bridge-postmsg · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
