@airgap/icp 0.13.11-beta.1 → 0.13.11-beta.10
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/index.d.ts +1 -0
- package/index.js +18 -0
- package/index.js.map +1 -0
- package/package.json +6 -9
- package/v1/block-explorer/ICPBlockExplorer.d.ts +9 -0
- package/v1/block-explorer/ICPBlockExplorer.js +74 -0
- package/v1/block-explorer/ICPBlockExplorer.js.map +1 -0
- package/v1/index.d.ts +14 -0
- package/v1/index.js +14 -0
- package/v1/index.js.map +1 -0
- package/v1/module/ICPModule.d.ts +14 -0
- package/v1/module/ICPModule.js +119 -0
- package/v1/module/ICPModule.js.map +1 -0
- package/v1/module.d.ts +3 -0
- package/v1/module.js +24 -0
- package/v1/module.js.map +1 -0
- package/v1/protocol/ICPImplementation.d.ts +34 -0
- package/v1/protocol/ICPImplementation.js +376 -0
- package/v1/protocol/ICPImplementation.js.map +1 -0
- package/v1/protocol/ICPProtocol.d.ts +45 -0
- package/v1/protocol/ICPProtocol.js +423 -0
- package/v1/protocol/ICPProtocol.js.map +1 -0
- package/v1/protocol/icrc/CkBTCProtocol.d.ts +13 -0
- package/v1/protocol/icrc/CkBTCProtocol.js +328 -0
- package/v1/protocol/icrc/CkBTCProtocol.js.map +1 -0
- package/v1/protocol/icrc/ICRC1Protocol.d.ts +95 -0
- package/v1/protocol/icrc/ICRC1Protocol.js +717 -0
- package/v1/protocol/icrc/ICRC1Protocol.js.map +1 -0
- package/v1/serializer/v3/schemas/converter/transaction-converter.d.ts +7 -0
- package/v1/serializer/v3/schemas/converter/transaction-converter.js +21 -0
- package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-icp.d.ts +4 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-icp.js +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-icp.js.map +1 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-icp.d.ts +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-icp.js +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-icp.js.map +1 -0
- package/v1/serializer/v3/schemas/generated/transaction-sign-request-icp.json +32 -0
- package/v1/serializer/v3/schemas/generated/transaction-sign-response-icp.json +19 -0
- package/v1/serializer/v3/serializer-companion.d.ts +14 -0
- package/v1/serializer/v3/serializer-companion.js +190 -0
- package/v1/serializer/v3/serializer-companion.js.map +1 -0
- package/v1/serializer/v3/validators/transaction-validator.d.ts +10 -0
- package/v1/serializer/v3/validators/transaction-validator.js +100 -0
- package/v1/serializer/v3/validators/transaction-validator.js.map +1 -0
- package/v1/serializer/v3/validators/validators.d.ts +5 -0
- package/v1/serializer/v3/validators/validators.js +106 -0
- package/v1/serializer/v3/validators/validators.js.map +1 -0
- package/v1/types/ckbtc/metadata.d.ts +4 -0
- package/v1/types/ckbtc/metadata.js +3 -0
- package/v1/types/ckbtc/metadata.js.map +1 -0
- package/v1/types/crypto.d.ts +2 -0
- package/v1/types/crypto.js +3 -0
- package/v1/types/crypto.js.map +1 -0
- package/v1/types/governance.d.ts +580 -0
- package/v1/types/governance.js +796 -0
- package/v1/types/governance.js.map +1 -0
- package/v1/types/icrc/account.d.ts +4 -0
- package/v1/types/icrc/account.js +3 -0
- package/v1/types/icrc/account.js.map +1 -0
- package/v1/types/icrc/ledger.d.ts +15 -0
- package/v1/types/icrc/ledger.js +92 -0
- package/v1/types/icrc/ledger.js.map +1 -0
- package/v1/types/icrc/metadata.d.ts +6 -0
- package/v1/types/icrc/metadata.js +3 -0
- package/v1/types/icrc/metadata.js.map +1 -0
- package/v1/types/icrc/transfer.d.ts +9 -0
- package/v1/types/icrc/transfer.js +3 -0
- package/v1/types/icrc/transfer.js.map +1 -0
- package/v1/types/ledger.d.ts +142 -0
- package/v1/types/ledger.js +145 -0
- package/v1/types/ledger.js.map +1 -0
- package/v1/types/management_idl.d.ts +7 -0
- package/v1/types/management_idl.js +72 -0
- package/v1/types/management_idl.js.map +1 -0
- package/v1/types/protocol.d.ts +37 -0
- package/v1/types/protocol.js +3 -0
- package/v1/types/protocol.js.map +1 -0
- package/v1/types/transaction.d.ts +11 -0
- package/v1/types/transaction.js +3 -0
- package/v1/types/transaction.js.map +1 -0
- package/v1/utils/account.d.ts +24 -0
- package/v1/utils/account.js +112 -0
- package/v1/utils/account.js.map +1 -0
- package/v1/utils/actor.d.ts +246 -0
- package/v1/utils/actor.js +458 -0
- package/v1/utils/actor.js.map +1 -0
- package/v1/utils/agent.d.ts +156 -0
- package/v1/utils/agent.js +16 -0
- package/v1/utils/agent.js.map +1 -0
- package/v1/utils/auth.d.ts +110 -0
- package/v1/utils/auth.js +261 -0
- package/v1/utils/auth.js.map +1 -0
- package/v1/utils/bls.d.ts +38 -0
- package/v1/utils/bls.js +204 -0
- package/v1/utils/bls.js.map +1 -0
- package/v1/utils/buffer.d.ts +70 -0
- package/v1/utils/buffer.js +216 -0
- package/v1/utils/buffer.js.map +1 -0
- package/v1/utils/cbor.d.ts +9 -0
- package/v1/utils/cbor.js +178 -0
- package/v1/utils/cbor.js.map +1 -0
- package/v1/utils/certificate.d.ts +74 -0
- package/v1/utils/certificate.js +396 -0
- package/v1/utils/certificate.js.map +1 -0
- package/v1/utils/convert.d.ts +10 -0
- package/v1/utils/convert.js +88 -0
- package/v1/utils/convert.js.map +1 -0
- package/v1/utils/crypto.d.ts +0 -0
- package/v1/utils/crypto.js +104 -0
- package/v1/utils/crypto.js.map +1 -0
- package/v1/utils/der.d.ts +35 -0
- package/v1/utils/der.js +176 -0
- package/v1/utils/der.js.map +1 -0
- package/v1/utils/errors.d.ts +7 -0
- package/v1/utils/errors.js +38 -0
- package/v1/utils/errors.js.map +1 -0
- package/v1/utils/hdkey.d.ts +13 -0
- package/v1/utils/hdkey.js +265 -0
- package/v1/utils/hdkey.js.map +1 -0
- package/v1/utils/http.d.ts +284 -0
- package/v1/utils/http.js +614 -0
- package/v1/utils/http.js.map +1 -0
- package/v1/utils/icrc1.d.ts +20 -0
- package/v1/utils/icrc1.js +171 -0
- package/v1/utils/icrc1.js.map +1 -0
- package/v1/utils/idl.d.ts +515 -0
- package/v1/utils/idl.js +2103 -0
- package/v1/utils/idl.js.map +1 -0
- package/v1/utils/leb128.d.ts +63 -0
- package/v1/utils/leb128.js +224 -0
- package/v1/utils/leb128.js.map +1 -0
- package/v1/utils/polling.d.ts +59 -0
- package/v1/utils/polling.js +325 -0
- package/v1/utils/polling.js.map +1 -0
- package/v1/utils/principal.d.ts +58 -0
- package/v1/utils/principal.js +543 -0
- package/v1/utils/principal.js.map +1 -0
- package/v1/utils/secp256k1.d.ts +79 -0
- package/v1/utils/secp256k1.js +278 -0
- package/v1/utils/secp256k1.js.map +1 -0
- package/v1/utils/transaction.d.ts +3 -0
- package/v1/utils/transaction.js +56 -0
- package/v1/utils/transaction.js.map +1 -0
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __values = (this && this.__values) || function(o) {
|
|
3
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
|
+
if (m) return m.call(o);
|
|
5
|
+
if (o && typeof o.length === "number") return {
|
|
6
|
+
next: function () {
|
|
7
|
+
if (o && i >= o.length) o = void 0;
|
|
8
|
+
return { value: o && o[i++], done: !o };
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
+
};
|
|
13
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
+
if (!m) return o;
|
|
16
|
+
var i = m.call(o), r, ar = [], e;
|
|
17
|
+
try {
|
|
18
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
+
}
|
|
20
|
+
catch (error) { e = { error: error }; }
|
|
21
|
+
finally {
|
|
22
|
+
try {
|
|
23
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
+
}
|
|
25
|
+
finally { if (e) throw e.error; }
|
|
26
|
+
}
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
30
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
+
if (ar || !(i in from)) {
|
|
32
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
+
ar[i] = from[i];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.Principal = exports.sha224 = exports.getCrc32 = exports.decode = exports.encode = void 0;
|
|
40
|
+
var js_sha256_1 = require("js-sha256");
|
|
41
|
+
// tslint:disable:no-bitwise
|
|
42
|
+
var alphabet = 'abcdefghijklmnopqrstuvwxyz234567';
|
|
43
|
+
// Build a lookup table for decoding.
|
|
44
|
+
var lookupTable = Object.create(null);
|
|
45
|
+
for (var i = 0; i < alphabet.length; i++) {
|
|
46
|
+
lookupTable[alphabet[i]] = i;
|
|
47
|
+
}
|
|
48
|
+
// Add aliases for rfc4648.
|
|
49
|
+
lookupTable['0'] = lookupTable.o;
|
|
50
|
+
lookupTable['1'] = lookupTable.i;
|
|
51
|
+
/**
|
|
52
|
+
* @param input The input array to encode.
|
|
53
|
+
* @returns A Base32 string encoding the input.
|
|
54
|
+
*/
|
|
55
|
+
function encode(input) {
|
|
56
|
+
// How many bits will we skip from the first byte.
|
|
57
|
+
var skip = 0;
|
|
58
|
+
// 5 high bits, carry from one byte to the next.
|
|
59
|
+
var bits = 0;
|
|
60
|
+
// The output string in base32.
|
|
61
|
+
var output = '';
|
|
62
|
+
function encodeByte(byte) {
|
|
63
|
+
if (skip < 0) {
|
|
64
|
+
// we have a carry from the previous byte
|
|
65
|
+
bits |= byte >> -skip;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
// no carry
|
|
69
|
+
bits = (byte << skip) & 248;
|
|
70
|
+
}
|
|
71
|
+
if (skip > 3) {
|
|
72
|
+
// Not enough data to produce a character, get us another one
|
|
73
|
+
skip -= 8;
|
|
74
|
+
return 1;
|
|
75
|
+
}
|
|
76
|
+
if (skip < 4) {
|
|
77
|
+
// produce a character
|
|
78
|
+
output += alphabet[bits >> 3];
|
|
79
|
+
skip += 5;
|
|
80
|
+
}
|
|
81
|
+
return 0;
|
|
82
|
+
}
|
|
83
|
+
for (var i = 0; i < input.length;) {
|
|
84
|
+
i += encodeByte(input[i]);
|
|
85
|
+
}
|
|
86
|
+
return output + (skip < 0 ? alphabet[bits >> 3] : '');
|
|
87
|
+
}
|
|
88
|
+
exports.encode = encode;
|
|
89
|
+
/**
|
|
90
|
+
* @param input The base32 encoded string to decode.
|
|
91
|
+
*/
|
|
92
|
+
function decode(input) {
|
|
93
|
+
var e_1, _a;
|
|
94
|
+
// how many bits we have from the previous character.
|
|
95
|
+
var skip = 0;
|
|
96
|
+
// current byte we're producing.
|
|
97
|
+
var byte = 0;
|
|
98
|
+
var output = new Uint8Array(((input.length * 4) / 3) | 0);
|
|
99
|
+
var o = 0;
|
|
100
|
+
function decodeChar(char) {
|
|
101
|
+
// Consume a character from the stream, store
|
|
102
|
+
// the output in this.output. As before, better
|
|
103
|
+
// to use update().
|
|
104
|
+
var val = lookupTable[char.toLowerCase()];
|
|
105
|
+
if (val === undefined) {
|
|
106
|
+
throw new Error("Invalid character: ".concat(JSON.stringify(char)));
|
|
107
|
+
}
|
|
108
|
+
// move to the high bits
|
|
109
|
+
val <<= 3;
|
|
110
|
+
byte |= val >>> skip;
|
|
111
|
+
skip += 5;
|
|
112
|
+
if (skip >= 8) {
|
|
113
|
+
// We have enough bytes to produce an output
|
|
114
|
+
output[o++] = byte;
|
|
115
|
+
skip -= 8;
|
|
116
|
+
if (skip > 0) {
|
|
117
|
+
byte = (val << (5 - skip)) & 255;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
byte = 0;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
try {
|
|
125
|
+
for (var input_1 = __values(input), input_1_1 = input_1.next(); !input_1_1.done; input_1_1 = input_1.next()) {
|
|
126
|
+
var c = input_1_1.value;
|
|
127
|
+
decodeChar(c);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
131
|
+
finally {
|
|
132
|
+
try {
|
|
133
|
+
if (input_1_1 && !input_1_1.done && (_a = input_1.return)) _a.call(input_1);
|
|
134
|
+
}
|
|
135
|
+
finally { if (e_1) throw e_1.error; }
|
|
136
|
+
}
|
|
137
|
+
return output.slice(0, o);
|
|
138
|
+
}
|
|
139
|
+
exports.decode = decode;
|
|
140
|
+
// tslint:disable:no-bitwise
|
|
141
|
+
// This file is translated to JavaScript from
|
|
142
|
+
// https://lxp32.github.io/docs/a-simple-example-crc32-calculation/
|
|
143
|
+
var lookUpTable = new Uint32Array([
|
|
144
|
+
0x00000000,
|
|
145
|
+
0x77073096,
|
|
146
|
+
0xee0e612c,
|
|
147
|
+
0x990951ba,
|
|
148
|
+
0x076dc419,
|
|
149
|
+
0x706af48f,
|
|
150
|
+
0xe963a535,
|
|
151
|
+
0x9e6495a3,
|
|
152
|
+
0x0edb8832,
|
|
153
|
+
0x79dcb8a4,
|
|
154
|
+
0xe0d5e91e,
|
|
155
|
+
0x97d2d988,
|
|
156
|
+
0x09b64c2b,
|
|
157
|
+
0x7eb17cbd,
|
|
158
|
+
0xe7b82d07,
|
|
159
|
+
0x90bf1d91,
|
|
160
|
+
0x1db71064,
|
|
161
|
+
0x6ab020f2,
|
|
162
|
+
0xf3b97148,
|
|
163
|
+
0x84be41de,
|
|
164
|
+
0x1adad47d,
|
|
165
|
+
0x6ddde4eb,
|
|
166
|
+
0xf4d4b551,
|
|
167
|
+
0x83d385c7,
|
|
168
|
+
0x136c9856,
|
|
169
|
+
0x646ba8c0,
|
|
170
|
+
0xfd62f97a,
|
|
171
|
+
0x8a65c9ec,
|
|
172
|
+
0x14015c4f,
|
|
173
|
+
0x63066cd9,
|
|
174
|
+
0xfa0f3d63,
|
|
175
|
+
0x8d080df5,
|
|
176
|
+
0x3b6e20c8,
|
|
177
|
+
0x4c69105e,
|
|
178
|
+
0xd56041e4,
|
|
179
|
+
0xa2677172,
|
|
180
|
+
0x3c03e4d1,
|
|
181
|
+
0x4b04d447,
|
|
182
|
+
0xd20d85fd,
|
|
183
|
+
0xa50ab56b,
|
|
184
|
+
0x35b5a8fa,
|
|
185
|
+
0x42b2986c,
|
|
186
|
+
0xdbbbc9d6,
|
|
187
|
+
0xacbcf940,
|
|
188
|
+
0x32d86ce3,
|
|
189
|
+
0x45df5c75,
|
|
190
|
+
0xdcd60dcf,
|
|
191
|
+
0xabd13d59,
|
|
192
|
+
0x26d930ac,
|
|
193
|
+
0x51de003a,
|
|
194
|
+
0xc8d75180,
|
|
195
|
+
0xbfd06116,
|
|
196
|
+
0x21b4f4b5,
|
|
197
|
+
0x56b3c423,
|
|
198
|
+
0xcfba9599,
|
|
199
|
+
0xb8bda50f,
|
|
200
|
+
0x2802b89e,
|
|
201
|
+
0x5f058808,
|
|
202
|
+
0xc60cd9b2,
|
|
203
|
+
0xb10be924,
|
|
204
|
+
0x2f6f7c87,
|
|
205
|
+
0x58684c11,
|
|
206
|
+
0xc1611dab,
|
|
207
|
+
0xb6662d3d,
|
|
208
|
+
0x76dc4190,
|
|
209
|
+
0x01db7106,
|
|
210
|
+
0x98d220bc,
|
|
211
|
+
0xefd5102a,
|
|
212
|
+
0x71b18589,
|
|
213
|
+
0x06b6b51f,
|
|
214
|
+
0x9fbfe4a5,
|
|
215
|
+
0xe8b8d433,
|
|
216
|
+
0x7807c9a2,
|
|
217
|
+
0x0f00f934,
|
|
218
|
+
0x9609a88e,
|
|
219
|
+
0xe10e9818,
|
|
220
|
+
0x7f6a0dbb,
|
|
221
|
+
0x086d3d2d,
|
|
222
|
+
0x91646c97,
|
|
223
|
+
0xe6635c01,
|
|
224
|
+
0x6b6b51f4,
|
|
225
|
+
0x1c6c6162,
|
|
226
|
+
0x856530d8,
|
|
227
|
+
0xf262004e,
|
|
228
|
+
0x6c0695ed,
|
|
229
|
+
0x1b01a57b,
|
|
230
|
+
0x8208f4c1,
|
|
231
|
+
0xf50fc457,
|
|
232
|
+
0x65b0d9c6,
|
|
233
|
+
0x12b7e950,
|
|
234
|
+
0x8bbeb8ea,
|
|
235
|
+
0xfcb9887c,
|
|
236
|
+
0x62dd1ddf,
|
|
237
|
+
0x15da2d49,
|
|
238
|
+
0x8cd37cf3,
|
|
239
|
+
0xfbd44c65,
|
|
240
|
+
0x4db26158,
|
|
241
|
+
0x3ab551ce,
|
|
242
|
+
0xa3bc0074,
|
|
243
|
+
0xd4bb30e2,
|
|
244
|
+
0x4adfa541,
|
|
245
|
+
0x3dd895d7,
|
|
246
|
+
0xa4d1c46d,
|
|
247
|
+
0xd3d6f4fb,
|
|
248
|
+
0x4369e96a,
|
|
249
|
+
0x346ed9fc,
|
|
250
|
+
0xad678846,
|
|
251
|
+
0xda60b8d0,
|
|
252
|
+
0x44042d73,
|
|
253
|
+
0x33031de5,
|
|
254
|
+
0xaa0a4c5f,
|
|
255
|
+
0xdd0d7cc9,
|
|
256
|
+
0x5005713c,
|
|
257
|
+
0x270241aa,
|
|
258
|
+
0xbe0b1010,
|
|
259
|
+
0xc90c2086,
|
|
260
|
+
0x5768b525,
|
|
261
|
+
0x206f85b3,
|
|
262
|
+
0xb966d409,
|
|
263
|
+
0xce61e49f,
|
|
264
|
+
0x5edef90e,
|
|
265
|
+
0x29d9c998,
|
|
266
|
+
0xb0d09822,
|
|
267
|
+
0xc7d7a8b4,
|
|
268
|
+
0x59b33d17,
|
|
269
|
+
0x2eb40d81,
|
|
270
|
+
0xb7bd5c3b,
|
|
271
|
+
0xc0ba6cad,
|
|
272
|
+
0xedb88320,
|
|
273
|
+
0x9abfb3b6,
|
|
274
|
+
0x03b6e20c,
|
|
275
|
+
0x74b1d29a,
|
|
276
|
+
0xead54739,
|
|
277
|
+
0x9dd277af,
|
|
278
|
+
0x04db2615,
|
|
279
|
+
0x73dc1683,
|
|
280
|
+
0xe3630b12,
|
|
281
|
+
0x94643b84,
|
|
282
|
+
0x0d6d6a3e,
|
|
283
|
+
0x7a6a5aa8,
|
|
284
|
+
0xe40ecf0b,
|
|
285
|
+
0x9309ff9d,
|
|
286
|
+
0x0a00ae27,
|
|
287
|
+
0x7d079eb1,
|
|
288
|
+
0xf00f9344,
|
|
289
|
+
0x8708a3d2,
|
|
290
|
+
0x1e01f268,
|
|
291
|
+
0x6906c2fe,
|
|
292
|
+
0xf762575d,
|
|
293
|
+
0x806567cb,
|
|
294
|
+
0x196c3671,
|
|
295
|
+
0x6e6b06e7,
|
|
296
|
+
0xfed41b76,
|
|
297
|
+
0x89d32be0,
|
|
298
|
+
0x10da7a5a,
|
|
299
|
+
0x67dd4acc,
|
|
300
|
+
0xf9b9df6f,
|
|
301
|
+
0x8ebeeff9,
|
|
302
|
+
0x17b7be43,
|
|
303
|
+
0x60b08ed5,
|
|
304
|
+
0xd6d6a3e8,
|
|
305
|
+
0xa1d1937e,
|
|
306
|
+
0x38d8c2c4,
|
|
307
|
+
0x4fdff252,
|
|
308
|
+
0xd1bb67f1,
|
|
309
|
+
0xa6bc5767,
|
|
310
|
+
0x3fb506dd,
|
|
311
|
+
0x48b2364b,
|
|
312
|
+
0xd80d2bda,
|
|
313
|
+
0xaf0a1b4c,
|
|
314
|
+
0x36034af6,
|
|
315
|
+
0x41047a60,
|
|
316
|
+
0xdf60efc3,
|
|
317
|
+
0xa867df55,
|
|
318
|
+
0x316e8eef,
|
|
319
|
+
0x4669be79,
|
|
320
|
+
0xcb61b38c,
|
|
321
|
+
0xbc66831a,
|
|
322
|
+
0x256fd2a0,
|
|
323
|
+
0x5268e236,
|
|
324
|
+
0xcc0c7795,
|
|
325
|
+
0xbb0b4703,
|
|
326
|
+
0x220216b9,
|
|
327
|
+
0x5505262f,
|
|
328
|
+
0xc5ba3bbe,
|
|
329
|
+
0xb2bd0b28,
|
|
330
|
+
0x2bb45a92,
|
|
331
|
+
0x5cb36a04,
|
|
332
|
+
0xc2d7ffa7,
|
|
333
|
+
0xb5d0cf31,
|
|
334
|
+
0x2cd99e8b,
|
|
335
|
+
0x5bdeae1d,
|
|
336
|
+
0x9b64c2b0,
|
|
337
|
+
0xec63f226,
|
|
338
|
+
0x756aa39c,
|
|
339
|
+
0x026d930a,
|
|
340
|
+
0x9c0906a9,
|
|
341
|
+
0xeb0e363f,
|
|
342
|
+
0x72076785,
|
|
343
|
+
0x05005713,
|
|
344
|
+
0x95bf4a82,
|
|
345
|
+
0xe2b87a14,
|
|
346
|
+
0x7bb12bae,
|
|
347
|
+
0x0cb61b38,
|
|
348
|
+
0x92d28e9b,
|
|
349
|
+
0xe5d5be0d,
|
|
350
|
+
0x7cdcefb7,
|
|
351
|
+
0x0bdbdf21,
|
|
352
|
+
0x86d3d2d4,
|
|
353
|
+
0xf1d4e242,
|
|
354
|
+
0x68ddb3f8,
|
|
355
|
+
0x1fda836e,
|
|
356
|
+
0x81be16cd,
|
|
357
|
+
0xf6b9265b,
|
|
358
|
+
0x6fb077e1,
|
|
359
|
+
0x18b74777,
|
|
360
|
+
0x88085ae6,
|
|
361
|
+
0xff0f6a70,
|
|
362
|
+
0x66063bca,
|
|
363
|
+
0x11010b5c,
|
|
364
|
+
0x8f659eff,
|
|
365
|
+
0xf862ae69,
|
|
366
|
+
0x616bffd3,
|
|
367
|
+
0x166ccf45,
|
|
368
|
+
0xa00ae278,
|
|
369
|
+
0xd70dd2ee,
|
|
370
|
+
0x4e048354,
|
|
371
|
+
0x3903b3c2,
|
|
372
|
+
0xa7672661,
|
|
373
|
+
0xd06016f7,
|
|
374
|
+
0x4969474d,
|
|
375
|
+
0x3e6e77db,
|
|
376
|
+
0xaed16a4a,
|
|
377
|
+
0xd9d65adc,
|
|
378
|
+
0x40df0b66,
|
|
379
|
+
0x37d83bf0,
|
|
380
|
+
0xa9bcae53,
|
|
381
|
+
0xdebb9ec5,
|
|
382
|
+
0x47b2cf7f,
|
|
383
|
+
0x30b5ffe9,
|
|
384
|
+
0xbdbdf21c,
|
|
385
|
+
0xcabac28a,
|
|
386
|
+
0x53b39330,
|
|
387
|
+
0x24b4a3a6,
|
|
388
|
+
0xbad03605,
|
|
389
|
+
0xcdd70693,
|
|
390
|
+
0x54de5729,
|
|
391
|
+
0x23d967bf,
|
|
392
|
+
0xb3667a2e,
|
|
393
|
+
0xc4614ab8,
|
|
394
|
+
0x5d681b02,
|
|
395
|
+
0x2a6f2b94,
|
|
396
|
+
0xb40bbe37,
|
|
397
|
+
0xc30c8ea1,
|
|
398
|
+
0x5a05df1b,
|
|
399
|
+
0x2d02ef8d
|
|
400
|
+
]);
|
|
401
|
+
/**
|
|
402
|
+
* Calculate the CRC32 of an ArrayBufferLike.
|
|
403
|
+
* @param buf The BufferLike to calculate the CRC32 of.
|
|
404
|
+
*/
|
|
405
|
+
function getCrc32(buf) {
|
|
406
|
+
var b = new Uint8Array(buf);
|
|
407
|
+
var crc = -1;
|
|
408
|
+
// tslint:disable-next-line:prefer-for-of
|
|
409
|
+
for (var i = 0; i < b.length; i++) {
|
|
410
|
+
var byte = b[i];
|
|
411
|
+
var t = (byte ^ crc) & 0xff;
|
|
412
|
+
crc = lookUpTable[t] ^ (crc >>> 8);
|
|
413
|
+
}
|
|
414
|
+
return (crc ^ -1) >>> 0;
|
|
415
|
+
}
|
|
416
|
+
exports.getCrc32 = getCrc32;
|
|
417
|
+
/**
|
|
418
|
+
* Returns the SHA224 hash of the buffer.
|
|
419
|
+
* @param data Arraybuffer to encode
|
|
420
|
+
*/
|
|
421
|
+
function sha224(data) {
|
|
422
|
+
var shaObj = js_sha256_1.sha224.create();
|
|
423
|
+
shaObj.update(data);
|
|
424
|
+
return new Uint8Array(shaObj.array());
|
|
425
|
+
}
|
|
426
|
+
exports.sha224 = sha224;
|
|
427
|
+
var SELF_AUTHENTICATING_SUFFIX = 2;
|
|
428
|
+
var ANONYMOUS_SUFFIX = 4;
|
|
429
|
+
var MANAGEMENT_CANISTER_PRINCIPAL_HEX_STR = 'aaaaa-aa';
|
|
430
|
+
var fromHexString = function (hexString) { var _a; return new Uint8Array(((_a = hexString.match(/.{1,2}/g)) !== null && _a !== void 0 ? _a : []).map(function (byte) { return parseInt(byte, 16); })); };
|
|
431
|
+
var toHexString = function (bytes) { return bytes.reduce(function (str, byte) { return str + byte.toString(16).padStart(2, '0'); }, ''); };
|
|
432
|
+
var Principal = /** @class */ (function () {
|
|
433
|
+
function Principal(_arr) {
|
|
434
|
+
this._arr = _arr;
|
|
435
|
+
this._isPrincipal = true;
|
|
436
|
+
}
|
|
437
|
+
Principal.anonymous = function () {
|
|
438
|
+
return new this(new Uint8Array([ANONYMOUS_SUFFIX]));
|
|
439
|
+
};
|
|
440
|
+
/**
|
|
441
|
+
* Utility method, returning the principal representing the management canister, decoded from the hex string `'aaaaa-aa'`
|
|
442
|
+
* @returns {Principal} principal of the management canister
|
|
443
|
+
*/
|
|
444
|
+
Principal.managementCanister = function () {
|
|
445
|
+
return this.fromHex(MANAGEMENT_CANISTER_PRINCIPAL_HEX_STR);
|
|
446
|
+
};
|
|
447
|
+
Principal.selfAuthenticating = function (publicKey) {
|
|
448
|
+
var sha = sha224(publicKey);
|
|
449
|
+
return new this(new Uint8Array(__spreadArray(__spreadArray([], __read(sha), false), [SELF_AUTHENTICATING_SUFFIX], false)));
|
|
450
|
+
};
|
|
451
|
+
Principal.from = function (other) {
|
|
452
|
+
if (typeof other === 'string') {
|
|
453
|
+
return Principal.fromText(other);
|
|
454
|
+
}
|
|
455
|
+
else if (typeof other === 'object' && other !== null && other._isPrincipal === true) {
|
|
456
|
+
return new Principal(other._arr);
|
|
457
|
+
}
|
|
458
|
+
throw new Error("Impossible to convert ".concat(JSON.stringify(other), " to Principal."));
|
|
459
|
+
};
|
|
460
|
+
Principal.fromHex = function (hex) {
|
|
461
|
+
return new this(fromHexString(hex));
|
|
462
|
+
};
|
|
463
|
+
Principal.fromText = function (text) {
|
|
464
|
+
var canisterIdNoDash = text.toLowerCase().replace(/-/g, '');
|
|
465
|
+
var arr = decode(canisterIdNoDash);
|
|
466
|
+
arr = arr.slice(4, arr.length);
|
|
467
|
+
var principal = new this(arr);
|
|
468
|
+
if (principal.toText() !== text) {
|
|
469
|
+
throw new Error("Principal \"".concat(principal.toText(), "\" does not have a valid checksum (original value \"").concat(text, "\" may not be a valid Principal ID)."));
|
|
470
|
+
}
|
|
471
|
+
return principal;
|
|
472
|
+
};
|
|
473
|
+
Principal.fromUint8Array = function (arr) {
|
|
474
|
+
return new this(arr);
|
|
475
|
+
};
|
|
476
|
+
Principal.prototype.isAnonymous = function () {
|
|
477
|
+
return this._arr.byteLength === 1 && this._arr[0] === ANONYMOUS_SUFFIX;
|
|
478
|
+
};
|
|
479
|
+
Principal.prototype.toUint8Array = function () {
|
|
480
|
+
return this._arr;
|
|
481
|
+
};
|
|
482
|
+
Principal.prototype.toHex = function () {
|
|
483
|
+
return toHexString(this._arr).toUpperCase();
|
|
484
|
+
};
|
|
485
|
+
Principal.prototype.toText = function () {
|
|
486
|
+
var checksumArrayBuf = new ArrayBuffer(4);
|
|
487
|
+
var view = new DataView(checksumArrayBuf);
|
|
488
|
+
view.setUint32(0, getCrc32(this._arr));
|
|
489
|
+
var checksum = new Uint8Array(checksumArrayBuf);
|
|
490
|
+
var bytes = Uint8Array.from(this._arr);
|
|
491
|
+
var array = new Uint8Array(__spreadArray(__spreadArray([], __read(checksum), false), __read(bytes), false));
|
|
492
|
+
var result = encode(array);
|
|
493
|
+
var matches = result.match(/.{1,5}/g);
|
|
494
|
+
if (!matches) {
|
|
495
|
+
// This should only happen if there's no character, which is unreachable.
|
|
496
|
+
throw new Error();
|
|
497
|
+
}
|
|
498
|
+
return matches.join('-');
|
|
499
|
+
};
|
|
500
|
+
Principal.prototype.toString = function () {
|
|
501
|
+
return this.toText();
|
|
502
|
+
};
|
|
503
|
+
/**
|
|
504
|
+
* Utility method taking a Principal to compare against. Used for determining canister ranges in certificate verification
|
|
505
|
+
* @param {Principal} other - a {@link Principal} to compare
|
|
506
|
+
* @returns {'lt' | 'eq' | 'gt'} `'lt' | 'eq' | 'gt'` a string, representing less than, equal to, or greater than
|
|
507
|
+
*/
|
|
508
|
+
Principal.prototype.compareTo = function (other) {
|
|
509
|
+
for (var i = 0; i < Math.min(this._arr.length, other._arr.length); i++) {
|
|
510
|
+
if (this._arr[i] < other._arr[i])
|
|
511
|
+
return 'lt';
|
|
512
|
+
else if (this._arr[i] > other._arr[i])
|
|
513
|
+
return 'gt';
|
|
514
|
+
}
|
|
515
|
+
// Here, at least one principal is a prefix of the other principal (they could be the same)
|
|
516
|
+
if (this._arr.length < other._arr.length)
|
|
517
|
+
return 'lt';
|
|
518
|
+
if (this._arr.length > other._arr.length)
|
|
519
|
+
return 'gt';
|
|
520
|
+
return 'eq';
|
|
521
|
+
};
|
|
522
|
+
/**
|
|
523
|
+
* Utility method checking whether a provided Principal is less than or equal to the current one using the {@link Principal.compareTo} method
|
|
524
|
+
* @param other a {@link Principal} to compare
|
|
525
|
+
* @returns {boolean} boolean
|
|
526
|
+
*/
|
|
527
|
+
Principal.prototype.ltEq = function (other) {
|
|
528
|
+
var cmp = this.compareTo(other);
|
|
529
|
+
return cmp == 'lt' || cmp == 'eq';
|
|
530
|
+
};
|
|
531
|
+
/**
|
|
532
|
+
* Utility method checking whether a provided Principal is greater than or equal to the current one using the {@link Principal.compareTo} method
|
|
533
|
+
* @param other a {@link Principal} to compare
|
|
534
|
+
* @returns {boolean} boolean
|
|
535
|
+
*/
|
|
536
|
+
Principal.prototype.gtEq = function (other) {
|
|
537
|
+
var cmp = this.compareTo(other);
|
|
538
|
+
return cmp == 'gt' || cmp == 'eq';
|
|
539
|
+
};
|
|
540
|
+
return Principal;
|
|
541
|
+
}());
|
|
542
|
+
exports.Principal = Principal;
|
|
543
|
+
//# sourceMappingURL=principal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"principal.js","sourceRoot":"","sources":["../../../src/v1/utils/principal.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAA8C;AAE9C,4BAA4B;AAC5B,IAAM,QAAQ,GAAG,kCAAkC,CAAA;AAEnD,qCAAqC;AACrC,IAAM,WAAW,GAA2B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;AAC/D,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;IACxC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;CAC7B;AAED,2BAA2B;AAC3B,WAAW,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,CAAC,CAAA;AAChC,WAAW,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,CAAC,CAAA;AAEhC;;;GAGG;AACH,SAAgB,MAAM,CAAC,KAAiB;IACtC,kDAAkD;IAClD,IAAI,IAAI,GAAG,CAAC,CAAA;IACZ,gDAAgD;IAChD,IAAI,IAAI,GAAG,CAAC,CAAA;IAEZ,+BAA+B;IAC/B,IAAI,MAAM,GAAG,EAAE,CAAA;IAEf,SAAS,UAAU,CAAC,IAAY;QAC9B,IAAI,IAAI,GAAG,CAAC,EAAE;YACZ,yCAAyC;YACzC,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,CAAA;SACtB;aAAM;YACL,WAAW;YACX,IAAI,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC,GAAG,GAAG,CAAA;SAC5B;QAED,IAAI,IAAI,GAAG,CAAC,EAAE;YACZ,6DAA6D;YAC7D,IAAI,IAAI,CAAC,CAAA;YAC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V,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;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C1B,IAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;QACjC,OAAO,GAAG,IAAI,IAAI,IAAI,GAAG,IAAI,IAAI,CAAA;IACnC,CAAC;IACH,gBAAC;AAAD,CAAC,AA7HD,IA6HC;AA7HY,8BAAS"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { DerEncodedPublicKey, KeyPair, PublicKey, Signature, SignIdentity } from './auth';
|
|
2
|
+
declare type PublicKeyHex = string;
|
|
3
|
+
declare type SecretKeyHex = string;
|
|
4
|
+
export declare type JsonableSecp256k1Identity = [PublicKeyHex, SecretKeyHex];
|
|
5
|
+
export declare class Secp256k1PublicKey implements PublicKey {
|
|
6
|
+
/**
|
|
7
|
+
* Construct Secp256k1PublicKey from an existing PublicKey
|
|
8
|
+
* @param {PublicKey} key
|
|
9
|
+
* @returns {Secp256k1PublicKey} Instance of Secp256k1PublicKey
|
|
10
|
+
*/
|
|
11
|
+
static from(key: PublicKey): Secp256k1PublicKey;
|
|
12
|
+
static fromRaw(rawKey: ArrayBuffer): Secp256k1PublicKey;
|
|
13
|
+
static fromDer(derKey: DerEncodedPublicKey): Secp256k1PublicKey;
|
|
14
|
+
private static derEncode;
|
|
15
|
+
private static derDecode;
|
|
16
|
+
private readonly rawKey;
|
|
17
|
+
private readonly derKey;
|
|
18
|
+
private constructor();
|
|
19
|
+
toDer(): DerEncodedPublicKey;
|
|
20
|
+
toRaw(): ArrayBuffer;
|
|
21
|
+
}
|
|
22
|
+
export declare class Secp256k1KeyIdentity extends SignIdentity {
|
|
23
|
+
protected _privateKey: ArrayBuffer;
|
|
24
|
+
/**
|
|
25
|
+
* Generates an identity. If a seed is provided, the keys are generated from the
|
|
26
|
+
* seed according to BIP 0032. Otherwise, the key pair is randomly generated.
|
|
27
|
+
* This method throws an error in case the seed is not 32 bytes long or invalid
|
|
28
|
+
* for use as a private key.
|
|
29
|
+
* @param {Uint8Array} seed the optional seed
|
|
30
|
+
* @returns {Secp256k1KeyIdentity}
|
|
31
|
+
*/
|
|
32
|
+
static generate(seed?: Uint8Array): Secp256k1KeyIdentity;
|
|
33
|
+
static fromParsedJson(obj: JsonableSecp256k1Identity): Secp256k1KeyIdentity;
|
|
34
|
+
static fromJSON(json: string): Secp256k1KeyIdentity;
|
|
35
|
+
/**
|
|
36
|
+
* generates an identity from a public and private key. Please ensure that you are generating these keys securely and protect the user's private key
|
|
37
|
+
* @param {ArrayBuffer} publicKey
|
|
38
|
+
* @param {ArrayBuffer} privateKey
|
|
39
|
+
* @returns {Secp256k1KeyIdentity}
|
|
40
|
+
*/
|
|
41
|
+
static fromKeyPair(publicKey: ArrayBuffer, privateKey: ArrayBuffer): Secp256k1KeyIdentity;
|
|
42
|
+
/**
|
|
43
|
+
* generates an identity from an existing secret key, and is the correct method to generate an identity from a seed phrase. Please ensure you protect the user's private key.
|
|
44
|
+
* @param {ArrayBuffer} secretKey
|
|
45
|
+
* @returns {Secp256k1KeyIdentity}
|
|
46
|
+
*/
|
|
47
|
+
static fromSecretKey(secretKey: ArrayBuffer): Secp256k1KeyIdentity;
|
|
48
|
+
/**
|
|
49
|
+
* Generates an identity from a seed phrase. Use carefully - seed phrases should only be used in secure contexts, and you should avoid having users copying and pasting seed phrases as much as possible.
|
|
50
|
+
* @param {string | string[]} seedPhrase - either an array of words or a string of words separated by spaces.
|
|
51
|
+
* @param password - optional password to be used by bip39
|
|
52
|
+
* @returns Secp256k1KeyIdentity
|
|
53
|
+
*/
|
|
54
|
+
static fromSeedPhrase(seedPhrase: string | string[], password?: string | undefined, derivationPath?: string): Secp256k1KeyIdentity;
|
|
55
|
+
protected _publicKey: Secp256k1PublicKey;
|
|
56
|
+
protected constructor(publicKey: Secp256k1PublicKey, _privateKey: ArrayBuffer);
|
|
57
|
+
/**
|
|
58
|
+
* Serialize this key to JSON-serializable object.
|
|
59
|
+
* @returns {JsonableSecp256k1Identity}
|
|
60
|
+
*/
|
|
61
|
+
toJSON(): JsonableSecp256k1Identity;
|
|
62
|
+
/**
|
|
63
|
+
* Return a copy of the key pair.
|
|
64
|
+
* @returns {KeyPair}
|
|
65
|
+
*/
|
|
66
|
+
getKeyPair(): KeyPair;
|
|
67
|
+
/**
|
|
68
|
+
* Return the public key.
|
|
69
|
+
* @returns {Secp256k1PublicKey}
|
|
70
|
+
*/
|
|
71
|
+
getPublicKey(): Secp256k1PublicKey;
|
|
72
|
+
/**
|
|
73
|
+
* Signs a blob of data, with this identity's private key.
|
|
74
|
+
* @param {ArrayBuffer} challenge - challenge to sign with this identity's secretKey, producing a signature
|
|
75
|
+
* @returns {Promise<Signature>} signature
|
|
76
|
+
*/
|
|
77
|
+
sign(challenge: ArrayBuffer): Promise<Signature>;
|
|
78
|
+
}
|
|
79
|
+
export default Secp256k1KeyIdentity;
|