|
| 1 | +/** |
| 2 | + * Deserialize a signed CIP-8 message from an MPC wallet at BitGo. |
| 3 | + * |
| 4 | + * Copyright 2025, BitGo, Inc. All Rights Reserved. |
| 5 | + */ |
| 6 | +import { BaseCoin } from "@bitgo/statics"; |
| 7 | +import { MessageBuilderFactory, bufferToCoseObjectsOutput } from "@bitgo/sdk-coin-ada"; |
| 8 | + |
| 9 | +async function deserializeSignedCip8MessageHex(): Promise<void> { |
| 10 | + const signedMsgHex = ''; |
| 11 | + |
| 12 | + const coinConfig = { name: 'ada' } as BaseCoin; |
| 13 | + const factory = new MessageBuilderFactory(coinConfig); |
| 14 | + const builder = factory.fromBroadcastString(signedMsgHex); |
| 15 | + const message = await builder.build(); |
| 16 | + |
| 17 | + const payload = message.getPayload(); |
| 18 | + console.log(`Message: ${payload}`); |
| 19 | + |
| 20 | + const address = message.getSigners()[0]; |
| 21 | + console.log(`Signer address: ${address}`); |
| 22 | + |
| 23 | + const signature = message.getSignatures()[0].signature; |
| 24 | + const publicKeyHex = message.getSignatures()[0].publicKey.pub; |
| 25 | + console.log(`Public key hex: ${publicKeyHex}`); |
| 26 | + |
| 27 | + const coseObjectsOutput = await bufferToCoseObjectsOutput(signature); |
| 28 | + |
| 29 | + const coseKey = coseObjectsOutput.manualCoseKeyHex; |
| 30 | + console.log(`Cose key: ${coseKey}`); |
| 31 | + |
| 32 | + const coseSign1 = coseObjectsOutput.manualCoseSign1Hex; |
| 33 | + console.log(`Cose sign1: ${coseSign1}`); |
| 34 | +} |
| 35 | + |
| 36 | +deserializeSignedCip8MessageHex().catch(console.error); |
0 commit comments