@keystonehq/bc-ur-registry-avalanche 0.0.3 → 0.0.5
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.
- package/dist/AvalancheSignRequest.d.ts +8 -1
- package/dist/AvalancheSignature.d.ts +13 -0
- package/dist/RegistryType.d.ts +1 -0
- package/dist/bc-ur-registry-avalanche.cjs.development.js +93 -5
- package/dist/bc-ur-registry-avalanche.cjs.development.js.map +1 -1
- package/dist/bc-ur-registry-avalanche.cjs.production.min.js +1 -1
- package/dist/bc-ur-registry-avalanche.cjs.production.min.js.map +1 -1
- package/dist/bc-ur-registry-avalanche.esm.js +95 -8
- package/dist/bc-ur-registry-avalanche.esm.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/package.json +1 -2
- package/src/AvalancheSignRequest.ts +80 -7
- package/src/AvalancheSignature.ts +54 -0
- package/src/RegistryType.ts +1 -0
- package/src/index.ts +1 -0
|
@@ -3,15 +3,22 @@ import { DataItem, RegistryItem } from "@keystonehq/bc-ur-registry";
|
|
|
3
3
|
declare type signRequestProps = {
|
|
4
4
|
requestId?: Buffer;
|
|
5
5
|
data: Buffer;
|
|
6
|
+
mfp: Buffer;
|
|
7
|
+
xpub: string;
|
|
8
|
+
walletIndex: number;
|
|
6
9
|
};
|
|
7
10
|
export declare class AvalancheSignRequest extends RegistryItem {
|
|
8
11
|
private requestId?;
|
|
9
12
|
private data;
|
|
13
|
+
private mfp;
|
|
14
|
+
private xpub;
|
|
15
|
+
private walletIndex;
|
|
10
16
|
getRegistryType: () => import("@keystonehq/bc-ur-registry").RegistryType;
|
|
11
17
|
constructor(args: signRequestProps);
|
|
12
18
|
getRequestId: () => Buffer | undefined;
|
|
13
19
|
getSignData: () => Buffer;
|
|
14
20
|
toDataItem: () => DataItem;
|
|
15
|
-
static
|
|
21
|
+
static fromDataItem: (dataItem: DataItem) => AvalancheSignRequest;
|
|
22
|
+
static constructAvalancheRequest(data: Buffer, mfp: string, xpub: string, walletIndex: number, requestId?: string | Buffer): AvalancheSignRequest;
|
|
16
23
|
}
|
|
17
24
|
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { DataItem, RegistryItem } from "@keystonehq/bc-ur-registry";
|
|
3
|
+
export declare class AvalancheSignature extends RegistryItem {
|
|
4
|
+
private requestId?;
|
|
5
|
+
private signature;
|
|
6
|
+
getRegistryType: () => import("@keystonehq/bc-ur-registry").RegistryType;
|
|
7
|
+
constructor(signature: Buffer, requestId?: Buffer);
|
|
8
|
+
getRequestId: () => Buffer | undefined;
|
|
9
|
+
getSignature: () => Buffer;
|
|
10
|
+
toDataItem: () => DataItem;
|
|
11
|
+
static fromDataItem: (dataItem: DataItem) => AvalancheSignature;
|
|
12
|
+
static fromCBOR: (_cborPayload: Buffer) => AvalancheSignature;
|
|
13
|
+
}
|
package/dist/RegistryType.d.ts
CHANGED
|
@@ -4,12 +4,23 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var bcUrRegistry = require('@keystonehq/bc-ur-registry');
|
|
6
6
|
var uuid = require('uuid');
|
|
7
|
-
var buffer = require('buffer');
|
|
8
7
|
|
|
9
8
|
const ExtendedRegistryTypes = {
|
|
10
|
-
AVALANCHE_SIGN_REQUEST: /*#__PURE__*/new bcUrRegistry.RegistryType("avax-sign-request", 8301)
|
|
9
|
+
AVALANCHE_SIGN_REQUEST: /*#__PURE__*/new bcUrRegistry.RegistryType("avax-sign-request", 8301),
|
|
10
|
+
AVALANCHE_SIGNATURE: /*#__PURE__*/new bcUrRegistry.RegistryType("avax-signature", 8302)
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
const {
|
|
14
|
+
RegistryTypes
|
|
15
|
+
} = bcUrRegistry.extend;
|
|
16
|
+
var Keys;
|
|
17
|
+
(function (Keys) {
|
|
18
|
+
Keys[Keys["requestId"] = 1] = "requestId";
|
|
19
|
+
Keys[Keys["signData"] = 2] = "signData";
|
|
20
|
+
Keys[Keys["mfp"] = 3] = "mfp";
|
|
21
|
+
Keys[Keys["xpub"] = 6] = "xpub";
|
|
22
|
+
Keys[Keys["walletIndex"] = 7] = "walletIndex";
|
|
23
|
+
})(Keys || (Keys = {}));
|
|
13
24
|
class AvalancheSignRequest extends bcUrRegistry.RegistryItem {
|
|
14
25
|
constructor(args) {
|
|
15
26
|
super();
|
|
@@ -17,18 +28,94 @@ class AvalancheSignRequest extends bcUrRegistry.RegistryItem {
|
|
|
17
28
|
this.getRequestId = () => this.requestId;
|
|
18
29
|
this.getSignData = () => this.data;
|
|
19
30
|
this.toDataItem = () => {
|
|
20
|
-
|
|
31
|
+
const map = {};
|
|
32
|
+
if (this.requestId) {
|
|
33
|
+
map[Keys.requestId] = new bcUrRegistry.DataItem(this.requestId, RegistryTypes.UUID.getTag());
|
|
34
|
+
}
|
|
35
|
+
map[Keys.signData] = Buffer.from(this.data);
|
|
36
|
+
map[Keys.mfp] = this.mfp.readUInt32BE(0);
|
|
37
|
+
map[Keys.xpub] = this.xpub;
|
|
38
|
+
map[Keys.walletIndex] = Number(this.walletIndex);
|
|
39
|
+
return new bcUrRegistry.DataItem(map);
|
|
21
40
|
};
|
|
22
41
|
this.requestId = args.requestId;
|
|
23
42
|
this.data = args.data;
|
|
43
|
+
this.mfp = args.mfp;
|
|
44
|
+
this.xpub = args.xpub;
|
|
45
|
+
this.walletIndex = args.walletIndex;
|
|
24
46
|
}
|
|
25
|
-
static constructAvalancheRequest(data,
|
|
47
|
+
static constructAvalancheRequest(data, mfp, xpub, walletIndex, requestId) {
|
|
48
|
+
let _requestId;
|
|
49
|
+
if (typeof requestId === "string") {
|
|
50
|
+
_requestId = Buffer.from(uuid.parse(requestId));
|
|
51
|
+
} else if (requestId instanceof Buffer) {
|
|
52
|
+
_requestId = requestId;
|
|
53
|
+
} else {
|
|
54
|
+
_requestId = Buffer.from(uuid.parse(uuid.v4()));
|
|
55
|
+
}
|
|
26
56
|
return new AvalancheSignRequest({
|
|
27
57
|
data,
|
|
28
|
-
requestId:
|
|
58
|
+
requestId: _requestId,
|
|
59
|
+
mfp: Buffer.from(mfp, "hex"),
|
|
60
|
+
xpub,
|
|
61
|
+
walletIndex
|
|
29
62
|
});
|
|
30
63
|
}
|
|
31
64
|
}
|
|
65
|
+
AvalancheSignRequest.fromDataItem = dataItem => {
|
|
66
|
+
const map = dataItem.getData();
|
|
67
|
+
const masterFingerprint = Buffer.alloc(4);
|
|
68
|
+
const _masterFingerprint = map[Keys.mfp];
|
|
69
|
+
masterFingerprint.writeUInt32BE(_masterFingerprint, 0);
|
|
70
|
+
const requestId = map[Keys.requestId] ? map[Keys.requestId].getData() : undefined;
|
|
71
|
+
const data = map[Keys.signData];
|
|
72
|
+
const xpub = map[Keys.xpub];
|
|
73
|
+
const walletIndex = map[Keys.signData];
|
|
74
|
+
return new AvalancheSignRequest({
|
|
75
|
+
requestId,
|
|
76
|
+
data,
|
|
77
|
+
xpub,
|
|
78
|
+
walletIndex,
|
|
79
|
+
mfp: masterFingerprint
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const {
|
|
84
|
+
RegistryTypes: RegistryTypes$1,
|
|
85
|
+
decodeToDataItem
|
|
86
|
+
} = bcUrRegistry.extend;
|
|
87
|
+
var Keys$1;
|
|
88
|
+
(function (Keys) {
|
|
89
|
+
Keys[Keys["requestId"] = 1] = "requestId";
|
|
90
|
+
Keys[Keys["signature"] = 2] = "signature";
|
|
91
|
+
})(Keys$1 || (Keys$1 = {}));
|
|
92
|
+
class AvalancheSignature extends bcUrRegistry.RegistryItem {
|
|
93
|
+
constructor(signature, requestId) {
|
|
94
|
+
super();
|
|
95
|
+
this.getRegistryType = () => ExtendedRegistryTypes.AVALANCHE_SIGNATURE;
|
|
96
|
+
this.getRequestId = () => this.requestId;
|
|
97
|
+
this.getSignature = () => this.signature;
|
|
98
|
+
this.toDataItem = () => {
|
|
99
|
+
const map = {};
|
|
100
|
+
if (this.requestId) {
|
|
101
|
+
map[Keys$1.requestId] = new bcUrRegistry.DataItem(this.requestId, RegistryTypes$1.UUID.getTag());
|
|
102
|
+
}
|
|
103
|
+
map[Keys$1.signature] = this.signature;
|
|
104
|
+
return new bcUrRegistry.DataItem(map);
|
|
105
|
+
};
|
|
106
|
+
this.signature = signature;
|
|
107
|
+
this.requestId = requestId;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
AvalancheSignature.fromDataItem = dataItem => {
|
|
111
|
+
const map = dataItem.getData();
|
|
112
|
+
const signature = map[Keys$1.signature];
|
|
113
|
+
return new AvalancheSignature(signature);
|
|
114
|
+
};
|
|
115
|
+
AvalancheSignature.fromCBOR = _cborPayload => {
|
|
116
|
+
const dataItem = decodeToDataItem(_cborPayload);
|
|
117
|
+
return AvalancheSignature.fromDataItem(dataItem);
|
|
118
|
+
};
|
|
32
119
|
|
|
33
120
|
bcUrRegistry.patchTags(Object.values(ExtendedRegistryTypes).filter(rt => !!rt.getTag()).map(rt => rt.getTag()));
|
|
34
121
|
|
|
@@ -41,4 +128,5 @@ Object.keys(bcUrRegistry).forEach(function (k) {
|
|
|
41
128
|
});
|
|
42
129
|
});
|
|
43
130
|
exports.AvalancheSignRequest = AvalancheSignRequest;
|
|
131
|
+
exports.AvalancheSignature = AvalancheSignature;
|
|
44
132
|
//# sourceMappingURL=bc-ur-registry-avalanche.cjs.development.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bc-ur-registry-avalanche.cjs.development.js","sources":["../src/RegistryType.ts","../src/AvalancheSignRequest.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};\n","import {
|
|
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\";\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] = Buffer.from(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 requestId?: string | Buffer\n ) {\n let _requestId;\n if (typeof requestId === \"string\") {\n _requestId = Buffer.from(uuid.parse(requestId) as Uint8Array);\n } else if (requestId instanceof Buffer) {\n _requestId = requestId;\n } else {\n _requestId = Buffer.from(uuid.parse(uuid.v4()));\n }\n\n return new AvalancheSignRequest({\n data,\n requestId: _requestId,\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","Buffer","from","mfp","readUInt32BE","xpub","walletIndex","Number","constructAvalancheRequest","_requestId","uuid","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;;ACID,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,CAA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,IAAI,CAAC0B,SAAS;IAEnC,eAAU,GAAG;MAClB,MAAMxB,GAAG,GAAgB,EAAE;MAC3B,IAAI,IAAI,CAACF,SAAS,EAAE;QAClBE,GAAG,CAACP,MAAI,CAACK,SAAS,CAAC,GAAG,IAAIG,qBAAQ,CAChC,IAAI,CAACH,SAAS,EACdP,eAAa,CAACW,IAAI,CAACC,MAAM,EAAE,CAC5B;;MAEHH,GAAG,CAACP,MAAI,CAAC+B,SAAS,CAAC,GAAG,IAAI,CAACA,SAAS;MACpC,OAAO,IAAIvB,qBAAQ,CAACD,GAAG,CAAC;KACzB;IAjBC,IAAI,CAACwB,SAAS,GAAGA,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 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@keystonehq/bc-ur-registry"),t=require("uuid")
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@keystonehq/bc-ur-registry"),t=require("uuid");const s={AVALANCHE_SIGN_REQUEST:new e.RegistryType("avax-sign-request",8301),AVALANCHE_SIGNATURE:new e.RegistryType("avax-signature",8302)},{RegistryTypes:a}=e.extend;var r;!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"}(r||(r={}));class n extends e.RegistryItem{constructor(t){super(),this.getRegistryType=()=>s.AVALANCHE_SIGN_REQUEST,this.getRequestId=()=>this.requestId,this.getSignData=()=>this.data,this.toDataItem=()=>{const t={};return this.requestId&&(t[r.requestId]=new e.DataItem(this.requestId,a.UUID.getTag())),t[r.signData]=Buffer.from(this.data),t[r.mfp]=this.mfp.readUInt32BE(0),t[r.xpub]=this.xpub,t[r.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,s,a,r,u){let i;return i="string"==typeof u?Buffer.from(t.parse(u)):u instanceof Buffer?u:Buffer.from(t.parse(t.v4())),new n({data:e,requestId:i,mfp:Buffer.from(s,"hex"),xpub:a,walletIndex:r})}}n.fromDataItem=e=>{const t=e.getData(),s=Buffer.alloc(4);s.writeUInt32BE(t[r.mfp],0);const a=t[r.requestId]?t[r.requestId].getData():void 0;return new n({requestId:a,data:t[r.signData],xpub:t[r.xpub],walletIndex:t[r.signData],mfp:s})};const{RegistryTypes:u,decodeToDataItem:i}=e.extend;var I;!function(e){e[e.requestId=1]="requestId",e[e.signature=2]="signature"}(I||(I={}));class d extends e.RegistryItem{constructor(t,a){super(),this.getRegistryType=()=>s.AVALANCHE_SIGNATURE,this.getRequestId=()=>this.requestId,this.getSignature=()=>this.signature,this.toDataItem=()=>{const t={};return this.requestId&&(t[I.requestId]=new e.DataItem(this.requestId,u.UUID.getTag())),t[I.signature]=this.signature,new e.DataItem(t)},this.signature=t,this.requestId=a}}d.fromDataItem=e=>{const t=e.getData();return new d(t[I.signature])},d.fromCBOR=e=>{const t=i(e);return d.fromDataItem(t)},e.patchTags(Object.values(s).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=d;
|
|
2
2
|
//# sourceMappingURL=bc-ur-registry-avalanche.cjs.production.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bc-ur-registry-avalanche.cjs.production.min.js","sources":["../src/RegistryType.ts","../src/AvalancheSignRequest.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};\n","import {
|
|
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\";\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] = Buffer.from(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 requestId?: string | Buffer\n ) {\n let _requestId;\n if (typeof requestId === \"string\") {\n _requestId = Buffer.from(uuid.parse(requestId) as Uint8Array);\n } else if (requestId instanceof Buffer) {\n _requestId = requestId;\n } else {\n _requestId = Buffer.from(uuid.parse(uuid.v4()));\n }\n\n return new AvalancheSignRequest({\n data,\n requestId: _requestId,\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","Buffer","from","mfp","readUInt32BE","xpub","walletIndex","Number","[object Object]","_requestId","uuid","dataItem","getData","masterFingerprint","alloc","writeUInt32BE","undefined","decodeToDataItem","AvalancheSignature","signature","_cborPayload","fromDataItem","patchTags","Object","values","filter","rt"],"mappings":"kIAEO,MAAMA,EAAwB,CACnCC,uBAAwB,IAAIC,eAAa,o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pBI,EAKJ,OAAO,IAAI5B,EAAqB,CAC9BM,UAAAA,EACAC,KANWC,EAAIT,EAAKa,UAOpBK,KANWT,EAAIT,EAAKkB,MAOpBC,YANkBV,EAAIT,EAAKa,UAO3BG,IAAKU,KC1EX,oBAAQ5B,EAAagC,iBAAEA,GAAqB/B,SAE5C,IAAKC,GAAL,SAAKA,GACHA,6BACAA,6BAFF,CAAKA,IAAAA,aAKQ+B,UAA2B7B,eAMtCC,YAAY6B,EAAmBzB,GAC7BF,QAHFC,qBAAkB,IAAMZ,EAAsBG,oBAQvCS,kBAAe,IAAMA,KAAKC,UAC1BD,kBAAe,IAAMA,KAAK0B,UAE1B1B,gBAAa,KAClB,MAAMG,EAAmB,GAQzB,OAPIH,KAAKC,YACPE,EAAIT,EAAKO,WAAa,IAAIG,WACxBJ,KAAKC,UACLT,EAAca,KAAKC,WAGvBH,EAAIT,EAAKgC,WAAa1B,KAAK0B,UACpB,IAAItB,WAASD,IAhBpBH,KAAK0B,UAAYA,EACjB1B,KAAKC,UAAYA,GAkBLwB,eAAgBP,IAC5B,MAAMf,EAAMe,EAASC,UAGrB,OAAO,IAAIM,EAFOtB,EAAIT,EAAKgC,aAKfD,WAAYE,IACxB,MAAMT,EAAWM,EAAiBG,GAClC,OAAOF,EAAmBG,aAAaV,IC/C3CW,YACEC,OAAOC,OAAO3C,GACX4C,OAAQC,KAASA,EAAG3B,UACpBH,IAAK8B,GAAOA,EAAG3B"}
|
|
@@ -1,12 +1,23 @@
|
|
|
1
|
-
import { RegistryType, RegistryItem, DataItem, patchTags } from '@keystonehq/bc-ur-registry';
|
|
1
|
+
import { RegistryType, RegistryItem, DataItem, extend, patchTags } from '@keystonehq/bc-ur-registry';
|
|
2
2
|
export * from '@keystonehq/bc-ur-registry';
|
|
3
|
-
import { parse } from 'uuid';
|
|
4
|
-
import { Buffer } from 'buffer';
|
|
3
|
+
import { parse, v4 } from 'uuid';
|
|
5
4
|
|
|
6
5
|
const ExtendedRegistryTypes = {
|
|
7
|
-
AVALANCHE_SIGN_REQUEST: /*#__PURE__*/new RegistryType("avax-sign-request", 8301)
|
|
6
|
+
AVALANCHE_SIGN_REQUEST: /*#__PURE__*/new RegistryType("avax-sign-request", 8301),
|
|
7
|
+
AVALANCHE_SIGNATURE: /*#__PURE__*/new RegistryType("avax-signature", 8302)
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
+
const {
|
|
11
|
+
RegistryTypes
|
|
12
|
+
} = extend;
|
|
13
|
+
var Keys;
|
|
14
|
+
(function (Keys) {
|
|
15
|
+
Keys[Keys["requestId"] = 1] = "requestId";
|
|
16
|
+
Keys[Keys["signData"] = 2] = "signData";
|
|
17
|
+
Keys[Keys["mfp"] = 3] = "mfp";
|
|
18
|
+
Keys[Keys["xpub"] = 6] = "xpub";
|
|
19
|
+
Keys[Keys["walletIndex"] = 7] = "walletIndex";
|
|
20
|
+
})(Keys || (Keys = {}));
|
|
10
21
|
class AvalancheSignRequest extends RegistryItem {
|
|
11
22
|
constructor(args) {
|
|
12
23
|
super();
|
|
@@ -14,20 +25,96 @@ class AvalancheSignRequest extends RegistryItem {
|
|
|
14
25
|
this.getRequestId = () => this.requestId;
|
|
15
26
|
this.getSignData = () => this.data;
|
|
16
27
|
this.toDataItem = () => {
|
|
17
|
-
|
|
28
|
+
const map = {};
|
|
29
|
+
if (this.requestId) {
|
|
30
|
+
map[Keys.requestId] = new DataItem(this.requestId, RegistryTypes.UUID.getTag());
|
|
31
|
+
}
|
|
32
|
+
map[Keys.signData] = Buffer.from(this.data);
|
|
33
|
+
map[Keys.mfp] = this.mfp.readUInt32BE(0);
|
|
34
|
+
map[Keys.xpub] = this.xpub;
|
|
35
|
+
map[Keys.walletIndex] = Number(this.walletIndex);
|
|
36
|
+
return new DataItem(map);
|
|
18
37
|
};
|
|
19
38
|
this.requestId = args.requestId;
|
|
20
39
|
this.data = args.data;
|
|
40
|
+
this.mfp = args.mfp;
|
|
41
|
+
this.xpub = args.xpub;
|
|
42
|
+
this.walletIndex = args.walletIndex;
|
|
21
43
|
}
|
|
22
|
-
static constructAvalancheRequest(data,
|
|
44
|
+
static constructAvalancheRequest(data, mfp, xpub, walletIndex, requestId) {
|
|
45
|
+
let _requestId;
|
|
46
|
+
if (typeof requestId === "string") {
|
|
47
|
+
_requestId = Buffer.from(parse(requestId));
|
|
48
|
+
} else if (requestId instanceof Buffer) {
|
|
49
|
+
_requestId = requestId;
|
|
50
|
+
} else {
|
|
51
|
+
_requestId = Buffer.from(parse(v4()));
|
|
52
|
+
}
|
|
23
53
|
return new AvalancheSignRequest({
|
|
24
54
|
data,
|
|
25
|
-
requestId:
|
|
55
|
+
requestId: _requestId,
|
|
56
|
+
mfp: Buffer.from(mfp, "hex"),
|
|
57
|
+
xpub,
|
|
58
|
+
walletIndex
|
|
26
59
|
});
|
|
27
60
|
}
|
|
28
61
|
}
|
|
62
|
+
AvalancheSignRequest.fromDataItem = dataItem => {
|
|
63
|
+
const map = dataItem.getData();
|
|
64
|
+
const masterFingerprint = Buffer.alloc(4);
|
|
65
|
+
const _masterFingerprint = map[Keys.mfp];
|
|
66
|
+
masterFingerprint.writeUInt32BE(_masterFingerprint, 0);
|
|
67
|
+
const requestId = map[Keys.requestId] ? map[Keys.requestId].getData() : undefined;
|
|
68
|
+
const data = map[Keys.signData];
|
|
69
|
+
const xpub = map[Keys.xpub];
|
|
70
|
+
const walletIndex = map[Keys.signData];
|
|
71
|
+
return new AvalancheSignRequest({
|
|
72
|
+
requestId,
|
|
73
|
+
data,
|
|
74
|
+
xpub,
|
|
75
|
+
walletIndex,
|
|
76
|
+
mfp: masterFingerprint
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const {
|
|
81
|
+
RegistryTypes: RegistryTypes$1,
|
|
82
|
+
decodeToDataItem
|
|
83
|
+
} = extend;
|
|
84
|
+
var Keys$1;
|
|
85
|
+
(function (Keys) {
|
|
86
|
+
Keys[Keys["requestId"] = 1] = "requestId";
|
|
87
|
+
Keys[Keys["signature"] = 2] = "signature";
|
|
88
|
+
})(Keys$1 || (Keys$1 = {}));
|
|
89
|
+
class AvalancheSignature extends RegistryItem {
|
|
90
|
+
constructor(signature, requestId) {
|
|
91
|
+
super();
|
|
92
|
+
this.getRegistryType = () => ExtendedRegistryTypes.AVALANCHE_SIGNATURE;
|
|
93
|
+
this.getRequestId = () => this.requestId;
|
|
94
|
+
this.getSignature = () => this.signature;
|
|
95
|
+
this.toDataItem = () => {
|
|
96
|
+
const map = {};
|
|
97
|
+
if (this.requestId) {
|
|
98
|
+
map[Keys$1.requestId] = new DataItem(this.requestId, RegistryTypes$1.UUID.getTag());
|
|
99
|
+
}
|
|
100
|
+
map[Keys$1.signature] = this.signature;
|
|
101
|
+
return new DataItem(map);
|
|
102
|
+
};
|
|
103
|
+
this.signature = signature;
|
|
104
|
+
this.requestId = requestId;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
AvalancheSignature.fromDataItem = dataItem => {
|
|
108
|
+
const map = dataItem.getData();
|
|
109
|
+
const signature = map[Keys$1.signature];
|
|
110
|
+
return new AvalancheSignature(signature);
|
|
111
|
+
};
|
|
112
|
+
AvalancheSignature.fromCBOR = _cborPayload => {
|
|
113
|
+
const dataItem = decodeToDataItem(_cborPayload);
|
|
114
|
+
return AvalancheSignature.fromDataItem(dataItem);
|
|
115
|
+
};
|
|
29
116
|
|
|
30
117
|
patchTags(Object.values(ExtendedRegistryTypes).filter(rt => !!rt.getTag()).map(rt => rt.getTag()));
|
|
31
118
|
|
|
32
|
-
export { AvalancheSignRequest };
|
|
119
|
+
export { AvalancheSignRequest, AvalancheSignature };
|
|
33
120
|
//# sourceMappingURL=bc-ur-registry-avalanche.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bc-ur-registry-avalanche.esm.js","sources":["../src/RegistryType.ts","../src/AvalancheSignRequest.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};\n","import {
|
|
1
|
+
{"version":3,"file":"bc-ur-registry-avalanche.esm.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\";\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] = Buffer.from(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 requestId?: string | Buffer\n ) {\n let _requestId;\n if (typeof requestId === \"string\") {\n _requestId = Buffer.from(uuid.parse(requestId) as Uint8Array);\n } else if (requestId instanceof Buffer) {\n _requestId = requestId;\n } else {\n _requestId = Buffer.from(uuid.parse(uuid.v4()));\n }\n\n return new AvalancheSignRequest({\n data,\n requestId: _requestId,\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","Buffer","from","mfp","readUInt32BE","xpub","walletIndex","Number","constructAvalancheRequest","_requestId","uuid","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,YAAY,CAAC,mBAAmB,EAAE,IAAI,CAAC;EACnEC,mBAAmB,eAAE,IAAID,YAAY,CAAC,gBAAgB,EAAE,IAAI;CAC7D;;ACID,MAAM;EAAEE;CAAe,GAAGC,MAAM;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,YAAY;EASpDC,YAAYC,IAAsB;IAChC,KAAK,EAAE;IAHT,oBAAe,GAAG,MAAMV,qBAAqB,CAACC,sBAAsB;IAW7D,iBAAY,GAAG,MAAM,IAAI,CAACU,SAAS;I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package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keystonehq/bc-ur-registry-avalanche",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "bc-ur-registry extension for Avalanche",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
"license": "ISC",
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@keystonehq/bc-ur-registry": "^0.6.4",
|
|
28
|
-
"buffer": "^6.0.3",
|
|
29
28
|
"uuid": "^8.3.2"
|
|
30
29
|
},
|
|
31
30
|
"devDependencies": {
|
|
@@ -1,16 +1,36 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
DataItem,
|
|
3
|
+
RegistryItem,
|
|
4
|
+
extend,
|
|
5
|
+
DataItemMap,
|
|
6
|
+
} from "@keystonehq/bc-ur-registry";
|
|
2
7
|
import { ExtendedRegistryTypes } from "./RegistryType";
|
|
3
8
|
import * as uuid from "uuid";
|
|
4
|
-
|
|
9
|
+
|
|
10
|
+
const { RegistryTypes } = extend;
|
|
5
11
|
|
|
6
12
|
type signRequestProps = {
|
|
7
13
|
requestId?: Buffer;
|
|
8
14
|
data: Buffer;
|
|
15
|
+
mfp: Buffer;
|
|
16
|
+
xpub: string;
|
|
17
|
+
walletIndex: number;
|
|
9
18
|
};
|
|
10
19
|
|
|
20
|
+
enum Keys {
|
|
21
|
+
requestId = 1,
|
|
22
|
+
signData = 2,
|
|
23
|
+
mfp = 3,
|
|
24
|
+
xpub = 6,
|
|
25
|
+
walletIndex = 7,
|
|
26
|
+
}
|
|
27
|
+
|
|
11
28
|
export class AvalancheSignRequest extends RegistryItem {
|
|
12
29
|
private requestId?: Buffer;
|
|
13
30
|
private data: Buffer;
|
|
31
|
+
private mfp: Buffer;
|
|
32
|
+
private xpub: string;
|
|
33
|
+
private walletIndex: number;
|
|
14
34
|
|
|
15
35
|
getRegistryType = () => ExtendedRegistryTypes.AVALANCHE_SIGN_REQUEST;
|
|
16
36
|
|
|
@@ -18,21 +38,74 @@ export class AvalancheSignRequest extends RegistryItem {
|
|
|
18
38
|
super();
|
|
19
39
|
this.requestId = args.requestId;
|
|
20
40
|
this.data = args.data;
|
|
41
|
+
this.mfp = args.mfp;
|
|
42
|
+
this.xpub = args.xpub;
|
|
43
|
+
this.walletIndex = args.walletIndex;
|
|
21
44
|
}
|
|
22
45
|
|
|
23
46
|
public getRequestId = () => this.requestId;
|
|
24
47
|
public getSignData = () => this.data;
|
|
25
48
|
|
|
26
49
|
public toDataItem = () => {
|
|
27
|
-
|
|
50
|
+
const map: DataItemMap = {};
|
|
51
|
+
if (this.requestId) {
|
|
52
|
+
map[Keys.requestId] = new DataItem(
|
|
53
|
+
this.requestId,
|
|
54
|
+
RegistryTypes.UUID.getTag()
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
map[Keys.signData] = Buffer.from(this.data);
|
|
59
|
+
map[Keys.mfp] = this.mfp.readUInt32BE(0);
|
|
60
|
+
map[Keys.xpub] = this.xpub;
|
|
61
|
+
map[Keys.walletIndex] = Number(this.walletIndex);
|
|
62
|
+
|
|
63
|
+
return new DataItem(map);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
public static fromDataItem = (dataItem: DataItem) => {
|
|
67
|
+
const map = dataItem.getData();
|
|
68
|
+
const masterFingerprint = Buffer.alloc(4);
|
|
69
|
+
const _masterFingerprint = map[Keys.mfp];
|
|
70
|
+
masterFingerprint.writeUInt32BE(_masterFingerprint, 0);
|
|
71
|
+
const requestId = map[Keys.requestId]
|
|
72
|
+
? map[Keys.requestId].getData()
|
|
73
|
+
: undefined;
|
|
74
|
+
const data = map[Keys.signData];
|
|
75
|
+
const xpub = map[Keys.xpub];
|
|
76
|
+
const walletIndex = map[Keys.signData];
|
|
77
|
+
|
|
78
|
+
return new AvalancheSignRequest({
|
|
79
|
+
requestId,
|
|
80
|
+
data,
|
|
81
|
+
xpub,
|
|
82
|
+
walletIndex,
|
|
83
|
+
mfp: masterFingerprint,
|
|
84
|
+
});
|
|
28
85
|
};
|
|
29
86
|
|
|
30
|
-
public static constructAvalancheRequest(
|
|
87
|
+
public static constructAvalancheRequest(
|
|
88
|
+
data: Buffer,
|
|
89
|
+
mfp: string,
|
|
90
|
+
xpub: string,
|
|
91
|
+
walletIndex: number,
|
|
92
|
+
requestId?: string | Buffer
|
|
93
|
+
) {
|
|
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()));
|
|
101
|
+
}
|
|
102
|
+
|
|
31
103
|
return new AvalancheSignRequest({
|
|
32
104
|
data,
|
|
33
|
-
requestId:
|
|
34
|
-
|
|
35
|
-
|
|
105
|
+
requestId: _requestId,
|
|
106
|
+
mfp: Buffer.from(mfp, "hex"),
|
|
107
|
+
xpub,
|
|
108
|
+
walletIndex,
|
|
36
109
|
});
|
|
37
110
|
}
|
|
38
111
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
extend,
|
|
3
|
+
DataItem,
|
|
4
|
+
RegistryItem,
|
|
5
|
+
DataItemMap,
|
|
6
|
+
} from "@keystonehq/bc-ur-registry";
|
|
7
|
+
import { ExtendedRegistryTypes } from "./RegistryType";
|
|
8
|
+
|
|
9
|
+
const { RegistryTypes, decodeToDataItem } = extend;
|
|
10
|
+
|
|
11
|
+
enum Keys {
|
|
12
|
+
requestId = 1,
|
|
13
|
+
signature,
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class AvalancheSignature extends RegistryItem {
|
|
17
|
+
private requestId?: Buffer;
|
|
18
|
+
private signature: Buffer;
|
|
19
|
+
|
|
20
|
+
getRegistryType = () => ExtendedRegistryTypes.AVALANCHE_SIGNATURE;
|
|
21
|
+
|
|
22
|
+
constructor(signature: Buffer, requestId?: Buffer) {
|
|
23
|
+
super();
|
|
24
|
+
this.signature = signature;
|
|
25
|
+
this.requestId = requestId;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public getRequestId = () => this.requestId;
|
|
29
|
+
public getSignature = () => this.signature;
|
|
30
|
+
|
|
31
|
+
public toDataItem = () => {
|
|
32
|
+
const map: DataItemMap = {};
|
|
33
|
+
if (this.requestId) {
|
|
34
|
+
map[Keys.requestId] = new DataItem(
|
|
35
|
+
this.requestId,
|
|
36
|
+
RegistryTypes.UUID.getTag()
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
map[Keys.signature] = this.signature;
|
|
40
|
+
return new DataItem(map);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
public static fromDataItem = (dataItem: DataItem) => {
|
|
44
|
+
const map = dataItem.getData();
|
|
45
|
+
const signature = map[Keys.signature];
|
|
46
|
+
|
|
47
|
+
return new AvalancheSignature(signature);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
public static fromCBOR = (_cborPayload: Buffer) => {
|
|
51
|
+
const dataItem = decodeToDataItem(_cborPayload);
|
|
52
|
+
return AvalancheSignature.fromDataItem(dataItem);
|
|
53
|
+
};
|
|
54
|
+
}
|
package/src/RegistryType.ts
CHANGED
package/src/index.ts
CHANGED