{"_id":"@amax/amaxwallet-adapters","_rev":"1-e1362f902367125b4227f6eeb465e473","name":"@amax/amaxwallet-adapters","description":"Wallet adapters to help developers interact with Amax wallets using consistent API.","dist-tags":{"latest":"1.1.1"},"versions":{"1.1.0":{"name":"@amax/amaxwallet-adapters","version":"1.1.0","keywords":["armoniax","amaxScan"],"author":{"name":"armoniax"},"license":"MIT","_id":"@amax/amaxwallet-adapters@1.1.0","maintainers":[{"name":"armoniametachain","email":"aplink2022@gmail.com"}],"homepage":"https://github.com/armoniax/amaxjs/tree/main#readme","bugs":{"url":"https://github.com/armoniax/amaxjs/issues"},"dist":{"shasum":"abc7f1e4cb127e79ebd7667cbdc5d3847062d50a","tarball":"https://registry.npmjs.org/@amax/amaxwallet-adapters/-/amaxwallet-adapters-1.1.0.tgz","fileCount":14,"integrity":"sha512-pXqGnd0dnRNfc795HxG1c8/L/lcQsuCTdPs2H8sSvBJby3mYtgHB0zWVfFAJpbOdi60bNYp/rCQ1iHYu+iphsg==","signatures":[{"sig":"MEUCIQDmIfjjXHHuBe/QbdKF3ChjGOp/acapBlg/vk2d6a0nVgIgdcBqCx1yUAj6Rpq/NHREyWzmRiuHThnHpOVuCyoRAA4=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":7653265},"main":"./lib/cjs/index.js","type":"module","_from":"file:amax-amaxwallet-adapters-1.1.0.tgz","types":"./lib/types/index.d.ts","module":"./lib/esm/index.js","engines":{"node":">=16","pnpm":">=7"},"exports":{"types":"./lib/types/index.d.ts","import":"./lib/esm/index.js","require":"./lib/cjs/index.js"},"scripts":{"clean":"shx mkdir -p lib && shx rm -rf lib","package":"shx echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json","build:umd":"node ../../../scripts/build-umd.js"},"_npmUser":{"name":"armoniametachain","email":"aplink2022@gmail.com"},"_resolved":"/private/var/folders/3f/51_3qrs158j01hsttw5lg5940000gn/T/9e159d99e260fa219aa7596dc2013c77/amax-amaxwallet-adapters-1.1.0.tgz","_integrity":"sha512-pXqGnd0dnRNfc795HxG1c8/L/lcQsuCTdPs2H8sSvBJby3mYtgHB0zWVfFAJpbOdi60bNYp/rCQ1iHYu+iphsg==","repository":{"url":"git+https://github.com/armoniax/amaxjs.git#main","type":"git"},"_npmVersion":"10.2.3","description":"Wallet adapters to help developers interact with Amax wallets using consistent API.","directories":{},"sideEffects":false,"_nodeVersion":"20.10.0","dependencies":{"@amax/amaxwallet-adapter-aplink":"^1.1.0","@amax/amaxwallet-adapter-unisat":"^1.1.0","@amax/amaxwallet-adapter-metamask":"^1.1.0","@amax/amaxwallet-adapter-armodillo":"^1.1.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"shx":"^0.3.4"},"_npmOperationalInternal":{"tmp":"tmp/amaxwallet-adapters_1.1.0_1718853149993_0.49448255912882644","host":"s3://npm-registry-packages"}},"1.1.1":{"name":"@amax/amaxwallet-adapters","version":"1.1.1","description":"Wallet adapters to help developers interact with Amax wallets using consistent API.","keywords":["armoniax","amaxScan"],"author":{"name":"armoniax"},"repository":{"type":"git","url":"git+https://github.com/armoniax/amaxjs.git#main"},"license":"MIT","type":"module","sideEffects":false,"engines":{"node":">=16","pnpm":">=7"},"main":"./lib/cjs/index.js","module":"./lib/esm/index.js","types":"./lib/types/index.d.ts","exports":{"require":"./lib/cjs/index.js","import":"./lib/esm/index.js","types":"./lib/types/index.d.ts"},"publishConfig":{"access":"public"},"dependencies":{"@amax/amaxwallet-adapter-unisat":"^1.1.0","@amax/amaxwallet-adapter-armodillo":"^1.1.1","@amax/amaxwallet-adapter-metamask":"^1.1.0","@amax/amaxwallet-adapter-aplink":"^1.1.0"},"devDependencies":{"shx":"^0.3.4"},"scripts":{"clean":"shx mkdir -p lib && shx rm -rf lib","package":"shx echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json","build:umd":"node ../../../scripts/build-umd.js"},"bugs":{"url":"https://github.com/armoniax/amaxjs/issues"},"homepage":"https://github.com/armoniax/amaxjs/tree/main#readme","_id":"@amax/amaxwallet-adapters@1.1.1","_integrity":"sha512-l2awH/TJ61Ta328D00NZfIRctkuV4OoR9eAeFTJPecn3kRCSBANs4+A4SEilx9H7lbdhAu68jUkK+hqeeR1D8w==","_resolved":"/private/var/folders/3f/51_3qrs158j01hsttw5lg5940000gn/T/516e0df4fbbac5fdf92152b312d9b236/amax-amaxwallet-adapters-1.1.1.tgz","_from":"file:amax-amaxwallet-adapters-1.1.1.tgz","_nodeVersion":"20.10.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-l2awH/TJ61Ta328D00NZfIRctkuV4OoR9eAeFTJPecn3kRCSBANs4+A4SEilx9H7lbdhAu68jUkK+hqeeR1D8w==","shasum":"5de20bcea8f8c3a556f2ec028d07edc1ad687dcb","tarball":"https://registry.npmjs.org/@amax/amaxwallet-adapters/-/amaxwallet-adapters-1.1.1.tgz","fileCount":14,"unpackedSize":7655468,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBhHhBIzSrEZj934L01lGL0LpuvDsOB0noRLM0GMh7nfAiA1y014s55O7fNjJCNH7VSWkIkmzZyq3xzo8yjheXX2YA=="}]},"_npmUser":{"name":"armoniametachain","email":"aplink2022@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/amaxwallet-adapters_1.1.1_1719309629286_0.09490811201065874"},"_hasShrinkwrap":false}},"time":{"created":"2024-06-20T03:12:29.927Z","modified":"2024-06-25T10:00:29.654Z","1.1.0":"2024-06-20T03:12:30.253Z","1.1.1":"2024-06-25T10:00:29.454Z"},"maintainers":[{"name":"armoniametachain","email":"aplink2022@gmail.com"}],"author":{"name":"armoniax"},"repository":{"type":"git","url":"git+https://github.com/armoniax/amaxjs.git#main"},"keywords":["armoniax","amaxScan"],"license":"MIT","homepage":"https://github.com/armoniax/amaxjs/tree/main#readme","bugs":{"url":"https://github.com/armoniax/amaxjs/issues"},"readme":"# @amax/amaxwallet-adapters\n\n`@amax/amaxwallet-adapters` provides multiple wallet adapters to help developers connect to Amax wallet.\n\n## Supported wallets\n\nAs `@amax/amaxwallet-adapters` exports adapter of each wallet , you can use this package, or use the individual wallet adapter you want.\n\n| NPM package                                                                                                          | Description                                                                  | Source Code                                                                                          |\n| -------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |\n| [`@amax/amaxwallet-adapters`](https://github.com/armoniax/amaxjs/tree/main/packages/amaxwallet-adapter/packages/adapters/adapters)                           | Includes all the wallet adapters                                             | [View](https://github.com/armoniax/amaxjs/tree/main/packages/amaxwallet-adapter/packages/adapters/adapters)      |\n| [`@amax/amaxwallet-adapter-armodillo`](https://github.com/armoniax/amaxjs/tree/main/packages/amaxwallet-adapter/packages/adapters/wallets/armodillo)           | adapter for [Armadillo](https://chromewebstore.google.com/detail/armadillo/ahkbnfljhaifiikpkhnkeobchonbpjpb?hl=zh-CN&utm_source=ext_sidebar)                            | [View](https://github.com/armoniax/amaxjs/tree/main/packages/amaxwallet-adapter/packages/adapters/wallets/armodillo)      |\n| [`@amax/amaxwallet-adapter-aplink`](https://github.com/armoniax/amaxjs/tree/main/packages/amaxwallet-adapter/packages/adapters/wallets/aplink) | adapter for adapter for [APLink](https://aplink.app/home) | [View](https://github.com/armoniax/amaxjs/tree/main/packages/amaxwallet-adapter/packages/adapters/wallets/aplink) |\n| [`@amax/amaxwallet-adapter-metamask`](https://github.com/armoniax/amaxjs/tree/main/packages/amaxwallet-adapter/packages/adapters/wallets/metamask)     | adapter for [Metamask](https://metamask.io/)                          | [View](https://github.com/armoniax/amaxjs/tree/main/packages/amaxwallet-adapter/packages/adapters/wallets/metamask)   |\n| [`\"@amax/amaxwallet-adapter-unisat`](https://github.com/armoniax/amaxjs/tree/main/packages/amaxwallet-adapter/packages/adapters/wallets/unisat)             | adapter for [UniSat](https://chromewebstore.google.com/detail/ppbibelpcjmhbdihakflkdcoccbgbkpo)                                  | [View](https://github.com/armoniax/amaxjs/tree/main/packages/amaxwallet-adapter/packages/adapters/wallets/unisat)       |\n\n\n## Usage\n\n> If you are working in a typescript project, you must set `skipLibCheck: true` in `tsconfig.json`.\n\n### React\n\nYou can use `@amax/amaxwallet-adapters` in your component. Use `useMemo` to memorize the `adapter` to improve your web performance.\n\n```tsx\nimport { ArmodilloAdapter } from '@amax/amaxwallet-adapters';\n\nfunction App() {\n    const [readyState, setReadyState] = useState(WalletReadyState.NotFound);\n    const [account, setAccount] = useState('');\n    const [signedMessage, setSignedMessage] = useState('');\n\n    const adapter = useMemo(() => new ArmodilloAdapter({permission: 'owner' }), []);\n\n    useEffect(() => {\n        setReadyState(adapter.readyState);\n        setAccount(adapter.account!);\n\n        adapter.on('connect', () => {\n            setAccount(adapter.account!);\n        });\n\n        adapter.on('readyStateChanged', (state) => {\n            setReadyState(state);\n        });\n\n        adapter.on('accountsChanged', (data) => {\n            setAccount(data);\n        });\n\n        adapter.on('disconnect', () => {\n            // when disconnect from wallet\n        });\n        return () => {\n            // remove all listeners when components is destroyed\n            adapter.removeAllListeners();\n        };\n    }, []);\n\n    async function sign() {\n        const res = await adapter!.signMessage('helloworld');\n        setSignedMessage(res);\n    }\n\n    return (\n        <div className=\"App\">\n            <div>readyState: {readyState}</div>\n            <div>current account: {JSON.stringify(account)}</div>\n            <button disabled={adapter.connected} onClick={() => adapter.connect()}>\n                Connect to Amax\n            </button>\n            <button onClick={sign}>sign message</button>\n            <br />\n            SignedMessage: {signedMessage}\n        </div>\n    );\n}\n```\n\nA demo with cdn file can be found [here](https://github.com/armoniax/amaxjs/tree/main/packages/amaxwallet-adapter/demos/react-ui).\n\n\n### Vue\n\nIn Vue, as the `created/mounted` hook just can be executed once, you can init the adapter in `mounted` or `created` hook.\n\n```js\n// vue2.x\nexport default {\n    created() {\n        this.adapter = new ArmodilloAdapter();\n        this.adapter.on('connect', () => {\n            // here you can do something\n        });\n    },\n    beforeDestroy() {\n        this.adapter.removeAllListeners();\n    }\n}\n\n// vue3\nexport default {\n    setup() {\n        onMounted(function() {\n            const adapter = new ArmodilloAdapter();\n            adapter.on('connect', () => {\n                // here you can do something\n            });\n        });\n        onBeforeUnmount(function() {\n            // remove all listeners when components is destroyed\n            adapter.removeAllListeners();\n        });\n        return {};\n    }\n}\n```\n\n## API Reference\n\n### Adapter\n\nThe `Adapter` class defines the common interface for all adapters of specified wallets.\n\n#### Constructor\n\n-   `constructor(config)`: adapter constructor method, an optional config is valid. For detailed config type, refer to the following adapter section.\n\n#### Properties\n\n-   `name`: The name of the adapter.\n-   `url`: The website of the adapter's wallet.\n-   `icon`: The icon of the adapter's wallet.\n-   `readyState`: The wallet's state, which includes three value:\n    -   `Loading`: When adapter is checking if the wallet is available or not.\n    -   `NotFound`: The wallet is not detected in current browser.\n    -   `Found`: The wallet is detected in current browser.\n-   `account`: The account of current account when the adapter is connected.\n-   `connecting`: Whether the adapter is trying to connect to the wallet.\n-   `connected`: Whether the adapter is connected to the wallet.\n\n#### Methods\n\n-   `connect(): Promise<void>`: connect to the wallet.\n-   `disconnect(): Promise<void>`: disconnect to the wallet.\n-   `signMessage(message): Promise<string>`: sign a string, return the signature result.\n-   `transact(actions): Promise<TransactResult>`: push a transaction.\n\n#### Events\n\n`Adapter` extends the `EventEmitter` class in `eventemitter3` package. So you can listen to the events by `adapter.on('connect', function() {})`.\n\nEvents are as follows:\n\n-   `connect(address)`: Emit when adapter is connected to the wallet. The parameter is the address of current account.\n-   `disconnect()`: Emit when adapter is disconnected to the wallet.\n-   `readyStateChanged(state: WalletReadyState)`: Emit when wallet's readyState is changed. The parameter is the state of wallet:\n    ```typescript\n    enum WalletReadyState {\n        /**\n         * Adapter will start to check if wallet exists after adapter instance is created.\n         */\n        Loading = 'Loading',\n        /**\n         * When checking ends and wallet is not found, readyState will be NotFound.\n         */\n        NotFound = 'NotFound',\n        /**\n         * When checking ends and wallet is found, readyState will be Found.\n         */\n        Found = 'Found',\n    }\n    ```\n-   `accountsChanged(address: string, preAddress: string)`: Emit when users change the current selected account in wallet. The parameter is the address of new account.\n-   `chainChanged(chainInfo: ChainInfo)`: Emit when users change the current selected chain in wallet. The parameter is the new network config：\n    ```typescript\n    interface ChainInfo {\n        chainId: string;\n    }\n    ```\n-   `error(WalletError)`: Emit when there are some errors when call the adapter's method. The [WalletError Types] is defined as follows.\n\n### WalletError\n\n`WalletError` is a superclass which defines the error when using adapter.\nAll error types are extended from this class.\nDevelopers can check the error type according to the error instance.\n\n```typescript\ntry {\n    // do something here\n} catch (error: WalletError) {\n    if (error instanceof WalletNotFoundError) {\n        console.log('Wallet is not found');\n    }\n}\n```\n\nAll errors are as follows:\n\n-   `WalletNotFoundError`: Occurs when wallet is not installed.\n-   `WalletNotSelectedError`: Occurs when connect but there is no selected wallet.\n-   `WalletDisconnectedError`: Occurs when wallet is disconnected. Used by some wallets which won't connect automatically when call `signMessage()` or `signTransaction()`.\n-   `WalletConnectionError`: Occurs when try to connect a wallet.\n-   `WalletDisconnectionError`: Occurs when try to disconnect a wallet.\n-   `WalletSignMessageError`: Occurs when call `signMessage()`.\n-   `WalletSignTransactionError`: Occurs when call `signTransaction()`.\n\nFollowing exmaple shows how to get original error info with `WalletError`:\n\n```js\nconst adapter = new ArmodilloAdapter();\ntry {\n    await adapter.connect();\n} catch (e: any) {\n    const originalError = e.error;\n}\n```\n\n<h3>ArmodilloAdapter</h3>\n\n-   `Constructor(config: ArmodilloAdapterConfig)`\n    ```typescript\n    interface ArmodilloAdapterConfig {\n        permission?: string;\n        walletProviderLocalStorageKey?: string;\n    }\n    ```\n\n\n-   **TronLink Doesn't support `disconnect` by DApp**. As ArmodilloAdapter doesn't support disconnect by DApp website, call `adapter.disconnect()` won't disconnect from amax extension really.\n-   **Auto open TronLink app in mobile browser**. If developers call `connect()` method in mobile browser, it will open DApp in TronLink app to get amax wallet.\n","readmeFilename":"README.md"}