diff --git a/.changeset/nervous-vans-begin.md b/.changeset/nervous-vans-begin.md new file mode 100644 index 000000000..ff50ed410 --- /dev/null +++ b/.changeset/nervous-vans-begin.md @@ -0,0 +1,5 @@ +--- +'@cypherock/sdk-app-btc': patch +--- + +Get address from firmware along with btc get pubkey diff --git a/packages/app-btc/src/operations/getPublicKey/index.ts b/packages/app-btc/src/operations/getPublicKey/index.ts index b7647980a..4986eb99f 100644 --- a/packages/app-btc/src/operations/getPublicKey/index.ts +++ b/packages/app-btc/src/operations/getPublicKey/index.ts @@ -68,13 +68,15 @@ export const getPublicKey = async ( forceStatusUpdate(GetPublicKeyEvent.VERIFY); - const address = await getAddressFromPublicKey( - result.result.publicKey, - params.derivationPath, - ); + const { publicKey } = result.result; + + let { address } = result.result; + if (!address) { + address = await getAddressFromPublicKey(publicKey, params.derivationPath); + } return { - publicKey: result.result.publicKey, + publicKey, address, }; }; diff --git a/packages/app-btc/tests/02.getPublicKey/__fixtures__/valid.ts b/packages/app-btc/tests/02.getPublicKey/__fixtures__/valid.ts index aa6979da3..7aead24fe 100644 --- a/packages/app-btc/tests/02.getPublicKey/__fixtures__/valid.ts +++ b/packages/app-btc/tests/02.getPublicKey/__fixtures__/valid.ts @@ -2,8 +2,79 @@ import { createFlowStatus } from '@cypherock/sdk-utils'; import { IGetPublicKeyTestCase } from './types'; import { Query } from '../../../src/proto/generated/btc/core'; -const requestAddress: IGetPublicKeyTestCase = { - name: 'Request Address', +const requestPublicKeyAndAddress: IGetPublicKeyTestCase = { + name: 'Request Public Key and Address', + params: { + walletId: new Uint8Array([ + 199, 89, 252, 26, 32, 135, 183, 211, 90, 220, 38, 17, 160, 103, 233, 62, + 110, 172, 92, 20, 35, 250, 190, 146, 62, 8, 53, 86, 128, 26, 3, 187, 121, + 64, + ]), + derivationPath: [0x80000000 + 44, 0x80000000, 0x80000000, 0, 0], + }, + queries: [ + { + name: 'Initate query', + data: Uint8Array.from( + Query.encode( + Query.create({ + getPublicKey: { + initiate: { + walletId: new Uint8Array([ + 199, 89, 252, 26, 32, 135, 183, 211, 90, 220, 38, 17, 160, + 103, 233, 62, 110, 172, 92, 20, 35, 250, 190, 146, 62, 8, 53, + 86, 128, 26, 3, 187, 121, 64, + ]), + derivationPath: [0x80000000 + 44, 0x80000000, 0x80000000, 0, 0], + }, + }, + }), + ).finish(), + ), + }, + ], + results: [ + { + name: 'result', + data: new Uint8Array([ + 10, 105, 10, 103, 10, 65, 4, 213, 142, 30, 138, 1, 14, 51, 201, 110, 13, + 175, 117, 169, 164, 195, 10, 80, 185, 29, 225, 243, 140, 234, 62, 2, + 113, 160, 3, 0, 24, 67, 112, 122, 209, 115, 117, 147, 114, 244, 145, + 194, 157, 62, 139, 85, 72, 1, 9, 41, 120, 223, 115, 142, 210, 212, 60, + 96, 7, 197, 15, 51, 21, 132, 183, 18, 34, 49, 57, 118, 56, 112, 101, 49, + 84, 86, 109, 84, 109, 88, 111, 50, 50, 97, 104, 76, 112, 78, 89, 104, + 103, 66, 54, 70, 88, 102, 107, 78, 112, 119, 106, + ]), + statuses: [ + { + flowStatus: createFlowStatus(0, 0), + expectEventCalls: [0], + }, + { + flowStatus: createFlowStatus(1, 0), + expectEventCalls: [1], + }, + { + flowStatus: createFlowStatus(2, 1), + expectEventCalls: [2], + }, + ], + }, + ], + mocks: { eventCalls: [[0], [1], [2], [3], [4]] }, + output: { + publicKey: new Uint8Array([ + 4, 213, 142, 30, 138, 1, 14, 51, 201, 110, 13, 175, 117, 169, 164, 195, + 10, 80, 185, 29, 225, 243, 140, 234, 62, 2, 113, 160, 3, 0, 24, 67, 112, + 122, 209, 115, 117, 147, 114, 244, 145, 194, 157, 62, 139, 85, 72, 1, 9, + 41, 120, 223, 115, 142, 210, 212, 60, 96, 7, 197, 15, 51, 21, 132, 183, + ]), + address: '19v8pe1TVmTmXo22ahLpNYhgB6FXfkNpwj', + }, +}; + +const requestPublicKeyAndDeriveAddress: IGetPublicKeyTestCase = { + name: 'Request Public Key and Derive Address', params: { walletId: new Uint8Array([ 199, 89, 252, 26, 32, 135, 183, 211, 90, 220, 38, 17, 160, 103, 233, 62, @@ -68,6 +139,9 @@ const requestAddress: IGetPublicKeyTestCase = { }, }; -const valid: IGetPublicKeyTestCase[] = [requestAddress]; +const valid: IGetPublicKeyTestCase[] = [ + requestPublicKeyAndAddress, + requestPublicKeyAndDeriveAddress, +]; export default valid; diff --git a/submodules/common b/submodules/common index a66b02d49..5df90fc62 160000 --- a/submodules/common +++ b/submodules/common @@ -1 +1 @@ -Subproject commit a66b02d49b9a6613ac0a499bf56f9d9c3c13d1af +Subproject commit 5df90fc62ba73604ee7f13069a99521a976bc717