diff --git a/packages/ur-registry-avalanche/__tests__/AvalancheSignRequest.test.ts b/packages/ur-registry-avalanche/__tests__/AvalancheSignRequest.test.ts index 5fc9554..d8ef728 100644 --- a/packages/ur-registry-avalanche/__tests__/AvalancheSignRequest.test.ts +++ b/packages/ur-registry-avalanche/__tests__/AvalancheSignRequest.test.ts @@ -10,12 +10,13 @@ describe("avalanche-sign-request", () => { ); const derivationPath = "m/44'/133'/0'/0/0"; const utxos = []; - + const xfp = '2d0bdabc' const avalancheSignRequest = AvalancheSignRequest.constructAvalancheRequest( avalancheData, derivationPath, - utxos + utxos, + xfp ); const request = AvalancheSignRequest.fromDataItem( diff --git a/packages/ur-registry-avalanche/src/AvalancheSignRequest.ts b/packages/ur-registry-avalanche/src/AvalancheSignRequest.ts index 7e066f4..68b702b 100644 --- a/packages/ur-registry-avalanche/src/AvalancheSignRequest.ts +++ b/packages/ur-registry-avalanche/src/AvalancheSignRequest.ts @@ -4,6 +4,7 @@ import { extend, DataItemMap, CryptoKeypath, + PathComponent, } from "@keystonehq/bc-ur-registry"; import { ExtendedRegistryTypes } from "./RegistryType"; import * as uuid from "uuid"; @@ -87,9 +88,10 @@ export class AvalancheSignRequest extends RegistryItem { public static constructAvalancheRequest( data: Buffer, - derivationPath: CryptoKeypath, + hdPath: string, utxos: AvalancheUtxoData[], - requestId?: string | Buffer, + xfp: string, + requestId?: string | Buffer ) { let _requestId; if (typeof requestId === "string") { @@ -99,14 +101,28 @@ export class AvalancheSignRequest extends RegistryItem { } else { _requestId = Buffer.from(uuid.parse(uuid.v4()) as Uint8Array); } + const avalancheUtxos = utxos.map((utxo) => AvalancheUtxo.constructAvalancheUtxo(utxo) ); + const paths = hdPath.replace(/[m|M]\//, "").split("/"); + const hdpathObject = new CryptoKeypath( + paths.map((path) => { + const index = parseInt(path.replace("'", "")); + let isHardened = false; + if (path.endsWith("'")) { + isHardened = true; + } + return new PathComponent({ index, hardened: isHardened }); + }), + Buffer.from(xfp, "hex") + ); + return new AvalancheSignRequest({ data, requestId: _requestId, - derivationPath, + derivationPath: hdpathObject, utxos: avalancheUtxos, }); }