Skip to content

Commit 348185c

Browse files
authored
Merge pull request #210 from KeystoneHQ/update-core-wallet-sdk
feat: update constructAvalancheRequest derivationPath parse
2 parents 38057de + a820228 commit 348185c

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

packages/ur-registry-avalanche/__tests__/AvalancheSignRequest.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ describe("avalanche-sign-request", () => {
1010
);
1111
const derivationPath = "m/44'/133'/0'/0/0";
1212
const utxos = [];
13-
13+
const xfp = '2d0bdabc'
1414

1515
const avalancheSignRequest = AvalancheSignRequest.constructAvalancheRequest(
1616
avalancheData,
1717
derivationPath,
18-
utxos
18+
utxos,
19+
xfp
1920
);
2021

2122
const request = AvalancheSignRequest.fromDataItem(

packages/ur-registry-avalanche/src/AvalancheSignRequest.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
extend,
55
DataItemMap,
66
CryptoKeypath,
7+
PathComponent,
78
} from "@keystonehq/bc-ur-registry";
89
import { ExtendedRegistryTypes } from "./RegistryType";
910
import * as uuid from "uuid";
@@ -87,9 +88,10 @@ export class AvalancheSignRequest extends RegistryItem {
8788

8889
public static constructAvalancheRequest(
8990
data: Buffer,
90-
derivationPath: CryptoKeypath,
91+
hdPath: string,
9192
utxos: AvalancheUtxoData[],
92-
requestId?: string | Buffer,
93+
xfp: string,
94+
requestId?: string | Buffer
9395
) {
9496
let _requestId;
9597
if (typeof requestId === "string") {
@@ -99,14 +101,28 @@ export class AvalancheSignRequest extends RegistryItem {
99101
} else {
100102
_requestId = Buffer.from(uuid.parse(uuid.v4()) as Uint8Array);
101103
}
104+
102105
const avalancheUtxos = utxos.map((utxo) =>
103106
AvalancheUtxo.constructAvalancheUtxo(utxo)
104107
);
105108

109+
const paths = hdPath.replace(/[m|M]\//, "").split("/");
110+
const hdpathObject = new CryptoKeypath(
111+
paths.map((path) => {
112+
const index = parseInt(path.replace("'", ""));
113+
let isHardened = false;
114+
if (path.endsWith("'")) {
115+
isHardened = true;
116+
}
117+
return new PathComponent({ index, hardened: isHardened });
118+
}),
119+
Buffer.from(xfp, "hex")
120+
);
121+
106122
return new AvalancheSignRequest({
107123
data,
108124
requestId: _requestId,
109-
derivationPath,
125+
derivationPath: hdpathObject,
110126
utxos: avalancheUtxos,
111127
});
112128
}

0 commit comments

Comments
 (0)