diff --git a/js/src/consts.ts b/js/src/consts.ts index 2a11adf..4baf504 100644 --- a/js/src/consts.ts +++ b/js/src/consts.ts @@ -22,6 +22,7 @@ export const INS = { GET_ADDR_SECP256K1: 0x01, SIGN_SECP256K1: 0x02, SIGN_SAPLING: 0x12, + GET_UNIFIED_ADDR_SECP256K1: 0x13, GET_DIV_LIST: 0x09, GET_ADDR_SAPLING_DIV: 0x10, diff --git a/js/src/index.ts b/js/src/index.ts index 3f4db57..89873d9 100644 --- a/js/src/index.ts +++ b/js/src/index.ts @@ -33,7 +33,8 @@ import { TRANSPARENT_PK_LEN, } from './consts' import { - AddressResponse, DfvkResponse, + AddressResponse, + DfvkResponse, DiversifierListResponse, ExtractSpendResponse, FvkResponse, @@ -45,6 +46,7 @@ import { SignResponse, SpendSignatureResponse, TransaparentSignatureResponse, + UfvkResponse, } from './types' import { signSendChunkv1 } from './utils' @@ -70,6 +72,7 @@ export default class ZCashApp extends GenericApp { //////////////////////////////////////////// //////////////////////////////////////////// + async getAddressTransparent(path: string, showInScreen = true): Promise { try { const sentToDevice = serializePath(path) @@ -328,6 +331,45 @@ export default class ZCashApp extends GenericApp { } } + async getUfvk(zip32Account: number): Promise { + try { + const serializedZip32Acc = Buffer.alloc(4) + serializedZip32Acc.writeUInt32LE(zip32Account + 0x80000000, 0) + let responseBuffer = await this.transport.send(CLA, INS.GET_DFVK_SAPLING, 0, 0, serializedZip32Acc, [0x9000]) + let response = processResponse(responseBuffer) + + console.log(response.length()) + + const akRaw = response.readBytes(SAPLING_AK_LEN) + const nkRaw = response.readBytes(SAPLING_NK_LEN) + const ovkRaw = response.readBytes(SAPLING_OVK_LEN) + const dkRaw = response.readBytes(SAPLING_DK_LEN) + + const serializedUnifiedTransparentAcc = serializePath(`m/44'/133'/${zip32Account}'`, [3]) + responseBuffer = await this.transport.send(CLA, INS.GET_UNIFIED_ADDR_SECP256K1, 0, 0, serializedUnifiedTransparentAcc, [0x9000]) + response = processResponse(responseBuffer) + + console.log(response.length()) + + const pkRaw = response.readBytes(TRANSPARENT_PK_LEN) + + return { + sapling: { + akRaw, + nkRaw, + ovkRaw, + dkRaw + }, + transparent: { + pkRaw + }, + orchard: null + } + } catch (error) { + throw processErrorResponse(error) + } + } + //////////////////////////////////// //////////////////////////////////// //////////////////////////////////// diff --git a/js/src/types.ts b/js/src/types.ts index e04d33e..10bf9fd 100644 --- a/js/src/types.ts +++ b/js/src/types.ts @@ -41,6 +41,19 @@ export type DfvkResponse = { dkRaw: Buffer } +export type UfvkResponse = { + sapling: { + akRaw: Buffer + nkRaw: Buffer + ovkRaw: Buffer + dkRaw: Buffer + }, + transparent: { + pkRaw: Buffer + }, + orchard: {} | null +} + export type DiversifierListResponse = { diversifiers: Buffer[] } diff --git a/tests_zemu/snapshots/fl-get-ufvk-expert/00000.png b/tests_zemu/snapshots/fl-get-ufvk-expert/00000.png new file mode 100644 index 0000000..046adfc Binary files /dev/null and b/tests_zemu/snapshots/fl-get-ufvk-expert/00000.png differ diff --git a/tests_zemu/snapshots/fl-get-ufvk-expert/00001.png b/tests_zemu/snapshots/fl-get-ufvk-expert/00001.png new file mode 100644 index 0000000..7d9ff12 Binary files /dev/null and b/tests_zemu/snapshots/fl-get-ufvk-expert/00001.png differ diff --git a/tests_zemu/snapshots/fl-get-ufvk-expert/00002.png b/tests_zemu/snapshots/fl-get-ufvk-expert/00002.png new file mode 100644 index 0000000..7887326 Binary files /dev/null and b/tests_zemu/snapshots/fl-get-ufvk-expert/00002.png differ diff --git a/tests_zemu/snapshots/fl-get-ufvk-expert/00003.png b/tests_zemu/snapshots/fl-get-ufvk-expert/00003.png new file mode 100644 index 0000000..1b062f5 Binary files /dev/null and b/tests_zemu/snapshots/fl-get-ufvk-expert/00003.png differ diff --git a/tests_zemu/snapshots/fl-get-ufvk/00000.png b/tests_zemu/snapshots/fl-get-ufvk/00000.png new file mode 100644 index 0000000..046adfc Binary files /dev/null and b/tests_zemu/snapshots/fl-get-ufvk/00000.png differ diff --git a/tests_zemu/snapshots/fl-get-ufvk/00001.png b/tests_zemu/snapshots/fl-get-ufvk/00001.png new file mode 100644 index 0000000..c07b465 Binary files /dev/null and b/tests_zemu/snapshots/fl-get-ufvk/00001.png differ diff --git a/tests_zemu/snapshots/fl-get-ufvk/00002.png b/tests_zemu/snapshots/fl-get-ufvk/00002.png new file mode 100644 index 0000000..7887326 Binary files /dev/null and b/tests_zemu/snapshots/fl-get-ufvk/00002.png differ diff --git a/tests_zemu/snapshots/fl-get-ufvk/00003.png b/tests_zemu/snapshots/fl-get-ufvk/00003.png new file mode 100644 index 0000000..1b062f5 Binary files /dev/null and b/tests_zemu/snapshots/fl-get-ufvk/00003.png differ diff --git a/tests_zemu/snapshots/s-get-ufvk-expert/00000.png b/tests_zemu/snapshots/s-get-ufvk-expert/00000.png new file mode 100644 index 0000000..8870947 Binary files /dev/null and b/tests_zemu/snapshots/s-get-ufvk-expert/00000.png differ diff --git a/tests_zemu/snapshots/s-get-ufvk-expert/00001.png b/tests_zemu/snapshots/s-get-ufvk-expert/00001.png new file mode 100644 index 0000000..d877827 Binary files /dev/null and b/tests_zemu/snapshots/s-get-ufvk-expert/00001.png differ diff --git a/tests_zemu/snapshots/s-get-ufvk-expert/00002.png b/tests_zemu/snapshots/s-get-ufvk-expert/00002.png new file mode 100644 index 0000000..4555aa5 Binary files /dev/null and b/tests_zemu/snapshots/s-get-ufvk-expert/00002.png differ diff --git a/tests_zemu/snapshots/s-get-ufvk-expert/00003.png b/tests_zemu/snapshots/s-get-ufvk-expert/00003.png new file mode 100644 index 0000000..006c26a Binary files /dev/null and b/tests_zemu/snapshots/s-get-ufvk-expert/00003.png differ diff --git a/tests_zemu/snapshots/s-get-ufvk-expert/00004.png b/tests_zemu/snapshots/s-get-ufvk-expert/00004.png new file mode 100644 index 0000000..7565458 Binary files /dev/null and b/tests_zemu/snapshots/s-get-ufvk-expert/00004.png differ diff --git a/tests_zemu/snapshots/s-get-ufvk/00000.png b/tests_zemu/snapshots/s-get-ufvk/00000.png new file mode 100644 index 0000000..6726bf6 Binary files /dev/null and b/tests_zemu/snapshots/s-get-ufvk/00000.png differ diff --git a/tests_zemu/snapshots/s-get-ufvk/00001.png b/tests_zemu/snapshots/s-get-ufvk/00001.png new file mode 100644 index 0000000..006c26a Binary files /dev/null and b/tests_zemu/snapshots/s-get-ufvk/00001.png differ diff --git a/tests_zemu/snapshots/s-get-ufvk/00002.png b/tests_zemu/snapshots/s-get-ufvk/00002.png new file mode 100644 index 0000000..7565458 Binary files /dev/null and b/tests_zemu/snapshots/s-get-ufvk/00002.png differ diff --git a/tests_zemu/snapshots/sp-get-ufvk-expert/00000.png b/tests_zemu/snapshots/sp-get-ufvk-expert/00000.png new file mode 100644 index 0000000..b82f82a Binary files /dev/null and b/tests_zemu/snapshots/sp-get-ufvk-expert/00000.png differ diff --git a/tests_zemu/snapshots/sp-get-ufvk-expert/00001.png b/tests_zemu/snapshots/sp-get-ufvk-expert/00001.png new file mode 100644 index 0000000..ef254a3 Binary files /dev/null and b/tests_zemu/snapshots/sp-get-ufvk-expert/00001.png differ diff --git a/tests_zemu/snapshots/sp-get-ufvk-expert/00002.png b/tests_zemu/snapshots/sp-get-ufvk-expert/00002.png new file mode 100644 index 0000000..fd5fc62 Binary files /dev/null and b/tests_zemu/snapshots/sp-get-ufvk-expert/00002.png differ diff --git a/tests_zemu/snapshots/sp-get-ufvk-expert/00003.png b/tests_zemu/snapshots/sp-get-ufvk-expert/00003.png new file mode 100644 index 0000000..3b8e2a5 Binary files /dev/null and b/tests_zemu/snapshots/sp-get-ufvk-expert/00003.png differ diff --git a/tests_zemu/snapshots/sp-get-ufvk-expert/00004.png b/tests_zemu/snapshots/sp-get-ufvk-expert/00004.png new file mode 100644 index 0000000..1e4be69 Binary files /dev/null and b/tests_zemu/snapshots/sp-get-ufvk-expert/00004.png differ diff --git a/tests_zemu/snapshots/sp-get-ufvk-expert/00005.png b/tests_zemu/snapshots/sp-get-ufvk-expert/00005.png new file mode 100644 index 0000000..73b5785 Binary files /dev/null and b/tests_zemu/snapshots/sp-get-ufvk-expert/00005.png differ diff --git a/tests_zemu/snapshots/sp-get-ufvk/00000.png b/tests_zemu/snapshots/sp-get-ufvk/00000.png new file mode 100644 index 0000000..b82f82a Binary files /dev/null and b/tests_zemu/snapshots/sp-get-ufvk/00000.png differ diff --git a/tests_zemu/snapshots/sp-get-ufvk/00001.png b/tests_zemu/snapshots/sp-get-ufvk/00001.png new file mode 100644 index 0000000..b71066a Binary files /dev/null and b/tests_zemu/snapshots/sp-get-ufvk/00001.png differ diff --git a/tests_zemu/snapshots/sp-get-ufvk/00002.png b/tests_zemu/snapshots/sp-get-ufvk/00002.png new file mode 100644 index 0000000..1e4be69 Binary files /dev/null and b/tests_zemu/snapshots/sp-get-ufvk/00002.png differ diff --git a/tests_zemu/snapshots/sp-get-ufvk/00003.png b/tests_zemu/snapshots/sp-get-ufvk/00003.png new file mode 100644 index 0000000..73b5785 Binary files /dev/null and b/tests_zemu/snapshots/sp-get-ufvk/00003.png differ diff --git a/tests_zemu/snapshots/st-get-ufvk-expert/00000.png b/tests_zemu/snapshots/st-get-ufvk-expert/00000.png new file mode 100644 index 0000000..ebe3bfe Binary files /dev/null and b/tests_zemu/snapshots/st-get-ufvk-expert/00000.png differ diff --git a/tests_zemu/snapshots/st-get-ufvk-expert/00001.png b/tests_zemu/snapshots/st-get-ufvk-expert/00001.png new file mode 100644 index 0000000..d4e5f9f Binary files /dev/null and b/tests_zemu/snapshots/st-get-ufvk-expert/00001.png differ diff --git a/tests_zemu/snapshots/st-get-ufvk-expert/00002.png b/tests_zemu/snapshots/st-get-ufvk-expert/00002.png new file mode 100644 index 0000000..0c5798b Binary files /dev/null and b/tests_zemu/snapshots/st-get-ufvk-expert/00002.png differ diff --git a/tests_zemu/snapshots/st-get-ufvk-expert/00003.png b/tests_zemu/snapshots/st-get-ufvk-expert/00003.png new file mode 100644 index 0000000..dc1e5da Binary files /dev/null and b/tests_zemu/snapshots/st-get-ufvk-expert/00003.png differ diff --git a/tests_zemu/snapshots/st-get-ufvk/00000.png b/tests_zemu/snapshots/st-get-ufvk/00000.png new file mode 100644 index 0000000..ebe3bfe Binary files /dev/null and b/tests_zemu/snapshots/st-get-ufvk/00000.png differ diff --git a/tests_zemu/snapshots/st-get-ufvk/00001.png b/tests_zemu/snapshots/st-get-ufvk/00001.png new file mode 100644 index 0000000..7c92957 Binary files /dev/null and b/tests_zemu/snapshots/st-get-ufvk/00001.png differ diff --git a/tests_zemu/snapshots/st-get-ufvk/00002.png b/tests_zemu/snapshots/st-get-ufvk/00002.png new file mode 100644 index 0000000..0c5798b Binary files /dev/null and b/tests_zemu/snapshots/st-get-ufvk/00002.png differ diff --git a/tests_zemu/snapshots/st-get-ufvk/00003.png b/tests_zemu/snapshots/st-get-ufvk/00003.png new file mode 100644 index 0000000..dc1e5da Binary files /dev/null and b/tests_zemu/snapshots/st-get-ufvk/00003.png differ diff --git a/tests_zemu/snapshots/x-get-ufvk-expert/00000.png b/tests_zemu/snapshots/x-get-ufvk-expert/00000.png new file mode 100644 index 0000000..b82f82a Binary files /dev/null and b/tests_zemu/snapshots/x-get-ufvk-expert/00000.png differ diff --git a/tests_zemu/snapshots/x-get-ufvk-expert/00001.png b/tests_zemu/snapshots/x-get-ufvk-expert/00001.png new file mode 100644 index 0000000..ef254a3 Binary files /dev/null and b/tests_zemu/snapshots/x-get-ufvk-expert/00001.png differ diff --git a/tests_zemu/snapshots/x-get-ufvk-expert/00002.png b/tests_zemu/snapshots/x-get-ufvk-expert/00002.png new file mode 100644 index 0000000..fd5fc62 Binary files /dev/null and b/tests_zemu/snapshots/x-get-ufvk-expert/00002.png differ diff --git a/tests_zemu/snapshots/x-get-ufvk-expert/00003.png b/tests_zemu/snapshots/x-get-ufvk-expert/00003.png new file mode 100644 index 0000000..3b8e2a5 Binary files /dev/null and b/tests_zemu/snapshots/x-get-ufvk-expert/00003.png differ diff --git a/tests_zemu/snapshots/x-get-ufvk-expert/00004.png b/tests_zemu/snapshots/x-get-ufvk-expert/00004.png new file mode 100644 index 0000000..1e4be69 Binary files /dev/null and b/tests_zemu/snapshots/x-get-ufvk-expert/00004.png differ diff --git a/tests_zemu/snapshots/x-get-ufvk-expert/00005.png b/tests_zemu/snapshots/x-get-ufvk-expert/00005.png new file mode 100644 index 0000000..73b5785 Binary files /dev/null and b/tests_zemu/snapshots/x-get-ufvk-expert/00005.png differ diff --git a/tests_zemu/snapshots/x-get-ufvk/00000.png b/tests_zemu/snapshots/x-get-ufvk/00000.png new file mode 100644 index 0000000..b82f82a Binary files /dev/null and b/tests_zemu/snapshots/x-get-ufvk/00000.png differ diff --git a/tests_zemu/snapshots/x-get-ufvk/00001.png b/tests_zemu/snapshots/x-get-ufvk/00001.png new file mode 100644 index 0000000..b71066a Binary files /dev/null and b/tests_zemu/snapshots/x-get-ufvk/00001.png differ diff --git a/tests_zemu/snapshots/x-get-ufvk/00002.png b/tests_zemu/snapshots/x-get-ufvk/00002.png new file mode 100644 index 0000000..1e4be69 Binary files /dev/null and b/tests_zemu/snapshots/x-get-ufvk/00002.png differ diff --git a/tests_zemu/snapshots/x-get-ufvk/00003.png b/tests_zemu/snapshots/x-get-ufvk/00003.png new file mode 100644 index 0000000..73b5785 Binary files /dev/null and b/tests_zemu/snapshots/x-get-ufvk/00003.png differ diff --git a/tests_zemu/tests/keys.test.ts b/tests_zemu/tests/keys.test.ts index 806de98..48964cf 100644 --- a/tests_zemu/tests/keys.test.ts +++ b/tests_zemu/tests/keys.test.ts @@ -293,6 +293,52 @@ describe('Get_keys', function () { await sim.close() } }) + + test.concurrent.each(models)('Get ufvk', async function (m) { + const sim = new Zemu(m.path) + try { + await sim.start({ + ...defaultOptions(m, true), + approveKeyword: isTouchDevice(m.name) ? 'Approve' : '', + approveAction: ButtonKind.ApproveTapButton + }) + + const app = new ZCashApp(sim.getTransport()) + + const account = 1000 + const ufvkreq = app.getUfvk(account) + + await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot()) + await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-get-ufvk`) + + const ufvk = await ufvkreq + + console.log(ufvk) + + const expected_akRaw = '0bbb1d4bfe70a4f4fc762e2f980ab7c600a060c28410ccd03972931fe310f2a5' + const akRaw = ufvk.sapling.akRaw?.toString('hex') + expect(akRaw).toEqual(expected_akRaw) + + const expected_nkRaw = '9f552de44e5c38db16de3165aaa4627e352e00b6863dd627cc58df02a39deec7' + const nkRaw = ufvk.sapling.nkRaw?.toString('hex') + expect(nkRaw).toEqual(expected_nkRaw) + + const expected_ovkRaw = '199be731acfa8bf5d525eade16451edf6e818f27db0164ff1f428bd8bf432f69' + const ovkRaw = ufvk.sapling.ovkRaw?.toString('hex') + expect(ovkRaw).toEqual(expected_ovkRaw) + + const expected_dkRaw = '702c87a33c31670b463df27f43ad02942f68ef9071d5547b0ead7b5ae425b079' + const dkRaw = ufvk.sapling.dkRaw?.toString('hex') + expect(dkRaw).toEqual(expected_dkRaw) + + const expected_pkRaw = '025b92d7edb1d5acaa9e4eafd9c220d0d4ca2d63fcfd464ca95b9329d91d98cb5b' + const pkRaw = ufvk.transparent.pkRaw?.toString('hex') + expect(pkRaw).toEqual(expected_pkRaw) + + } finally { + await sim.close() + } + }) }) @@ -443,6 +489,54 @@ describe('Get_keys', function () { await sim.close() } }) + + test.concurrent.each(models)('Get ufvk', async function (m) { + const sim = new Zemu(m.path) + try { + await sim.start({ + ...defaultOptions(m, true), + approveKeyword: isTouchDevice(m.name) ? 'Approve' : '', + approveAction: ButtonKind.ApproveTapButton + }) + + await sim.toggleExpertMode() + + const app = new ZCashApp(sim.getTransport()) + + const account = 1000 + const ufvkreq = app.getUfvk(account) + + await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot()) + await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-get-ufvk-expert`) + + const ufvk = await ufvkreq + + console.log(ufvk) + + const expected_akRaw = '0bbb1d4bfe70a4f4fc762e2f980ab7c600a060c28410ccd03972931fe310f2a5' + const akRaw = ufvk.sapling.akRaw?.toString('hex') + expect(akRaw).toEqual(expected_akRaw) + + const expected_nkRaw = '9f552de44e5c38db16de3165aaa4627e352e00b6863dd627cc58df02a39deec7' + const nkRaw = ufvk.sapling.nkRaw?.toString('hex') + expect(nkRaw).toEqual(expected_nkRaw) + + const expected_ovkRaw = '199be731acfa8bf5d525eade16451edf6e818f27db0164ff1f428bd8bf432f69' + const ovkRaw = ufvk.sapling.ovkRaw?.toString('hex') + expect(ovkRaw).toEqual(expected_ovkRaw) + + const expected_dkRaw = '702c87a33c31670b463df27f43ad02942f68ef9071d5547b0ead7b5ae425b079' + const dkRaw = ufvk.sapling.dkRaw?.toString('hex') + expect(dkRaw).toEqual(expected_dkRaw) + + const expected_pkRaw = '025b92d7edb1d5acaa9e4eafd9c220d0d4ca2d63fcfd464ca95b9329d91d98cb5b' + const pkRaw = ufvk.transparent.pkRaw?.toString('hex') + expect(pkRaw).toEqual(expected_pkRaw) + + } finally { + await sim.close() + } + }) }) })