@keystonehq/bc-ur-registry-avalanche 0.0.4 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/AvalancheSignRequest.cjs +112 -0
  2. package/dist/AvalancheSignRequest.cjs.map +1 -0
  3. package/dist/AvalancheSignRequest.d.cts +25 -0
  4. package/dist/AvalancheSignRequest.d.cts.map +1 -0
  5. package/dist/AvalancheSignRequest.d.mts +25 -0
  6. package/dist/AvalancheSignRequest.d.mts.map +1 -0
  7. package/dist/AvalancheSignRequest.mjs +77 -0
  8. package/dist/AvalancheSignRequest.mjs.map +1 -0
  9. package/dist/AvalancheSignature.cjs +40 -0
  10. package/dist/AvalancheSignature.cjs.map +1 -0
  11. package/dist/{AvalancheSignature.d.ts → AvalancheSignature.d.cts} +13 -13
  12. package/dist/AvalancheSignature.d.cts.map +1 -0
  13. package/dist/AvalancheSignature.d.mts +13 -0
  14. package/dist/AvalancheSignature.d.mts.map +1 -0
  15. package/dist/AvalancheSignature.mjs +38 -0
  16. package/dist/AvalancheSignature.mjs.map +1 -0
  17. package/dist/AvalancheUtxo.cjs +63 -0
  18. package/dist/AvalancheUtxo.cjs.map +1 -0
  19. package/dist/AvalancheUtxo.d.cts +26 -0
  20. package/dist/AvalancheUtxo.d.cts.map +1 -0
  21. package/dist/AvalancheUtxo.d.mts +26 -0
  22. package/dist/AvalancheUtxo.d.mts.map +1 -0
  23. package/dist/AvalancheUtxo.mjs +61 -0
  24. package/dist/AvalancheUtxo.mjs.map +1 -0
  25. package/dist/RegistryType.cjs +10 -0
  26. package/dist/RegistryType.cjs.map +1 -0
  27. package/dist/{RegistryType.d.ts → RegistryType.d.cts} +7 -5
  28. package/dist/RegistryType.d.cts.map +1 -0
  29. package/dist/RegistryType.d.mts +7 -0
  30. package/dist/RegistryType.d.mts.map +1 -0
  31. package/dist/RegistryType.mjs +8 -0
  32. package/dist/RegistryType.mjs.map +1 -0
  33. package/dist/index.cjs +28 -0
  34. package/dist/index.cjs.map +1 -0
  35. package/dist/index.d.cts +4 -0
  36. package/dist/index.d.cts.map +1 -0
  37. package/dist/index.d.mts +4 -0
  38. package/dist/index.d.mts.map +1 -0
  39. package/dist/index.mjs +10 -0
  40. package/dist/index.mjs.map +1 -0
  41. package/package.json +17 -12
  42. package/src/AvalancheSignRequest.ts +44 -35
  43. package/src/AvalancheUtxo.ts +100 -0
  44. package/src/RegistryType.ts +1 -0
  45. package/dist/AvalancheSignRequest.d.ts +0 -24
  46. package/dist/bc-ur-registry-avalanche.cjs.development.js +0 -126
  47. package/dist/bc-ur-registry-avalanche.cjs.development.js.map +0 -1
  48. package/dist/bc-ur-registry-avalanche.cjs.production.min.js +0 -2
  49. package/dist/bc-ur-registry-avalanche.cjs.production.min.js.map +0 -1
  50. package/dist/bc-ur-registry-avalanche.esm.js +0 -114
  51. package/dist/bc-ur-registry-avalanche.esm.js.map +0 -1
  52. package/dist/index.d.ts +0 -3
  53. package/dist/index.js +0 -8
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExtendedRegistryTypes = void 0;
4
+ const bc_ur_registry_1 = require("@keystonehq/bc-ur-registry");
5
+ exports.ExtendedRegistryTypes = {
6
+ AVALANCHE_SIGN_REQUEST: new bc_ur_registry_1.RegistryType("avax-sign-request", 8301),
7
+ AVALANCHE_SIGNATURE: new bc_ur_registry_1.RegistryType("avax-signature", 8302),
8
+ AVALANCHE_UTXO: new bc_ur_registry_1.RegistryType("avax-utxo", 8303),
9
+ };
10
+ //# sourceMappingURL=RegistryType.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RegistryType.cjs","sourceRoot":"","sources":["../src/RegistryType.ts"],"names":[],"mappings":";;;AAAA,+DAA0D;AAE7C,QAAA,qBAAqB,GAAG;IACnC,sBAAsB,EAAE,IAAI,6BAAY,CAAC,mBAAmB,EAAE,IAAI,CAAC;IACnE,mBAAmB,EAAE,IAAI,6BAAY,CAAC,gBAAgB,EAAE,IAAI,CAAC;IAC7D,cAAc,EAAE,IAAI,6BAAY,CAAC,WAAW,EAAE,IAAI,CAAC;CACpD,CAAC","sourcesContent":["import { RegistryType } from \"@keystonehq/bc-ur-registry\";\n\nexport const ExtendedRegistryTypes = {\n AVALANCHE_SIGN_REQUEST: new RegistryType(\"avax-sign-request\", 8301),\n AVALANCHE_SIGNATURE: new RegistryType(\"avax-signature\", 8302),\n AVALANCHE_UTXO: new RegistryType(\"avax-utxo\", 8303),\n};\n"]}
@@ -1,5 +1,7 @@
1
- import { RegistryType } from "@keystonehq/bc-ur-registry";
2
- export declare const ExtendedRegistryTypes: {
3
- AVALANCHE_SIGN_REQUEST: RegistryType;
4
- AVALANCHE_SIGNATURE: RegistryType;
5
- };
1
+ import { RegistryType } from "@keystonehq/bc-ur-registry";
2
+ export declare const ExtendedRegistryTypes: {
3
+ AVALANCHE_SIGN_REQUEST: RegistryType;
4
+ AVALANCHE_SIGNATURE: RegistryType;
5
+ AVALANCHE_UTXO: RegistryType;
6
+ };
7
+ //# sourceMappingURL=RegistryType.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RegistryType.d.cts","sourceRoot":"","sources":["../src/RegistryType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,mCAAmC;AAE1D,eAAO,MAAM,qBAAqB;;;;CAIjC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { RegistryType } from "@keystonehq/bc-ur-registry";
2
+ export declare const ExtendedRegistryTypes: {
3
+ AVALANCHE_SIGN_REQUEST: RegistryType;
4
+ AVALANCHE_SIGNATURE: RegistryType;
5
+ AVALANCHE_UTXO: RegistryType;
6
+ };
7
+ //# sourceMappingURL=RegistryType.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RegistryType.d.mts","sourceRoot":"","sources":["../src/RegistryType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,mCAAmC;AAE1D,eAAO,MAAM,qBAAqB;;;;CAIjC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import $keystonehqbcurregistry from "@keystonehq/bc-ur-registry";
2
+ const { RegistryType } = $keystonehqbcurregistry;
3
+ export const ExtendedRegistryTypes = {
4
+ AVALANCHE_SIGN_REQUEST: new RegistryType("avax-sign-request", 8301),
5
+ AVALANCHE_SIGNATURE: new RegistryType("avax-signature", 8302),
6
+ AVALANCHE_UTXO: new RegistryType("avax-utxo", 8303),
7
+ };
8
+ //# sourceMappingURL=RegistryType.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RegistryType.mjs","sourceRoot":"","sources":["../src/RegistryType.ts"],"names":[],"mappings":";;AAEA,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,sBAAsB,EAAE,IAAI,YAAY,CAAC,mBAAmB,EAAE,IAAI,CAAC;IACnE,mBAAmB,EAAE,IAAI,YAAY,CAAC,gBAAgB,EAAE,IAAI,CAAC;IAC7D,cAAc,EAAE,IAAI,YAAY,CAAC,WAAW,EAAE,IAAI,CAAC;CACpD,CAAC","sourcesContent":["import { RegistryType } from \"@keystonehq/bc-ur-registry\";\n\nexport const ExtendedRegistryTypes = {\n AVALANCHE_SIGN_REQUEST: new RegistryType(\"avax-sign-request\", 8301),\n AVALANCHE_SIGNATURE: new RegistryType(\"avax-signature\", 8302),\n AVALANCHE_UTXO: new RegistryType(\"avax-utxo\", 8303),\n};\n"]}
package/dist/index.cjs ADDED
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.AvalancheSignature = exports.AvalancheSignRequest = void 0;
18
+ const bc_ur_registry_1 = require("@keystonehq/bc-ur-registry");
19
+ const RegistryType_1 = require("./RegistryType.cjs");
20
+ __exportStar(require("@keystonehq/bc-ur-registry"), exports);
21
+ (0, bc_ur_registry_1.patchTags)(Object.values(RegistryType_1.ExtendedRegistryTypes)
22
+ .filter((rt) => !!rt.getTag())
23
+ .map((rt) => rt.getTag()));
24
+ var AvalancheSignRequest_1 = require("./AvalancheSignRequest.cjs");
25
+ Object.defineProperty(exports, "AvalancheSignRequest", { enumerable: true, get: function () { return AvalancheSignRequest_1.AvalancheSignRequest; } });
26
+ var AvalancheSignature_1 = require("./AvalancheSignature.cjs");
27
+ Object.defineProperty(exports, "AvalancheSignature", { enumerable: true, get: function () { return AvalancheSignature_1.AvalancheSignature; } });
28
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+DAAuD;AACvD,qDAAuD;AACvD,6DAA2C;AAE3C,IAAA,0BAAS,EACP,MAAM,CAAC,MAAM,CAAC,oCAAqB,CAAC;KACjC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC;KAC7B,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,CAAa,CACxC,CAAC;AAEF,mEAA8D;AAArD,4HAAA,oBAAoB,OAAA;AAC7B,+DAA0D;AAAjD,wHAAA,kBAAkB,OAAA","sourcesContent":["import { patchTags } from \"@keystonehq/bc-ur-registry\";\nimport { ExtendedRegistryTypes } from \"./RegistryType\";\nexport * from \"@keystonehq/bc-ur-registry\";\n\npatchTags(\n Object.values(ExtendedRegistryTypes)\n .filter((rt) => !!rt.getTag())\n .map((rt) => rt.getTag()) as number[]\n);\n\nexport { AvalancheSignRequest } from \"./AvalancheSignRequest\";\nexport { AvalancheSignature } from \"./AvalancheSignature\";\n"]}
@@ -0,0 +1,4 @@
1
+ export * from "@keystonehq/bc-ur-registry";
2
+ export { AvalancheSignRequest } from "./AvalancheSignRequest.cjs";
3
+ export { AvalancheSignature } from "./AvalancheSignature.cjs";
4
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,2CAA2C;AAQ3C,OAAO,EAAE,oBAAoB,EAAE,mCAA+B;AAC9D,OAAO,EAAE,kBAAkB,EAAE,iCAA6B"}
@@ -0,0 +1,4 @@
1
+ export * from "@keystonehq/bc-ur-registry";
2
+ export { AvalancheSignRequest } from "./AvalancheSignRequest.mjs";
3
+ export { AvalancheSignature } from "./AvalancheSignature.mjs";
4
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,2CAA2C;AAQ3C,OAAO,EAAE,oBAAoB,EAAE,mCAA+B;AAC9D,OAAO,EAAE,kBAAkB,EAAE,iCAA6B"}
package/dist/index.mjs ADDED
@@ -0,0 +1,10 @@
1
+ import $keystonehqbcurregistry from "@keystonehq/bc-ur-registry";
2
+ const { patchTags } = $keystonehqbcurregistry;
3
+ import { ExtendedRegistryTypes } from "./RegistryType.mjs";
4
+ export * from "@keystonehq/bc-ur-registry";
5
+ patchTags(Object.values(ExtendedRegistryTypes)
6
+ .filter((rt) => !!rt.getTag())
7
+ .map((rt) => rt.getTag()));
8
+ export { AvalancheSignRequest } from "./AvalancheSignRequest.mjs";
9
+ export { AvalancheSignature } from "./AvalancheSignature.mjs";
10
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AACA,OAAO,EAAE,qBAAqB,EAAE,2BAAuB;AACvD,2CAA2C;AAE3C,SAAS,CACP,MAAM,CAAC,MAAM,CAAC,qBAAqB,CAAC;KACjC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC;KAC7B,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,CAAa,CACxC,CAAC;AAEF,OAAO,EAAE,oBAAoB,EAAE,mCAA+B;AAC9D,OAAO,EAAE,kBAAkB,EAAE,iCAA6B","sourcesContent":["import { patchTags } from \"@keystonehq/bc-ur-registry\";\nimport { ExtendedRegistryTypes } from \"./RegistryType\";\nexport * from \"@keystonehq/bc-ur-registry\";\n\npatchTags(\n Object.values(ExtendedRegistryTypes)\n .filter((rt) => !!rt.getTag())\n .map((rt) => rt.getTag()) as number[]\n);\n\nexport { AvalancheSignRequest } from \"./AvalancheSignRequest\";\nexport { AvalancheSignature } from \"./AvalancheSignature\";\n"]}
package/package.json CHANGED
@@ -1,9 +1,17 @@
1
1
  {
2
2
  "name": "@keystonehq/bc-ur-registry-avalanche",
3
- "version": "0.0.4",
3
+ "version": "0.1.0",
4
4
  "description": "bc-ur-registry extension for Avalanche",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.mts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.mjs",
11
+ "require": "./dist/index.cjs",
12
+ "types": "./dist/index.d.mts"
13
+ }
14
+ },
7
15
  "directories": {
8
16
  "lib": "src",
9
17
  "test": "__tests__"
@@ -12,12 +20,6 @@
12
20
  "src",
13
21
  "dist"
14
22
  ],
15
- "scripts": {
16
- "clean": "rm -rf ./dist",
17
- "start": "tsdx watch",
18
- "build": "tsdx build",
19
- "test": "jest --passWithNoTests"
20
- },
21
23
  "publishConfig": {
22
24
  "access": "public"
23
25
  },
@@ -25,13 +27,16 @@
25
27
  "license": "ISC",
26
28
  "dependencies": {
27
29
  "@keystonehq/bc-ur-registry": "^0.6.4",
28
- "buffer": "^6.0.3",
29
30
  "uuid": "^8.3.2"
30
31
  },
31
32
  "devDependencies": {
32
33
  "@babel/preset-typescript": "^7.15.0",
33
34
  "@types/uuid": "^8.3.1",
34
- "tsdx": "^0.14.1",
35
- "typescript": "^4.6.2"
35
+ "typescript": "^5.2.2"
36
+ },
37
+ "scripts": {
38
+ "clean": "rm -rf ./dist",
39
+ "build": "pnpm ts-bridge --project tsconfig.build.json --verbose --clean",
40
+ "test": "jest --passWithNoTests"
36
41
  }
37
42
  }
@@ -3,35 +3,33 @@ import {
3
3
  RegistryItem,
4
4
  extend,
5
5
  DataItemMap,
6
+ CryptoKeypath,
6
7
  } from "@keystonehq/bc-ur-registry";
7
8
  import { ExtendedRegistryTypes } from "./RegistryType";
8
9
  import * as uuid from "uuid";
9
- import { Buffer } from "buffer";
10
+ import { AvalancheUtxo, AvalancheUtxoData } from "./AvalancheUtxo";
10
11
 
11
12
  const { RegistryTypes } = extend;
12
13
 
13
14
  type signRequestProps = {
14
15
  requestId?: Buffer;
15
16
  data: Buffer;
16
- mfp: Buffer;
17
- xpub: string;
18
- walletIndex: number;
17
+ derivationPath: CryptoKeypath;
18
+ utxos: AvalancheUtxo[];
19
19
  };
20
20
 
21
21
  enum Keys {
22
22
  requestId = 1,
23
- signData = 2,
24
- mfp = 3,
25
- xpub = 6,
26
- walletIndex = 7,
23
+ signData,
24
+ derivationPath,
25
+ utxos,
27
26
  }
28
-
29
27
  export class AvalancheSignRequest extends RegistryItem {
30
28
  private requestId?: Buffer;
31
29
  private data: Buffer;
32
- private mfp: Buffer;
33
- private xpub: string;
34
- private walletIndex: number;
30
+ private derivationPath: CryptoKeypath;
31
+ private utxos: AvalancheUtxo[];
32
+
35
33
 
36
34
  getRegistryType = () => ExtendedRegistryTypes.AVALANCHE_SIGN_REQUEST;
37
35
 
@@ -39,13 +37,14 @@ export class AvalancheSignRequest extends RegistryItem {
39
37
  super();
40
38
  this.requestId = args.requestId;
41
39
  this.data = args.data;
42
- this.mfp = args.mfp;
43
- this.xpub = args.xpub;
44
- this.walletIndex = args.walletIndex;
40
+ this.derivationPath = args.derivationPath;
41
+ this.utxos = args.utxos;
45
42
  }
46
43
 
47
44
  public getRequestId = () => this.requestId;
48
45
  public getSignData = () => this.data;
46
+ public getUtxos = () => this.utxos;
47
+ public getDerivationPath = () => this.derivationPath;
49
48
 
50
49
  public toDataItem = () => {
51
50
  const map: DataItemMap = {};
@@ -56,49 +55,59 @@ export class AvalancheSignRequest extends RegistryItem {
56
55
  );
57
56
  }
58
57
 
59
- map[Keys.signData] = this.data;
60
- map[Keys.mfp] = this.mfp.readUInt32BE(0);
61
- map[Keys.xpub] = this.xpub;
62
- map[Keys.walletIndex] = Number(this.walletIndex);
58
+ map[Keys.signData] = Buffer.from(this.data);
59
+ map[Keys.derivationPath] = this.derivationPath;
60
+ map[Keys.utxos] = this.utxos.map((utxo) => {
61
+ const res = utxo.toDataItem();
62
+ res.setTag(utxo.getRegistryType().getTag());
63
+ return res;
64
+ });
63
65
 
64
66
  return new DataItem(map);
65
67
  };
66
68
 
67
69
  public static fromDataItem = (dataItem: DataItem) => {
68
70
  const map = dataItem.getData();
69
- const masterFingerprint = Buffer.alloc(4);
70
- const _masterFingerprint = map[Keys.mfp];
71
- masterFingerprint.writeUInt32BE(_masterFingerprint, 0);
72
71
  const requestId = map[Keys.requestId]
73
72
  ? map[Keys.requestId].getData()
74
73
  : undefined;
75
74
  const data = map[Keys.signData];
76
- const xpub = map[Keys.xpub];
77
- const walletIndex = map[Keys.signData];
75
+ const derivationPath = map[Keys.signData];
76
+ const utxos: AvalancheUtxo[] = map[Keys.utxos].map((utxo: DataItem) =>
77
+ AvalancheUtxo.fromDataItem(utxo)
78
+ );
78
79
 
79
80
  return new AvalancheSignRequest({
80
81
  requestId,
81
82
  data,
82
- xpub,
83
- walletIndex,
84
- mfp: masterFingerprint,
83
+ derivationPath,
84
+ utxos,
85
85
  });
86
86
  };
87
87
 
88
88
  public static constructAvalancheRequest(
89
89
  data: Buffer,
90
- mfp: string,
91
- xpub: string,
92
- walletIndex: number
90
+ derivationPath: CryptoKeypath,
91
+ utxos: AvalancheUtxoData[],
92
+ requestId?: string | Buffer,
93
93
  ) {
94
- const uuidString = uuid.v4();
94
+ let _requestId;
95
+ if (typeof requestId === "string") {
96
+ _requestId = Buffer.from(uuid.parse(requestId) as Uint8Array);
97
+ } else if (requestId instanceof Buffer) {
98
+ _requestId = requestId;
99
+ } else {
100
+ _requestId = Buffer.from(uuid.parse(uuid.v4()) as Uint8Array);
101
+ }
102
+ const avalancheUtxos = utxos.map((utxo) =>
103
+ AvalancheUtxo.constructAvalancheUtxo(utxo)
104
+ );
95
105
 
96
106
  return new AvalancheSignRequest({
97
107
  data,
98
- requestId: Buffer.from(uuid.parse(uuidString) as Uint8Array),
99
- mfp: Buffer.from(mfp, "hex"),
100
- xpub,
101
- walletIndex,
108
+ requestId: _requestId,
109
+ derivationPath,
110
+ utxos: avalancheUtxos,
102
111
  });
103
112
  }
104
113
  }
@@ -0,0 +1,100 @@
1
+ import {
2
+ CryptoKeypath,
3
+ extend,
4
+ DataItem,
5
+ PathComponent,
6
+ RegistryItem,
7
+ DataItemMap,
8
+ } from "@keystonehq/bc-ur-registry";
9
+ import { ExtendedRegistryTypes } from "./RegistryType";
10
+
11
+ const { decodeToDataItem } = extend;
12
+
13
+ enum Keys {
14
+ txid = 1,
15
+ vout,
16
+ path,
17
+ }
18
+
19
+ export interface AvalancheUtxoProps {
20
+ txid: Buffer;
21
+ vout: number;
22
+ path: CryptoKeypath;
23
+ }
24
+
25
+ export interface AvalancheUtxoData {
26
+ txid: string;
27
+ vout: number;
28
+ path: string;
29
+ }
30
+
31
+ export class AvalancheUtxo extends RegistryItem {
32
+ private txid: Buffer;
33
+ private vout: number;
34
+ private path: CryptoKeypath;
35
+
36
+ getRegistryType = () => ExtendedRegistryTypes.AVALANCHE_UTXO;
37
+
38
+ constructor(args: AvalancheUtxoProps) {
39
+ super();
40
+ this.txid = args.txid;
41
+ this.vout = args.vout;
42
+ this.path = args.path;
43
+ }
44
+
45
+ public getTxid = () => this.txid;
46
+ public getVout = () => this.vout;
47
+ public getKeyPath = () => this.path.getPath();
48
+
49
+ public toDataItem = () => {
50
+ const map: DataItemMap = {};
51
+ map[Keys.txid] = this.txid;
52
+ map[Keys.vout] = this.vout;
53
+
54
+ const keyPath = this.path.toDataItem();
55
+ keyPath.setTag(this.path.getRegistryType().getTag());
56
+ map[Keys.path] = keyPath;
57
+
58
+ return new DataItem(map);
59
+ };
60
+
61
+ public static fromDataItem = (dataItem: DataItem) => {
62
+ const map = dataItem.getData();
63
+ const txid = map[Keys.txid];
64
+ const vout = map[Keys.vout];
65
+ const path = CryptoKeypath.fromDataItem(map[Keys.path]);
66
+
67
+ return new AvalancheUtxo({
68
+ txid,
69
+ vout,
70
+ path,
71
+ });
72
+ };
73
+
74
+ public static fromCBOR = (_cborPayload: Buffer) => {
75
+ const dataItem = decodeToDataItem(_cborPayload);
76
+ return AvalancheUtxo.fromDataItem(dataItem);
77
+ };
78
+
79
+ public static constructAvalancheUtxo({
80
+ txid,
81
+ vout,
82
+ path,
83
+ }: AvalancheUtxoData) {
84
+ const paths = path.replace(/[m|M]\//, "").split("/");
85
+ const hdPathObject = new CryptoKeypath(
86
+ paths.map((path) => {
87
+ const index = parseInt(path.replace("'", ""));
88
+ const isHardened = path.endsWith("'");
89
+ return new PathComponent({ index, hardened: isHardened });
90
+ }),
91
+ );
92
+
93
+ return new AvalancheUtxo({
94
+ txid: Buffer.from(txid, "hex"),
95
+ vout,
96
+ path: hdPathObject,
97
+ });
98
+ }
99
+ }
100
+
@@ -3,4 +3,5 @@ import { RegistryType } from "@keystonehq/bc-ur-registry";
3
3
  export const ExtendedRegistryTypes = {
4
4
  AVALANCHE_SIGN_REQUEST: new RegistryType("avax-sign-request", 8301),
5
5
  AVALANCHE_SIGNATURE: new RegistryType("avax-signature", 8302),
6
+ AVALANCHE_UTXO: new RegistryType("avax-utxo", 8303),
6
7
  };
@@ -1,24 +0,0 @@
1
- /// <reference types="node" />
2
- import { DataItem, RegistryItem } from "@keystonehq/bc-ur-registry";
3
- declare type signRequestProps = {
4
- requestId?: Buffer;
5
- data: Buffer;
6
- mfp: Buffer;
7
- xpub: string;
8
- walletIndex: number;
9
- };
10
- export declare class AvalancheSignRequest extends RegistryItem {
11
- private requestId?;
12
- private data;
13
- private mfp;
14
- private xpub;
15
- private walletIndex;
16
- getRegistryType: () => import("@keystonehq/bc-ur-registry").RegistryType;
17
- constructor(args: signRequestProps);
18
- getRequestId: () => Buffer | undefined;
19
- getSignData: () => Buffer;
20
- toDataItem: () => DataItem;
21
- static fromDataItem: (dataItem: DataItem) => AvalancheSignRequest;
22
- static constructAvalancheRequest(data: Buffer, mfp: string, xpub: string, walletIndex: number): AvalancheSignRequest;
23
- }
24
- export {};
@@ -1,126 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var bcUrRegistry = require('@keystonehq/bc-ur-registry');
6
- var uuid = require('uuid');
7
- var buffer = require('buffer');
8
-
9
- const ExtendedRegistryTypes = {
10
- AVALANCHE_SIGN_REQUEST: /*#__PURE__*/new bcUrRegistry.RegistryType("avax-sign-request", 8301),
11
- AVALANCHE_SIGNATURE: /*#__PURE__*/new bcUrRegistry.RegistryType("avax-signature", 8302)
12
- };
13
-
14
- const {
15
- RegistryTypes
16
- } = bcUrRegistry.extend;
17
- var Keys;
18
- (function (Keys) {
19
- Keys[Keys["requestId"] = 1] = "requestId";
20
- Keys[Keys["signData"] = 2] = "signData";
21
- Keys[Keys["mfp"] = 3] = "mfp";
22
- Keys[Keys["xpub"] = 6] = "xpub";
23
- Keys[Keys["walletIndex"] = 7] = "walletIndex";
24
- })(Keys || (Keys = {}));
25
- class AvalancheSignRequest extends bcUrRegistry.RegistryItem {
26
- constructor(args) {
27
- super();
28
- this.getRegistryType = () => ExtendedRegistryTypes.AVALANCHE_SIGN_REQUEST;
29
- this.getRequestId = () => this.requestId;
30
- this.getSignData = () => this.data;
31
- this.toDataItem = () => {
32
- const map = {};
33
- if (this.requestId) {
34
- map[Keys.requestId] = new bcUrRegistry.DataItem(this.requestId, RegistryTypes.UUID.getTag());
35
- }
36
- map[Keys.signData] = this.data;
37
- map[Keys.mfp] = this.mfp.readUInt32BE(0);
38
- map[Keys.xpub] = this.xpub;
39
- map[Keys.walletIndex] = Number(this.walletIndex);
40
- return new bcUrRegistry.DataItem(map);
41
- };
42
- this.requestId = args.requestId;
43
- this.data = args.data;
44
- this.mfp = args.mfp;
45
- this.xpub = args.xpub;
46
- this.walletIndex = args.walletIndex;
47
- }
48
- static constructAvalancheRequest(data, mfp, xpub, walletIndex) {
49
- const uuidString = uuid.v4();
50
- return new AvalancheSignRequest({
51
- data,
52
- requestId: buffer.Buffer.from(uuid.parse(uuidString)),
53
- mfp: buffer.Buffer.from(mfp, "hex"),
54
- xpub,
55
- walletIndex
56
- });
57
- }
58
- }
59
- AvalancheSignRequest.fromDataItem = dataItem => {
60
- const map = dataItem.getData();
61
- const masterFingerprint = buffer.Buffer.alloc(4);
62
- const _masterFingerprint = map[Keys.mfp];
63
- masterFingerprint.writeUInt32BE(_masterFingerprint, 0);
64
- const requestId = map[Keys.requestId] ? map[Keys.requestId].getData() : undefined;
65
- const data = map[Keys.signData];
66
- const xpub = map[Keys.xpub];
67
- const walletIndex = map[Keys.signData];
68
- return new AvalancheSignRequest({
69
- requestId,
70
- data,
71
- xpub,
72
- walletIndex,
73
- mfp: masterFingerprint
74
- });
75
- };
76
-
77
- const {
78
- RegistryTypes: RegistryTypes$1,
79
- decodeToDataItem
80
- } = bcUrRegistry.extend;
81
- var Keys$1;
82
- (function (Keys) {
83
- Keys[Keys["requestId"] = 1] = "requestId";
84
- Keys[Keys["signature"] = 2] = "signature";
85
- })(Keys$1 || (Keys$1 = {}));
86
- class AvalancheSignature extends bcUrRegistry.RegistryItem {
87
- constructor(signature, requestId) {
88
- super();
89
- this.getRegistryType = () => ExtendedRegistryTypes.AVALANCHE_SIGNATURE;
90
- this.getRequestId = () => this.requestId;
91
- this.getSignature = () => this.signature;
92
- this.toDataItem = () => {
93
- const map = {};
94
- if (this.requestId) {
95
- map[Keys$1.requestId] = new bcUrRegistry.DataItem(this.requestId, RegistryTypes$1.UUID.getTag());
96
- }
97
- map[Keys$1.signature] = this.signature;
98
- return new bcUrRegistry.DataItem(map);
99
- };
100
- this.signature = signature;
101
- this.requestId = requestId;
102
- }
103
- }
104
- AvalancheSignature.fromDataItem = dataItem => {
105
- const map = dataItem.getData();
106
- const signature = map[Keys$1.signature];
107
- return new AvalancheSignature(signature);
108
- };
109
- AvalancheSignature.fromCBOR = _cborPayload => {
110
- const dataItem = decodeToDataItem(_cborPayload);
111
- return AvalancheSignature.fromDataItem(dataItem);
112
- };
113
-
114
- bcUrRegistry.patchTags(Object.values(ExtendedRegistryTypes).filter(rt => !!rt.getTag()).map(rt => rt.getTag()));
115
-
116
- Object.keys(bcUrRegistry).forEach(function (k) {
117
- if (k !== 'default') Object.defineProperty(exports, k, {
118
- enumerable: true,
119
- get: function () {
120
- return bcUrRegistry[k];
121
- }
122
- });
123
- });
124
- exports.AvalancheSignRequest = AvalancheSignRequest;
125
- exports.AvalancheSignature = AvalancheSignature;
126
- //# sourceMappingURL=bc-ur-registry-avalanche.cjs.development.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bc-ur-registry-avalanche.cjs.development.js","sources":["../src/RegistryType.ts","../src/AvalancheSignRequest.ts","../src/AvalancheSignature.ts","../src/index.ts"],"sourcesContent":["import { RegistryType } from \"@keystonehq/bc-ur-registry\";\n\nexport const ExtendedRegistryTypes = {\n AVALANCHE_SIGN_REQUEST: new RegistryType(\"avax-sign-request\", 8301),\n AVALANCHE_SIGNATURE: new RegistryType(\"avax-signature\", 8302),\n};\n","import {\n DataItem,\n RegistryItem,\n extend,\n DataItemMap,\n} from \"@keystonehq/bc-ur-registry\";\nimport { ExtendedRegistryTypes } from \"./RegistryType\";\nimport * as uuid from \"uuid\";\nimport { Buffer } from \"buffer\";\n\nconst { RegistryTypes } = extend;\n\ntype signRequestProps = {\n requestId?: Buffer;\n data: Buffer;\n mfp: Buffer;\n xpub: string;\n walletIndex: number;\n};\n\nenum Keys {\n requestId = 1,\n signData = 2,\n mfp = 3,\n xpub = 6,\n walletIndex = 7,\n}\n\nexport class AvalancheSignRequest extends RegistryItem {\n private requestId?: Buffer;\n private data: Buffer;\n private mfp: Buffer;\n private xpub: string;\n private walletIndex: number;\n\n getRegistryType = () => ExtendedRegistryTypes.AVALANCHE_SIGN_REQUEST;\n\n constructor(args: signRequestProps) {\n super();\n this.requestId = args.requestId;\n this.data = args.data;\n this.mfp = args.mfp;\n this.xpub = args.xpub;\n this.walletIndex = args.walletIndex;\n }\n\n public getRequestId = () => this.requestId;\n public getSignData = () => this.data;\n\n public toDataItem = () => {\n const map: DataItemMap = {};\n if (this.requestId) {\n map[Keys.requestId] = new DataItem(\n this.requestId,\n RegistryTypes.UUID.getTag()\n );\n }\n\n map[Keys.signData] = this.data;\n map[Keys.mfp] = this.mfp.readUInt32BE(0);\n map[Keys.xpub] = this.xpub;\n map[Keys.walletIndex] = Number(this.walletIndex);\n\n return new DataItem(map);\n };\n\n public static fromDataItem = (dataItem: DataItem) => {\n const map = dataItem.getData();\n const masterFingerprint = Buffer.alloc(4);\n const _masterFingerprint = map[Keys.mfp];\n masterFingerprint.writeUInt32BE(_masterFingerprint, 0);\n const requestId = map[Keys.requestId]\n ? map[Keys.requestId].getData()\n : undefined;\n const data = map[Keys.signData];\n const xpub = map[Keys.xpub];\n const walletIndex = map[Keys.signData];\n\n return new AvalancheSignRequest({\n requestId,\n data,\n xpub,\n walletIndex,\n mfp: masterFingerprint,\n });\n };\n\n public static constructAvalancheRequest(\n data: Buffer,\n mfp: string,\n xpub: string,\n walletIndex: number\n ) {\n const uuidString = uuid.v4();\n\n return new AvalancheSignRequest({\n data,\n requestId: Buffer.from(uuid.parse(uuidString) as Uint8Array),\n mfp: Buffer.from(mfp, \"hex\"),\n xpub,\n walletIndex,\n });\n }\n}\n","import {\n extend,\n DataItem,\n RegistryItem,\n DataItemMap,\n} from \"@keystonehq/bc-ur-registry\";\nimport { ExtendedRegistryTypes } from \"./RegistryType\";\n\nconst { RegistryTypes, decodeToDataItem } = extend;\n\nenum Keys {\n requestId = 1,\n signature,\n}\n\nexport class AvalancheSignature extends RegistryItem {\n private requestId?: Buffer;\n private signature: Buffer;\n\n getRegistryType = () => ExtendedRegistryTypes.AVALANCHE_SIGNATURE;\n\n constructor(signature: Buffer, requestId?: Buffer) {\n super();\n this.signature = signature;\n this.requestId = requestId;\n }\n\n public getRequestId = () => this.requestId;\n public getSignature = () => this.signature;\n\n public toDataItem = () => {\n const map: DataItemMap = {};\n if (this.requestId) {\n map[Keys.requestId] = new DataItem(\n this.requestId,\n RegistryTypes.UUID.getTag()\n );\n }\n map[Keys.signature] = this.signature;\n return new DataItem(map);\n };\n\n public static fromDataItem = (dataItem: DataItem) => {\n const map = dataItem.getData();\n const signature = map[Keys.signature];\n\n return new AvalancheSignature(signature);\n };\n\n public static fromCBOR = (_cborPayload: Buffer) => {\n const dataItem = decodeToDataItem(_cborPayload);\n return AvalancheSignature.fromDataItem(dataItem);\n };\n}\n","import { patchTags } from \"@keystonehq/bc-ur-registry\";\nimport { ExtendedRegistryTypes } from \"./RegistryType\";\nexport * from \"@keystonehq/bc-ur-registry\";\n\npatchTags(\n Object.values(ExtendedRegistryTypes)\n .filter((rt) => !!rt.getTag())\n .map((rt) => rt.getTag()) as number[]\n);\n\nexport { AvalancheSignRequest } from \"./AvalancheSignRequest\";\nexport { AvalancheSignature } from \"./AvalancheSignature\";\n"],"names":["ExtendedRegistryTypes","AVALANCHE_SIGN_REQUEST","RegistryType","AVALANCHE_SIGNATURE","RegistryTypes","extend","Keys","AvalancheSignRequest","RegistryItem","constructor","args","requestId","data","map","DataItem","UUID","getTag","signData","mfp","readUInt32BE","xpub","walletIndex","Number","constructAvalancheRequest","uuidString","uuid","Buffer","from","dataItem","getData","masterFingerprint","alloc","_masterFingerprint","writeUInt32BE","undefined","decodeToDataItem","AvalancheSignature","signature","_cborPayload","fromDataItem","patchTags","Object","values","filter","rt"],"mappings":";;;;;;;;AAEO,MAAMA,qBAAqB,GAAG;EACnCC,sBAAsB,eAAE,IAAIC,yBAAY,CAAC,mBAAmB,EAAE,IAAI,CAAC;EACnEC,mBAAmB,eAAE,IAAID,yBAAY,CAAC,gBAAgB,EAAE,IAAI;CAC7D;;ACKD,MAAM;EAAEE;CAAe,GAAGC,mBAAM;AAUhC,IAAKC,IAMJ;AAND,WAAKA,IAAI;EACPA,yCAAa;EACbA,uCAAY;EACZA,6BAAO;EACPA,+BAAQ;EACRA,6CAAe;AACjB,CAAC,EANIA,IAAI,KAAJA,IAAI;AAQT,MAAaC,oBAAqB,SAAQC,yBAAY;EASpDC,YAAYC,IAAsB;IAChC,KAAK,EAAE;IAHT,oBAAe,GAAG,MAAMV,qBAAqB,CAACC,sBAAsB;IAW7D,iBAAY,GAAG,MAAM,IAAI,CAACU,SAAS;IACnC,gBAAW,GAAG,MAAM,IAAI,CAACC,IAAI;IAE7B,eAAU,GAAG;MAClB,MAAMC,GAAG,GAAgB,EAAE;MAC3B,IAAI,IAAI,CAACF,SAAS,EAAE;QAClBE,GAAG,CAACP,IAAI,CAACK,SAAS,CAAC,GAAG,IAAIG,qBAAQ,CAChC,IAAI,CAACH,SAAS,EACdP,aAAa,CAACW,IAAI,CAACC,MAAM,EAAE,CAC5B;;MAGHH,GAAG,CAACP,IAAI,CAACW,QAA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GA,SAAS;IAC1B,IAAI,CAAC1B,SAAS,GAAGA,SAAS;;;AAkBdyB,+BAAY,GAAIR,QAAkB;EAC9C,MAAMf,GAAG,GAAGe,QAAQ,CAACC,OAAO,EAAE;EAC9B,MAAMQ,SAAS,GAAGxB,GAAG,CAACP,MAAI,CAAC+B,SAAS,CAAC;EAErC,OAAO,IAAID,kBAAkB,CAACC,SAAS,CAAC;AAC1C,CAAC;AAEaD,2BAAQ,GAAIE,YAAoB;EAC5C,MAAMV,QAAQ,GAAGO,gBAAgB,CAACG,YAAY,CAAC;EAC/C,OAAOF,kBAAkB,CAACG,YAAY,CAACX,QAAQ,CAAC;AAClD,CAAC;;AChDHY,sBAAS,CACPC,MAAM,CAACC,MAAM,CAAC1C,qBAAqB,CAAC,CACjC2C,MAAM,CAAEC,EAAE,IAAK,CAAC,CAACA,EAAE,CAAC5B,MAAM,EAAE,CAAC,CAC7BH,GAAG,CAAE+B,EAAE,IAAKA,EAAE,CAAC5B,MAAM,EAAE,CAAa,CACxC;;;;;;;;;;;;;"}
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@keystonehq/bc-ur-registry"),t=require("uuid"),s=require("buffer");const a={AVALANCHE_SIGN_REQUEST:new e.RegistryType("avax-sign-request",8301),AVALANCHE_SIGNATURE:new e.RegistryType("avax-signature",8302)},{RegistryTypes:r}=e.extend;var u;!function(e){e[e.requestId=1]="requestId",e[e.signData=2]="signData",e[e.mfp=3]="mfp",e[e.xpub=6]="xpub",e[e.walletIndex=7]="walletIndex"}(u||(u={}));class n extends e.RegistryItem{constructor(t){super(),this.getRegistryType=()=>a.AVALANCHE_SIGN_REQUEST,this.getRequestId=()=>this.requestId,this.getSignData=()=>this.data,this.toDataItem=()=>{const t={};return this.requestId&&(t[u.requestId]=new e.DataItem(this.requestId,r.UUID.getTag())),t[u.signData]=this.data,t[u.mfp]=this.mfp.readUInt32BE(0),t[u.xpub]=this.xpub,t[u.walletIndex]=Number(this.walletIndex),new e.DataItem(t)},this.requestId=t.requestId,this.data=t.data,this.mfp=t.mfp,this.xpub=t.xpub,this.walletIndex=t.walletIndex}static constructAvalancheRequest(e,a,r,u){const i=t.v4();return new n({data:e,requestId:s.Buffer.from(t.parse(i)),mfp:s.Buffer.from(a,"hex"),xpub:r,walletIndex:u})}}n.fromDataItem=e=>{const t=e.getData(),a=s.Buffer.alloc(4);a.writeUInt32BE(t[u.mfp],0);const r=t[u.requestId]?t[u.requestId].getData():void 0;return new n({requestId:r,data:t[u.signData],xpub:t[u.xpub],walletIndex:t[u.signData],mfp:a})};const{RegistryTypes:i,decodeToDataItem:I}=e.extend;var d;!function(e){e[e.requestId=1]="requestId",e[e.signature=2]="signature"}(d||(d={}));class g extends e.RegistryItem{constructor(t,s){super(),this.getRegistryType=()=>a.AVALANCHE_SIGNATURE,this.getRequestId=()=>this.requestId,this.getSignature=()=>this.signature,this.toDataItem=()=>{const t={};return this.requestId&&(t[d.requestId]=new e.DataItem(this.requestId,i.UUID.getTag())),t[d.signature]=this.signature,new e.DataItem(t)},this.signature=t,this.requestId=s}}g.fromDataItem=e=>{const t=e.getData();return new g(t[d.signature])},g.fromCBOR=e=>{const t=I(e);return g.fromDataItem(t)},e.patchTags(Object.values(a).filter(e=>!!e.getTag()).map(e=>e.getTag())),Object.keys(e).forEach((function(t){"default"!==t&&Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})})),exports.AvalancheSignRequest=n,exports.AvalancheSignature=g;
2
- //# sourceMappingURL=bc-ur-registry-avalanche.cjs.production.min.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bc-ur-registry-avalanche.cjs.production.min.js","sources":["../src/RegistryType.ts","../src/AvalancheSignRequest.ts","../src/AvalancheSignature.ts","../src/index.ts"],"sourcesContent":["import { RegistryType } from \"@keystonehq/bc-ur-registry\";\n\nexport const ExtendedRegistryTypes = {\n AVALANCHE_SIGN_REQUEST: new RegistryType(\"avax-sign-request\", 8301),\n AVALANCHE_SIGNATURE: new RegistryType(\"avax-signature\", 8302),\n};\n","import {\n DataItem,\n RegistryItem,\n extend,\n DataItemMap,\n} from \"@keystonehq/bc-ur-registry\";\nimport { ExtendedRegistryTypes } from \"./RegistryType\";\nimport * as uuid from \"uuid\";\nimport { Buffer } from \"buffer\";\n\nconst { RegistryTypes } = extend;\n\ntype signRequestProps = {\n requestId?: Buffer;\n data: Buffer;\n mfp: Buffer;\n xpub: string;\n walletIndex: number;\n};\n\nenum Keys {\n requestId = 1,\n signData = 2,\n mfp = 3,\n xpub = 6,\n walletIndex = 7,\n}\n\nexport class AvalancheSignRequest extends RegistryItem {\n private requestId?: Buffer;\n private data: Buffer;\n private mfp: Buffer;\n private xpub: string;\n private walletIndex: number;\n\n getRegistryType = () => ExtendedRegistryTypes.AVALANCHE_SIGN_REQUEST;\n\n constructor(args: signRequestProps) {\n super();\n this.requestId = args.requestId;\n this.data = args.data;\n this.mfp = args.mfp;\n this.xpub = args.xpub;\n this.walletIndex = args.walletIndex;\n }\n\n public getRequestId = () => this.requestId;\n public getSignData = () => this.data;\n\n public toDataItem = () => {\n const map: DataItemMap = {};\n if (this.requestId) {\n map[Keys.requestId] = new DataItem(\n this.requestId,\n RegistryTypes.UUID.getTag()\n );\n }\n\n map[Keys.signData] = this.data;\n map[Keys.mfp] = this.mfp.readUInt32BE(0);\n map[Keys.xpub] = this.xpub;\n map[Keys.walletIndex] = Number(this.walletIndex);\n\n return new DataItem(map);\n };\n\n public static fromDataItem = (dataItem: DataItem) => {\n const map = dataItem.getData();\n const masterFingerprint = Buffer.alloc(4);\n const _masterFingerprint = map[Keys.mfp];\n masterFingerprint.writeUInt32BE(_masterFingerprint, 0);\n const requestId = map[Keys.requestId]\n ? map[Keys.requestId].getData()\n : undefined;\n const data = map[Keys.signData];\n const xpub = map[Keys.xpub];\n const walletIndex = map[Keys.signData];\n\n return new AvalancheSignRequest({\n requestId,\n data,\n xpub,\n walletIndex,\n mfp: masterFingerprint,\n });\n };\n\n public static constructAvalancheRequest(\n data: Buffer,\n mfp: string,\n xpub: string,\n walletIndex: number\n ) {\n const uuidString = uuid.v4();\n\n return new AvalancheSignRequest({\n data,\n requestId: Buffer.from(uuid.parse(uuidString) as Uint8Array),\n mfp: Buffer.from(mfp, \"hex\"),\n xpub,\n walletIndex,\n });\n }\n}\n","import {\n extend,\n DataItem,\n RegistryItem,\n DataItemMap,\n} from \"@keystonehq/bc-ur-registry\";\nimport { ExtendedRegistryTypes } from \"./RegistryType\";\n\nconst { RegistryTypes, decodeToDataItem } = extend;\n\nenum Keys {\n requestId = 1,\n signature,\n}\n\nexport class AvalancheSignature extends RegistryItem {\n private requestId?: Buffer;\n private signature: Buffer;\n\n getRegistryType = () => ExtendedRegistryTypes.AVALANCHE_SIGNATURE;\n\n constructor(signature: Buffer, requestId?: Buffer) {\n super();\n this.signature = signature;\n this.requestId = requestId;\n }\n\n public getRequestId = () => this.requestId;\n public getSignature = () => this.signature;\n\n public toDataItem = () => {\n const map: DataItemMap = {};\n if (this.requestId) {\n map[Keys.requestId] = new DataItem(\n this.requestId,\n RegistryTypes.UUID.getTag()\n );\n }\n map[Keys.signature] = this.signature;\n return new DataItem(map);\n };\n\n public static fromDataItem = (dataItem: DataItem) => {\n const map = dataItem.getData();\n const signature = map[Keys.signature];\n\n return new AvalancheSignature(signature);\n };\n\n public static fromCBOR = (_cborPayload: Buffer) => {\n const dataItem = decodeToDataItem(_cborPayload);\n return AvalancheSignature.fromDataItem(dataItem);\n };\n}\n","import { patchTags } from \"@keystonehq/bc-ur-registry\";\nimport { ExtendedRegistryTypes } from \"./RegistryType\";\nexport * from \"@keystonehq/bc-ur-registry\";\n\npatchTags(\n Object.values(ExtendedRegistryTypes)\n .filter((rt) => !!rt.getTag())\n .map((rt) => rt.getTag()) as number[]\n);\n\nexport { AvalancheSignRequest } from \"./AvalancheSignRequest\";\nexport { AvalancheSignature } from \"./AvalancheSignature\";\n"],"names":["ExtendedRegistryTypes","AVALANCHE_SIGN_REQUEST","RegistryType","AVALANCHE_SIGNATURE","RegistryTypes","extend","Keys","AvalancheSignRequest","RegistryItem","constructor","args","super","this","requestId","data","map","DataItem","UUID","getTag","signData","mfp","readUInt32BE","xpub","walletIndex","Number","[object Object]","uuidString","uuid","Buffer","from","dataItem","getData","masterFingerprint","alloc","writeUInt32BE","undefined","decodeToDataItem","AvalancheSignature","signature","_cborPayload","fromDataItem","patchTags","Object","values","filter","rt"],"mappings":"sJAEO,MAAMA,EAAwB,CACnCC,uBAAwB,IAAIC,eAAa,oBAAqB,MAC9DC,oBAAqB,IAAID,eAAa,iBAAkB,QCMpDE,cAAEA,GAAkBC,SAU1B,IAAKC,GAAL,SAAKA,GACHA,6BACAA,2BACAA,iBACAA,mBACAA,iCALF,CAAKA,IAAAA,aAQQC,UAA6BC,eASxCC,YAAYC,GACVC,QAHFC,qBAAkB,IAAMZ,EAAsBC,uBAWvCW,kBAAe,IAAMA,KAAKC,UAC1BD,iBAAc,IAAMA,KAAKE,KAEzBF,gBAAa,KAClB,MAAMG,EAAmB,GAazB,OAZIH,KAAKC,YACPE,EAAIT,EAAKO,WAAa,IAAIG,WACxBJ,KAAKC,UACLT,EAAca,KAAKC,WAIvBH,EAAIT,EAAKa,UAAYP,KAAKE,KAC1BC,EAAIT,EAAKc,KAAOR,KAAKQ,IAAIC,aAAa,GACtCN,EAAIT,EAAKgB,MAAQV,KAAKU,KACtBP,EAAIT,EAAKiB,aAAeC,OAAOZ,KAAKW,aAE7B,IAAIP,WAASD,IAxBpBH,KAAKC,UAAYH,EAAKG,UACtBD,KAAKE,KAAOJ,EAAKI,KACjBF,KAAKQ,IAAMV,EAAKU,IAChBR,KAAKU,KAAOZ,EAAKY,KACjBV,KAAKW,YAAcb,EAAKa,YA4CnBE,iCACLX,EACAM,EACAE,EACAC,GAEA,MAAMG,EAAaC,OAEnB,OAAO,IAAIpB,EAAqB,CAC9BO,KAAAA,EACAD,UAAWe,SAAOC,KAAKF,QAAWD,IAClCN,IAAKQ,SAAOC,K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