@airgap/icp 0.13.15-beta.0 → 0.13.15-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/package.json +8 -6
- package/v1/block-explorer/ICPBlockExplorer.js +16 -51
- package/v1/block-explorer/ICPBlockExplorer.js.map +1 -1
- package/v1/index.d.ts +3 -2
- package/v1/index.js +9 -5
- package/v1/index.js.map +1 -1
- package/v1/module/ICPModule.js +53 -94
- package/v1/module/ICPModule.js.map +1 -1
- package/v1/module.js +1 -1
- package/v1/module.js.map +1 -1
- package/v1/protocol/ICPGovernance.d.ts +39 -0
- package/v1/protocol/ICPGovernance.js +1177 -0
- package/v1/protocol/ICPGovernance.js.map +1 -0
- package/v1/protocol/ICPImplementation.d.ts +30 -5
- package/v1/protocol/ICPImplementation.js +317 -252
- package/v1/protocol/ICPImplementation.js.map +1 -1
- package/v1/protocol/ICPProtocol.d.ts +58 -6
- package/v1/protocol/ICPProtocol.js +764 -318
- package/v1/protocol/ICPProtocol.js.map +1 -1
- package/v1/protocol/icrc/CkBTCProtocol.js +137 -223
- package/v1/protocol/icrc/CkBTCProtocol.js.map +1 -1
- package/v1/protocol/icrc/ICRC1Protocol.js +338 -553
- package/v1/protocol/icrc/ICRC1Protocol.js.map +1 -1
- package/v1/serializer/v3/schemas/converter/transaction-converter.js +48 -5
- package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -1
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-icp.d.ts +8 -2
- package/v1/serializer/v3/schemas/generated/transaction-sign-request-icp.json +31 -1
- package/v1/serializer/v3/serializer-companion.js +85 -144
- package/v1/serializer/v3/serializer-companion.js.map +1 -1
- package/v1/serializer/v3/validators/transaction-validator.js +22 -60
- package/v1/serializer/v3/validators/transaction-validator.js.map +1 -1
- package/v1/serializer/v3/validators/validators.js +19 -58
- package/v1/serializer/v3/validators/validators.js.map +1 -1
- package/v1/types/governance.d.ts +29 -0
- package/v1/types/governance.js +279 -210
- package/v1/types/governance.js.map +1 -1
- package/v1/types/icrc/ledger.js +22 -23
- package/v1/types/icrc/ledger.js.map +1 -1
- package/v1/types/ledger.d.ts +1 -0
- package/v1/types/ledger.js +37 -38
- package/v1/types/ledger.js.map +1 -1
- package/v1/types/management_idl.js +6 -7
- package/v1/types/management_idl.js.map +1 -1
- package/v1/types/protocol.d.ts +1 -0
- package/v1/types/transaction.d.ts +22 -3
- package/v1/types/transaction.js +38 -0
- package/v1/types/transaction.js.map +1 -1
- package/v1/utils/account.js +42 -70
- package/v1/utils/account.js.map +1 -1
- package/v1/utils/actor.js +139 -322
- package/v1/utils/actor.js.map +1 -1
- package/v1/utils/auth.js +44 -134
- package/v1/utils/auth.js.map +1 -1
- package/v1/utils/bls.js +41 -109
- package/v1/utils/bls.js.map +1 -1
- package/v1/utils/buffer.js +47 -111
- package/v1/utils/buffer.js.map +1 -1
- package/v1/utils/cbor.js +50 -85
- package/v1/utils/cbor.js.map +1 -1
- package/v1/utils/certificate.js +116 -238
- package/v1/utils/certificate.js.map +1 -1
- package/v1/utils/convert.d.ts +1 -1
- package/v1/utils/convert.js +29 -49
- package/v1/utils/convert.js.map +1 -1
- package/v1/utils/der.js +37 -35
- package/v1/utils/der.js.map +1 -1
- package/v1/utils/errors.js +10 -30
- package/v1/utils/errors.js.map +1 -1
- package/v1/utils/hdkey.js +33 -33
- package/v1/utils/hdkey.js.map +1 -1
- package/v1/utils/http.d.ts +1 -1
- package/v1/utils/http.js +202 -426
- package/v1/utils/http.js.map +1 -1
- package/v1/utils/icrc1.js +24 -41
- package/v1/utils/icrc1.js.map +1 -1
- package/v1/utils/idl.js +780 -1159
- package/v1/utils/idl.js.map +1 -1
- package/v1/utils/json.d.ts +1 -0
- package/v1/utils/json.js +19 -0
- package/v1/utils/json.js.map +1 -0
- package/v1/utils/leb128.js +29 -30
- package/v1/utils/leb128.js.map +1 -1
- package/v1/utils/polling.js +84 -234
- package/v1/utils/polling.js.map +1 -1
- package/v1/utils/principal.js +78 -126
- package/v1/utils/principal.js.map +1 -1
- package/v1/utils/secp256k1.js +68 -134
- package/v1/utils/secp256k1.js.map +1 -1
- package/v1/utils/transaction.js +7 -7
- package/v1/utils/transaction.js.map +1 -1
package/v1/utils/buffer.js
CHANGED
|
@@ -1,67 +1,16 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.compare = exports.fromHex = exports.toHex = exports.zipWith = exports.PipeArrayBuffer = exports.fromHexString = exports.toHexString = exports.concat = void 0;
|
|
40
4
|
/**
|
|
41
5
|
* Concatenate multiple array buffers.
|
|
42
6
|
* @param buffers The buffers to concatenate.
|
|
43
7
|
*/
|
|
44
|
-
function concat() {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
for (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
var result = new Uint8Array(buffers.reduce(function (acc, curr) { return acc + curr.byteLength; }, 0));
|
|
51
|
-
var index = 0;
|
|
52
|
-
try {
|
|
53
|
-
for (var buffers_1 = __values(buffers), buffers_1_1 = buffers_1.next(); !buffers_1_1.done; buffers_1_1 = buffers_1.next()) {
|
|
54
|
-
var b = buffers_1_1.value;
|
|
55
|
-
result.set(new Uint8Array(b), index);
|
|
56
|
-
index += b.byteLength;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
60
|
-
finally {
|
|
61
|
-
try {
|
|
62
|
-
if (buffers_1_1 && !buffers_1_1.done && (_a = buffers_1.return)) _a.call(buffers_1);
|
|
63
|
-
}
|
|
64
|
-
finally { if (e_1) throw e_1.error; }
|
|
8
|
+
function concat(...buffers) {
|
|
9
|
+
const result = new Uint8Array(buffers.reduce((acc, curr) => acc + curr.byteLength, 0));
|
|
10
|
+
let index = 0;
|
|
11
|
+
for (const b of buffers) {
|
|
12
|
+
result.set(new Uint8Array(b), index);
|
|
13
|
+
index += b.byteLength;
|
|
65
14
|
}
|
|
66
15
|
return result;
|
|
67
16
|
}
|
|
@@ -71,7 +20,7 @@ exports.concat = concat;
|
|
|
71
20
|
* @param bytes The array buffer.
|
|
72
21
|
*/
|
|
73
22
|
function toHexString(bytes) {
|
|
74
|
-
return new Uint8Array(bytes).reduce(
|
|
23
|
+
return new Uint8Array(bytes).reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');
|
|
75
24
|
}
|
|
76
25
|
exports.toHexString = toHexString;
|
|
77
26
|
/**
|
|
@@ -80,59 +29,50 @@ exports.toHexString = toHexString;
|
|
|
80
29
|
*/
|
|
81
30
|
function fromHexString(hexString) {
|
|
82
31
|
var _a;
|
|
83
|
-
return new Uint8Array(((_a = hexString.match(/.{1,2}/g)) !== null && _a !== void 0 ? _a : []).map(
|
|
32
|
+
return new Uint8Array(((_a = hexString.match(/.{1,2}/g)) !== null && _a !== void 0 ? _a : []).map((byte) => parseInt(byte, 16)));
|
|
84
33
|
}
|
|
85
34
|
exports.fromHexString = fromHexString;
|
|
86
35
|
/**
|
|
87
36
|
* A class that abstracts a pipe-like ArrayBuffer.
|
|
88
37
|
*/
|
|
89
|
-
|
|
38
|
+
class PipeArrayBuffer {
|
|
90
39
|
/**
|
|
91
40
|
* Creates a new instance of a pipe
|
|
92
41
|
* @param buffer an optional buffer to start with
|
|
93
42
|
* @param length an optional amount of bytes to use for the length.
|
|
94
43
|
*/
|
|
95
|
-
|
|
96
|
-
if (length === void 0) { length = (buffer === null || buffer === void 0 ? void 0 : buffer.byteLength) || 0; }
|
|
44
|
+
constructor(buffer, length = (buffer === null || buffer === void 0 ? void 0 : buffer.byteLength) || 0) {
|
|
97
45
|
this._buffer = buffer || new ArrayBuffer(0);
|
|
98
46
|
this._view = new Uint8Array(this._buffer, 0, length);
|
|
99
47
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
});
|
|
108
|
-
Object.defineProperty(PipeArrayBuffer.prototype, "byteLength", {
|
|
109
|
-
get: function () {
|
|
110
|
-
return this._view.byteLength;
|
|
111
|
-
},
|
|
112
|
-
enumerable: false,
|
|
113
|
-
configurable: true
|
|
114
|
-
});
|
|
48
|
+
get buffer() {
|
|
49
|
+
// Return a copy of the buffer.
|
|
50
|
+
return this._view.slice();
|
|
51
|
+
}
|
|
52
|
+
get byteLength() {
|
|
53
|
+
return this._view.byteLength;
|
|
54
|
+
}
|
|
115
55
|
/**
|
|
116
56
|
* Read `num` number of bytes from the front of the pipe.
|
|
117
57
|
* @param num The number of bytes to read.
|
|
118
58
|
*/
|
|
119
|
-
|
|
120
|
-
|
|
59
|
+
read(num) {
|
|
60
|
+
const result = this._view.subarray(0, num);
|
|
121
61
|
this._view = this._view.subarray(num);
|
|
122
62
|
return result.slice().buffer;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
63
|
+
}
|
|
64
|
+
readUint8() {
|
|
65
|
+
const result = this._view[0];
|
|
126
66
|
this._view = this._view.subarray(1);
|
|
127
67
|
return result;
|
|
128
|
-
}
|
|
68
|
+
}
|
|
129
69
|
/**
|
|
130
70
|
* Write a buffer to the end of the pipe.
|
|
131
71
|
* @param buf The bytes to write.
|
|
132
72
|
*/
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
73
|
+
write(buf) {
|
|
74
|
+
const b = new Uint8Array(buf);
|
|
75
|
+
const offset = this._view.byteLength;
|
|
136
76
|
if (this._view.byteOffset + this._view.byteLength + b.byteLength >= this._buffer.byteLength) {
|
|
137
77
|
// Alloc grow the view to include the new bytes.
|
|
138
78
|
this.alloc(b.byteLength);
|
|
@@ -142,35 +82,30 @@ var PipeArrayBuffer = /** @class */ (function () {
|
|
|
142
82
|
this._view = new Uint8Array(this._buffer, this._view.byteOffset, this._view.byteLength + b.byteLength);
|
|
143
83
|
}
|
|
144
84
|
this._view.set(b, offset);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
},
|
|
153
|
-
enumerable: false,
|
|
154
|
-
configurable: true
|
|
155
|
-
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Whether or not there is more data to read from the buffer
|
|
88
|
+
*/
|
|
89
|
+
get end() {
|
|
90
|
+
return this._view.byteLength === 0;
|
|
91
|
+
}
|
|
156
92
|
/**
|
|
157
93
|
* Allocate a fixed amount of memory in the buffer. This does not affect the view.
|
|
158
94
|
* @param amount A number of bytes to add to the buffer.
|
|
159
95
|
*/
|
|
160
|
-
|
|
96
|
+
alloc(amount) {
|
|
161
97
|
// Add a little bit of exponential growth.
|
|
162
98
|
// tslint:disable-next-line:no-bitwise
|
|
163
|
-
|
|
164
|
-
|
|
99
|
+
const b = new ArrayBuffer(((this._buffer.byteLength + amount) * 1.2) | 0);
|
|
100
|
+
const v = new Uint8Array(b, 0, this._view.byteLength + amount);
|
|
165
101
|
v.set(this._view);
|
|
166
102
|
this._buffer = b;
|
|
167
103
|
this._view = v;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
}());
|
|
104
|
+
}
|
|
105
|
+
}
|
|
171
106
|
exports.PipeArrayBuffer = PipeArrayBuffer;
|
|
172
107
|
function zipWith(xs, ys, f) {
|
|
173
|
-
return xs.map(
|
|
108
|
+
return xs.map((x, i) => f(x, ys[i]));
|
|
174
109
|
}
|
|
175
110
|
exports.zipWith = zipWith;
|
|
176
111
|
/**
|
|
@@ -178,10 +113,10 @@ exports.zipWith = zipWith;
|
|
|
178
113
|
* @param buffer The buffer to return the hexadecimal string of.
|
|
179
114
|
*/
|
|
180
115
|
function toHex(buffer) {
|
|
181
|
-
return
|
|
116
|
+
return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('');
|
|
182
117
|
}
|
|
183
118
|
exports.toHex = toHex;
|
|
184
|
-
|
|
119
|
+
const hexRe = new RegExp(/^([0-9A-F]{2})*$/i);
|
|
185
120
|
/**
|
|
186
121
|
* Transforms a hexadecimal string into an array buffer.
|
|
187
122
|
* @param hex The hexadecimal string to use.
|
|
@@ -190,12 +125,13 @@ function fromHex(hex) {
|
|
|
190
125
|
if (!hexRe.test(hex)) {
|
|
191
126
|
throw new Error('Invalid hexadecimal string.');
|
|
192
127
|
}
|
|
193
|
-
|
|
128
|
+
const buffer = [...hex]
|
|
129
|
+
.reduce((acc, curr, i) => {
|
|
194
130
|
// tslint:disable-next-line:no-bitwise
|
|
195
131
|
acc[(i / 2) | 0] = (acc[(i / 2) | 0] || '') + curr;
|
|
196
132
|
return acc;
|
|
197
133
|
}, [])
|
|
198
|
-
.map(
|
|
134
|
+
.map((x) => Number.parseInt(x, 16));
|
|
199
135
|
return new Uint8Array(buffer).buffer;
|
|
200
136
|
}
|
|
201
137
|
exports.fromHex = fromHex;
|
|
@@ -203,9 +139,9 @@ function compare(b1, b2) {
|
|
|
203
139
|
if (b1.byteLength !== b2.byteLength) {
|
|
204
140
|
return b1.byteLength - b2.byteLength;
|
|
205
141
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
for (
|
|
142
|
+
const u1 = new Uint8Array(b1);
|
|
143
|
+
const u2 = new Uint8Array(b2);
|
|
144
|
+
for (let i = 0; i < u1.length; i++) {
|
|
209
145
|
if (u1[i] !== u2[i]) {
|
|
210
146
|
return u1[i] - u2[i];
|
|
211
147
|
}
|
package/v1/utils/buffer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffer.js","sourceRoot":"","sources":["../../../src/v1/utils/buffer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"buffer.js","sourceRoot":"","sources":["../../../src/v1/utils/buffer.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,SAAgB,MAAM,CAAC,GAAG,OAAsB;IAC9C,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,CAAA;IACtF,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE;QACvB,MAAM,CAAC,GAAG,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+28,54 @@ exports.decode = exports.encode = exports.CborTag = void 0;
|
|
|
28
28
|
// This file is based on:
|
|
29
29
|
// tslint:disable-next-line: max-line-length
|
|
30
30
|
// https://github.com/dfinity-lab/dfinity/blob/9bca65f8edd65701ea6bdb00e0752f9186bbc893/docs/spec/public/index.adoc#cbor-encoding-of-requests-and-responses
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
const borc_1 = require("borc");
|
|
32
|
+
const cbor = __importStar(require("simple-cbor"));
|
|
33
|
+
const simple_cbor_1 = require("simple-cbor");
|
|
34
|
+
const buffer_1 = require("./buffer");
|
|
35
35
|
// We are using hansl/simple-cbor for CBOR serialization, to avoid issues with
|
|
36
36
|
// encoding the uint64 values that the HTTP handler of the client expects for
|
|
37
37
|
// canister IDs. However, simple-cbor does not yet provide deserialization so
|
|
38
38
|
// we are using `Uint8Array` so that we can use the dignifiedquire/borc CBOR
|
|
39
39
|
// decoder.
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
class PrincipalEncoder {
|
|
41
|
+
get name() {
|
|
42
|
+
return 'Principal';
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
enumerable: false,
|
|
48
|
-
configurable: true
|
|
49
|
-
});
|
|
50
|
-
Object.defineProperty(PrincipalEncoder.prototype, "priority", {
|
|
51
|
-
get: function () {
|
|
52
|
-
return 0;
|
|
53
|
-
},
|
|
54
|
-
enumerable: false,
|
|
55
|
-
configurable: true
|
|
56
|
-
});
|
|
57
|
-
PrincipalEncoder.prototype.match = function (value) {
|
|
44
|
+
get priority() {
|
|
45
|
+
return 0;
|
|
46
|
+
}
|
|
47
|
+
match(value) {
|
|
58
48
|
return value && value._isPrincipal === true;
|
|
59
|
-
}
|
|
60
|
-
|
|
49
|
+
}
|
|
50
|
+
encode(v) {
|
|
61
51
|
return cbor.value.bytes(v.toUint8Array());
|
|
62
|
-
};
|
|
63
|
-
return PrincipalEncoder;
|
|
64
|
-
}());
|
|
65
|
-
var BufferEncoder = /** @class */ (function () {
|
|
66
|
-
function BufferEncoder() {
|
|
67
52
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return 1;
|
|
78
|
-
},
|
|
79
|
-
enumerable: false,
|
|
80
|
-
configurable: true
|
|
81
|
-
});
|
|
82
|
-
BufferEncoder.prototype.match = function (value) {
|
|
53
|
+
}
|
|
54
|
+
class BufferEncoder {
|
|
55
|
+
get name() {
|
|
56
|
+
return 'Buffer';
|
|
57
|
+
}
|
|
58
|
+
get priority() {
|
|
59
|
+
return 1;
|
|
60
|
+
}
|
|
61
|
+
match(value) {
|
|
83
62
|
return value instanceof ArrayBuffer || ArrayBuffer.isView(value);
|
|
84
|
-
}
|
|
85
|
-
|
|
63
|
+
}
|
|
64
|
+
encode(v) {
|
|
86
65
|
return cbor.value.bytes(new Uint8Array(v));
|
|
87
|
-
};
|
|
88
|
-
return BufferEncoder;
|
|
89
|
-
}());
|
|
90
|
-
var BigIntEncoder = /** @class */ (function () {
|
|
91
|
-
function BigIntEncoder() {
|
|
92
66
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
configurable: true
|
|
106
|
-
});
|
|
107
|
-
BigIntEncoder.prototype.match = function (value) {
|
|
108
|
-
return typeof value === "bigint";
|
|
109
|
-
};
|
|
110
|
-
BigIntEncoder.prototype.encode = function (v) {
|
|
67
|
+
}
|
|
68
|
+
class BigIntEncoder {
|
|
69
|
+
get name() {
|
|
70
|
+
return 'BigInt';
|
|
71
|
+
}
|
|
72
|
+
get priority() {
|
|
73
|
+
return 1;
|
|
74
|
+
}
|
|
75
|
+
match(value) {
|
|
76
|
+
return typeof value === `bigint`;
|
|
77
|
+
}
|
|
78
|
+
encode(v) {
|
|
111
79
|
// Always use a bigint encoding.
|
|
112
80
|
if (v > BigInt(0)) {
|
|
113
81
|
return cbor.value.tagged(2, cbor.value.bytes((0, buffer_1.fromHex)(v.toString(16))));
|
|
@@ -115,10 +83,9 @@ var BigIntEncoder = /** @class */ (function () {
|
|
|
115
83
|
else {
|
|
116
84
|
return cbor.value.tagged(3, cbor.value.bytes((0, buffer_1.fromHex)((BigInt('-1') * v).toString(16))));
|
|
117
85
|
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
var serializer = simple_cbor_1.SelfDescribeCborSerializer.withDefaultEncoders(true);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const serializer = simple_cbor_1.SelfDescribeCborSerializer.withDefaultEncoders(true);
|
|
122
89
|
serializer.addEncoder(new PrincipalEncoder());
|
|
123
90
|
serializer.addEncoder(new BufferEncoder());
|
|
124
91
|
serializer.addEncoder(new BigIntEncoder());
|
|
@@ -135,9 +102,9 @@ function encode(value) {
|
|
|
135
102
|
}
|
|
136
103
|
exports.encode = encode;
|
|
137
104
|
function decodePositiveBigInt(buf) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
for (
|
|
105
|
+
const len = buf.byteLength;
|
|
106
|
+
let res = BigInt(0);
|
|
107
|
+
for (let i = 0; i < len; i++) {
|
|
141
108
|
// tslint:disable-next-line:no-bitwise
|
|
142
109
|
res = res * BigInt(0x100) + BigInt(buf[i]);
|
|
143
110
|
}
|
|
@@ -159,17 +126,15 @@ function decodePositiveBigInt(buf) {
|
|
|
159
126
|
// }
|
|
160
127
|
// }
|
|
161
128
|
function decode(input) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
var decoder = new borc_1.Decoder({
|
|
129
|
+
const buffer = new Uint8Array(input);
|
|
130
|
+
const decoder = new borc_1.Decoder({
|
|
165
131
|
size: buffer.byteLength,
|
|
166
|
-
tags:
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
_a)
|
|
132
|
+
tags: {
|
|
133
|
+
// Override tags 2 and 3 for BigInt support (borc supports only BigNumber).
|
|
134
|
+
2: (val) => decodePositiveBigInt(val),
|
|
135
|
+
3: (val) => -decodePositiveBigInt(val),
|
|
136
|
+
[CborTag.Semantic]: (value) => value
|
|
137
|
+
}
|
|
173
138
|
});
|
|
174
139
|
//@ts-ignore
|
|
175
140
|
return decoder.decodeFirst(buffer);
|
package/v1/utils/cbor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cbor.js","sourceRoot":"","sources":["../../../src/v1/utils/cbor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sCAAsC;AACtC,yBAAyB;AACzB,4CAA4C;AAC5C,2JAA2J;AAC3J
|
|
1
|
+
{"version":3,"file":"cbor.js","sourceRoot":"","sources":["../../../src/v1/utils/cbor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sCAAsC;AACtC,yBAAyB;AACzB,4CAA4C;AAC5C,2JAA2J;AAC3J,+BAA8B;AAC9B,kDAAmC;AACnC,6CAAqE;AACrE,qCAAkC;AAElC,8EAA8E;AAC9E,6EAA6E;AAC7E,6EAA6E;AAC7E,4EAA4E;AAC5E,WAAW;AAEX,MAAM,gBAAgB;IACpB,IAAW,IAAI;QACb,OAAO,WAAW,CAAA;IACpB,CAAC;IAED,IAAW,QAAQ;QACjB,OAAO,CAAC,CAAA;IACV,CAAC;IAEM,KAAK,CAAC,KAAU;QACrB,OAAO,KAAK,IAAI,KAAK,CAAC,YAAY,KAAK,IAAI,CAAA;IAC7C,CAAC;IAEM,MAAM,CAAC,CAAY;QACxB,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC,CAAA;IAC3C,CAAC;CACF;AAED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