Created
May 14, 2024 22:00
-
-
Save mikedotexe/ba9ef3e7c84826e59700f39636cef20f to your computer and use it in GitHub Desktop.
Get MPC signature pieces from a transaction hash, like one returned from MyNEARWallet as a URL param
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // run with "node get-mpc-signature-from-tx-hash.js" or whatever name | |
| const { connect, keyStores } = require('near-api-js') | |
| const mockKeyStore = new keyStores.InMemoryKeyStore() | |
| const nearConfig = { | |
| keyStore: mockKeyStore, | |
| networkId: 'testnet', | |
| nodeUrl: 'https://archival-rpc.testnet.near.org', | |
| } | |
| const start = async () => { | |
| const near = await connect(nearConfig) | |
| const jsonProvider = near.connection.provider | |
| const txResult = await jsonProvider.txStatus('AaqDJeiXcwRgE1FxoZqjRXUrdodWYSvh7rAiTQVoUGEZ', 'mike.testnet') | |
| console.log('txResult.status', txResult.status) | |
| console.log('\nNote: the previous log shows the "status" key. More details are available.') | |
| if (Object.keys(txResult.status).length === 1 && 'SuccessValue' in txResult.status) { | |
| const successValue = txResult.status.SuccessValue | |
| const decodedValue = Buffer.from(successValue, 'base64').toString('utf-8') | |
| console.log('Decoded SuccessValue:\n') | |
| // If this transaction hash points to an MPC signature response, | |
| // it will be an array of two elements that need to be joined, like here: | |
| // https://github.com/Pessina/near-sandbox/blob/0680809ef19b66be184adb74f7d2f3fdc38ae8e0/utils/chain/Bitcoin.tsx#L247-L272 | |
| console.log(decodedValue) | |
| } else { | |
| console.log('SuccessValue is either missing or there are other keys present.') | |
| } | |
| } | |
| // Calls start function | |
| (() => start())() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment