@airgap/icp 0.13.15-beta.1 → 0.13.15-beta.3
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.d.ts +1 -1
- package/v1/block-explorer/ICPBlockExplorer.js +16 -49
- package/v1/block-explorer/ICPBlockExplorer.js.map +1 -1
- package/v1/index.d.ts +2 -2
- package/v1/index.js +7 -5
- package/v1/index.js.map +1 -1
- package/v1/module/ICPModule.d.ts +2 -4
- 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 +38 -0
- package/v1/protocol/ICPGovernance.js +748 -0
- package/v1/protocol/ICPGovernance.js.map +1 -0
- package/v1/protocol/ICPImplementation.d.ts +27 -5
- package/v1/protocol/ICPImplementation.js +368 -250
- package/v1/protocol/ICPImplementation.js.map +1 -1
- package/v1/protocol/ICPProtocol.d.ts +33 -8
- package/v1/protocol/ICPProtocol.js +508 -322
- package/v1/protocol/ICPProtocol.js.map +1 -1
- package/v1/protocol/icrc/CkBTCProtocol.js +138 -225
- package/v1/protocol/icrc/CkBTCProtocol.js.map +1 -1
- package/v1/protocol/icrc/ICRC1Protocol.d.ts +4 -4
- 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 +17 -4
- package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -1
- package/v1/serializer/v3/schemas/generated/transaction-sign-request-icp.json +35 -6
- package/v1/serializer/v3/serializer-companion.js +86 -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 +2 -0
- package/v1/types/governance.js +268 -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 +2 -1
- package/v1/types/transaction.d.ts +21 -3
- package/v1/types/transaction.js +28 -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/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/secp256k1.js
CHANGED
|
@@ -1,19 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
3
|
if (k2 === undefined) k2 = k;
|
|
19
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -46,49 +31,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
46
31
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
47
32
|
});
|
|
48
33
|
};
|
|
49
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
50
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
51
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
52
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
53
|
-
function step(op) {
|
|
54
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
55
|
-
while (_) try {
|
|
56
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
57
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
58
|
-
switch (op[0]) {
|
|
59
|
-
case 0: case 1: t = op; break;
|
|
60
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
61
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
62
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
63
|
-
default:
|
|
64
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
65
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
66
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
67
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
68
|
-
if (t[2]) _.ops.pop();
|
|
69
|
-
_.trys.pop(); continue;
|
|
70
|
-
}
|
|
71
|
-
op = body.call(thisArg, _);
|
|
72
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
73
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
77
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
78
|
-
if (!m) return o;
|
|
79
|
-
var i = m.call(o), r, ar = [], e;
|
|
80
|
-
try {
|
|
81
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
82
|
-
}
|
|
83
|
-
catch (error) { e = { error: error }; }
|
|
84
|
-
finally {
|
|
85
|
-
try {
|
|
86
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
87
|
-
}
|
|
88
|
-
finally { if (e) throw e.error; }
|
|
89
|
-
}
|
|
90
|
-
return ar;
|
|
91
|
-
};
|
|
92
34
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
93
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
94
36
|
};
|
|
@@ -96,17 +38,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
96
38
|
exports.Secp256k1KeyIdentity = exports.Secp256k1PublicKey = void 0;
|
|
97
39
|
/* eslint-disable no-underscore-dangle */
|
|
98
40
|
// tslint:disable: max-classes-per-file
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
41
|
+
const nacl = __importStar(require("@airgap/coinlib-core/dependencies/src/tweetnacl-1.0.1/nacl"));
|
|
42
|
+
const bip39_1 = require("bip39");
|
|
43
|
+
const js_sha256_1 = require("js-sha256");
|
|
44
|
+
const secp256k1_1 = __importDefault(require("secp256k1"));
|
|
45
|
+
const auth_1 = require("./auth");
|
|
46
|
+
const buffer_1 = require("./buffer");
|
|
47
|
+
const der_1 = require("./der");
|
|
48
|
+
const hdkey_1 = __importDefault(require("./hdkey"));
|
|
49
|
+
class Secp256k1PublicKey {
|
|
108
50
|
// `fromRaw` and `fromDer` should be used for instantiation, not this constructor.
|
|
109
|
-
|
|
51
|
+
constructor(key) {
|
|
110
52
|
key.byteLength;
|
|
111
53
|
this.rawKey = key;
|
|
112
54
|
this.derKey = Secp256k1PublicKey.derEncode(key);
|
|
@@ -116,37 +58,34 @@ var Secp256k1PublicKey = /** @class */ (function () {
|
|
|
116
58
|
* @param {PublicKey} key
|
|
117
59
|
* @returns {Secp256k1PublicKey} Instance of Secp256k1PublicKey
|
|
118
60
|
*/
|
|
119
|
-
|
|
61
|
+
static from(key) {
|
|
120
62
|
return this.fromDer(key.toDer());
|
|
121
|
-
}
|
|
122
|
-
|
|
63
|
+
}
|
|
64
|
+
static fromRaw(rawKey) {
|
|
123
65
|
return new Secp256k1PublicKey(rawKey);
|
|
124
|
-
}
|
|
125
|
-
|
|
66
|
+
}
|
|
67
|
+
static fromDer(derKey) {
|
|
126
68
|
return new Secp256k1PublicKey(this.derDecode(derKey));
|
|
127
|
-
}
|
|
128
|
-
|
|
69
|
+
}
|
|
70
|
+
static derEncode(publicKey) {
|
|
129
71
|
return (0, der_1.wrapDER)(publicKey, der_1.SECP256K1_OID).buffer;
|
|
130
|
-
}
|
|
131
|
-
|
|
72
|
+
}
|
|
73
|
+
static derDecode(key) {
|
|
132
74
|
return (0, der_1.unwrapDER)(key, der_1.SECP256K1_OID);
|
|
133
|
-
}
|
|
134
|
-
|
|
75
|
+
}
|
|
76
|
+
toDer() {
|
|
135
77
|
return this.derKey;
|
|
136
|
-
}
|
|
137
|
-
|
|
78
|
+
}
|
|
79
|
+
toRaw() {
|
|
138
80
|
return this.rawKey;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
}());
|
|
81
|
+
}
|
|
82
|
+
}
|
|
142
83
|
exports.Secp256k1PublicKey = Secp256k1PublicKey;
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
_this._publicKey = publicKey;
|
|
149
|
-
return _this;
|
|
84
|
+
class Secp256k1KeyIdentity extends auth_1.SignIdentity {
|
|
85
|
+
constructor(publicKey, _privateKey) {
|
|
86
|
+
super();
|
|
87
|
+
this._privateKey = _privateKey;
|
|
88
|
+
this._publicKey = publicKey;
|
|
150
89
|
}
|
|
151
90
|
/**
|
|
152
91
|
* Generates an identity. If a seed is provided, the keys are generated from the
|
|
@@ -156,11 +95,11 @@ var Secp256k1KeyIdentity = /** @class */ (function (_super) {
|
|
|
156
95
|
* @param {Uint8Array} seed the optional seed
|
|
157
96
|
* @returns {Secp256k1KeyIdentity}
|
|
158
97
|
*/
|
|
159
|
-
|
|
98
|
+
static generate(seed) {
|
|
160
99
|
if (seed && seed.byteLength !== 32) {
|
|
161
100
|
throw new Error('Secp256k1 Seed needs to be 32 bytes long.');
|
|
162
101
|
}
|
|
163
|
-
|
|
102
|
+
let privateKey;
|
|
164
103
|
if (seed) {
|
|
165
104
|
// private key from seed according to https://en.bitcoin.it/wiki/BIP_0032
|
|
166
105
|
// master key generation:
|
|
@@ -175,104 +114,99 @@ var Secp256k1KeyIdentity = /** @class */ (function (_super) {
|
|
|
175
114
|
privateKey = new Uint8Array(nacl.randomBytes(32));
|
|
176
115
|
}
|
|
177
116
|
}
|
|
178
|
-
|
|
179
|
-
|
|
117
|
+
const publicKeyRaw = secp256k1_1.default.publicKeyCreate(privateKey, false);
|
|
118
|
+
const publicKey = Secp256k1PublicKey.fromRaw(publicKeyRaw);
|
|
180
119
|
return new this(publicKey, privateKey);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
120
|
+
}
|
|
121
|
+
static fromParsedJson(obj) {
|
|
122
|
+
const [publicKeyRaw, privateKeyRaw] = obj;
|
|
184
123
|
return new Secp256k1KeyIdentity(Secp256k1PublicKey.fromRaw((0, buffer_1.fromHexString)(publicKeyRaw)), (0, buffer_1.fromHexString)(privateKeyRaw));
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
124
|
+
}
|
|
125
|
+
static fromJSON(json) {
|
|
126
|
+
const parsed = JSON.parse(json);
|
|
188
127
|
if (Array.isArray(parsed)) {
|
|
189
128
|
if (typeof parsed[0] === 'string' && typeof parsed[1] === 'string') {
|
|
190
129
|
return this.fromParsedJson([parsed[0], parsed[1]]);
|
|
191
130
|
}
|
|
192
131
|
throw new Error('Deserialization error: JSON must have at least 2 items.');
|
|
193
132
|
}
|
|
194
|
-
throw new Error(
|
|
195
|
-
}
|
|
133
|
+
throw new Error(`Deserialization error: Invalid JSON type for string: ${JSON.stringify(json)}`);
|
|
134
|
+
}
|
|
196
135
|
/**
|
|
197
136
|
* 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
|
|
198
137
|
* @param {ArrayBuffer} publicKey
|
|
199
138
|
* @param {ArrayBuffer} privateKey
|
|
200
139
|
* @returns {Secp256k1KeyIdentity}
|
|
201
140
|
*/
|
|
202
|
-
|
|
141
|
+
static fromKeyPair(publicKey, privateKey) {
|
|
203
142
|
return new Secp256k1KeyIdentity(Secp256k1PublicKey.fromRaw(publicKey), privateKey);
|
|
204
|
-
}
|
|
143
|
+
}
|
|
205
144
|
/**
|
|
206
145
|
* 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.
|
|
207
146
|
* @param {ArrayBuffer} secretKey
|
|
208
147
|
* @returns {Secp256k1KeyIdentity}
|
|
209
148
|
*/
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
149
|
+
static fromSecretKey(secretKey) {
|
|
150
|
+
const publicKey = secp256k1_1.default.publicKeyCreate(new Uint8Array(secretKey), false);
|
|
151
|
+
const identity = Secp256k1KeyIdentity.fromKeyPair(publicKey, new Uint8Array(secretKey));
|
|
213
152
|
return identity;
|
|
214
|
-
}
|
|
153
|
+
}
|
|
215
154
|
/**
|
|
216
155
|
* 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.
|
|
217
156
|
* @param {string | string[]} seedPhrase - either an array of words or a string of words separated by spaces.
|
|
218
157
|
* @param password - optional password to be used by bip39
|
|
219
158
|
* @returns Secp256k1KeyIdentity
|
|
220
159
|
*/
|
|
221
|
-
|
|
222
|
-
if (derivationPath === void 0) { derivationPath = "m/44'/223'/0'/0/0"; }
|
|
160
|
+
static fromSeedPhrase(seedPhrase, password, derivationPath = "m/44'/223'/0'/0/0") {
|
|
223
161
|
// Convert to string for convenience
|
|
224
|
-
|
|
162
|
+
const phrase = Array.isArray(seedPhrase) ? seedPhrase.join(' ') : seedPhrase;
|
|
225
163
|
// Warn if provided phrase is not conventional
|
|
226
164
|
if (phrase.split(' ').length < 12 || phrase.split(' ').length > 24) {
|
|
227
165
|
console.warn('Warning - an unusually formatted seed phrase has been provided. Decoding may not work as expected');
|
|
228
166
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
167
|
+
const seed = (0, bip39_1.mnemonicToSeedSync)(phrase, password);
|
|
168
|
+
const root = hdkey_1.default.fromMasterSeed(seed);
|
|
169
|
+
const addrnode = root.derive(derivationPath);
|
|
232
170
|
return Secp256k1KeyIdentity.fromSecretKey(addrnode.privateKey);
|
|
233
|
-
}
|
|
171
|
+
}
|
|
234
172
|
/**
|
|
235
173
|
* Serialize this key to JSON-serializable object.
|
|
236
174
|
* @returns {JsonableSecp256k1Identity}
|
|
237
175
|
*/
|
|
238
|
-
|
|
176
|
+
toJSON() {
|
|
239
177
|
return [(0, buffer_1.toHexString)(this._publicKey.toRaw()), (0, buffer_1.toHexString)(this._privateKey)];
|
|
240
|
-
}
|
|
178
|
+
}
|
|
241
179
|
/**
|
|
242
180
|
* Return a copy of the key pair.
|
|
243
181
|
* @returns {KeyPair}
|
|
244
182
|
*/
|
|
245
|
-
|
|
183
|
+
getKeyPair() {
|
|
246
184
|
return {
|
|
247
185
|
secretKey: this._privateKey,
|
|
248
186
|
publicKey: this._publicKey
|
|
249
187
|
};
|
|
250
|
-
}
|
|
188
|
+
}
|
|
251
189
|
/**
|
|
252
190
|
* Return the public key.
|
|
253
191
|
* @returns {Secp256k1PublicKey}
|
|
254
192
|
*/
|
|
255
|
-
|
|
193
|
+
getPublicKey() {
|
|
256
194
|
return this._publicKey;
|
|
257
|
-
}
|
|
195
|
+
}
|
|
258
196
|
/**
|
|
259
197
|
* Signs a blob of data, with this identity's private key.
|
|
260
198
|
* @param {ArrayBuffer} challenge - challenge to sign with this identity's secretKey, producing a signature
|
|
261
199
|
* @returns {Promise<Signature>} signature
|
|
262
200
|
*/
|
|
263
|
-
|
|
264
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
signature = secp256k1_1.default.ecdsaSign(new Uint8Array(hash.digest()), new Uint8Array(this._privateKey)).signature.buffer;
|
|
270
|
-
return [2 /*return*/, signature];
|
|
271
|
-
});
|
|
201
|
+
sign(challenge) {
|
|
202
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
203
|
+
const hash = js_sha256_1.sha256.create();
|
|
204
|
+
hash.update(challenge);
|
|
205
|
+
const signature = secp256k1_1.default.ecdsaSign(new Uint8Array(hash.digest()), new Uint8Array(this._privateKey)).signature.buffer;
|
|
206
|
+
return signature;
|
|
272
207
|
});
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
}(auth_1.SignIdentity));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
276
210
|
exports.Secp256k1KeyIdentity = Secp256k1KeyIdentity;
|
|
277
211
|
exports.default = Secp256k1KeyIdentity;
|
|
278
212
|
//# sourceMappingURL=secp256k1.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secp256k1.js","sourceRoot":"","sources":["../../../src/v1/utils/secp256k1.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"secp256k1.js","sourceRoot":"","sources":["../../../src/v1/utils/secp256k1.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAAyC;AACzC,uCAAuC;AACvC,iGAAkF;AAClF,iCAA0C;AAC1C,yCAAkC;AAClC,0DAAiC;AAEjC,iCAAyF;AACzF,qCAAqD;AACrD,+BAAyD;AACzD,oDAA2B;AAM3B,MAAa,kBAAkB;IA8B7B,kFAAkF;IAClF,YAAoB,GAAgB;QAClC,GAAG,CAAC,UAAU,CAAA;QACd,IAAI,CAAC,MAAM,GAAG,GAAG,CAAA;QACjB,IAAI,CAAC,MAAM,GAAG,kBAAkB,CAAC,SAA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AC,cAAc,CAAC,IAAI,CAAC,CAAA;QACvC,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,CAAA;QAE5C,OAAO,oBAAoB,CAAC,aAAa,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAA;IAChE,CAAC;IASD;;;OAGG;IACI,MAAM;QACX,OAAO,CAAC,IAAA,oBAAW,EAAC,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,EAAE,IAAA,oBAAW,EAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAA;IAC9E,CAAC;IAED;;;OAGG;IACI,UAAU;QACf,OAAO;YACL,SAAS,EAAE,IAAI,CAAC,WAAW;YAC3B,SAAS,EAAE,IAAI,CAAC,UAAU;SAC3B,CAAA;IACH,CAAC;IAED;;;OAGG;IACI,YAAY;QACjB,OAAO,IAAI,CAAC,UAAU,CAAA;IACxB,CAAC;IAED;;;;OAIG;IACU,IAAI,CAAC,SAAsB;;YACtC,MAAM,IAAI,GAAG,kBAAM,CAAC,MAAM,EAAE,CAAA;YAC5B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;YACtB,MAAM,SAAS,GAAG,mBAAS,CAAC,SAAS,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,IAAI,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAA;YACvH,OAAO,SAAsB,CAAA;QAC/B,CAAC;KAAA;CACF;AA9ID,oDA8IC;AAED,kBAAe,oBAAoB,CAAA"}
|
package/v1/utils/transaction.js
CHANGED
|
@@ -27,17 +27,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.decodeTx = exports.encodeTx = void 0;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
const coinlib_core_1 = require("@airgap/coinlib-core");
|
|
31
|
+
const bs58check = __importStar(require("@airgap/coinlib-core/dependencies/src/bs58check-2.1.2/index"));
|
|
32
|
+
const errors_1 = require("@airgap/coinlib-core/errors");
|
|
33
|
+
const base64Check_1 = __importDefault(require("@airgap/coinlib-core/utils/base64Check"));
|
|
34
|
+
const TRANSACTION_PREFIX = 'tx_';
|
|
35
35
|
function encodeTx(transaction) {
|
|
36
|
-
return
|
|
36
|
+
return `${TRANSACTION_PREFIX}${base64Check_1.default.encode(transaction)}`;
|
|
37
37
|
}
|
|
38
38
|
exports.encodeTx = encodeTx;
|
|
39
39
|
function decodeTx(transaction) {
|
|
40
|
-
|
|
40
|
+
const encoded = transaction.replace(TRANSACTION_PREFIX, '');
|
|
41
41
|
try {
|
|
42
42
|
return base64Check_1.default.decode(encoded);
|
|
43
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../../src/v1/utils/transaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../../src/v1/utils/transaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAA6C;AAC7C,uGAAwF;AACxF,wDAA+D;AAC/D,yFAA8D;AAE9D,MAAM,kBAAkB,GAAW,KAAK,CAAA;AAExC,SAAgB,QAAQ,CAAC,WAAgB;IACvC,OAAO,GAAG,kBAAkB,GAAG,qBAAS,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAA;AAChE,CAAC;AAFD,4BAEC;AAED,SAAgB,QAAQ,CAAC,WAAmB;IAC1C,MAAM,OAAO,GAAW,WAAW,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAA;IAEnE,IAAI;QACF,OAAO,qBAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;KACjC;IAAC,OAAO,KAAK,EAAE;QACd,EAAE;KACH;IAED,IAAI;QACF,OAAO,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;KACjC;IAAC,OAAO,KAAK,EAAE;QACd,EAAE;KACH;IAED,MAAM,IAAI,0BAAiB,CAAC,qBAAM,CAAC,SAAS,EAAE,qBAAqB,CAAC,CAAA;AACtE,CAAC;AAhBD,4BAgBC"}
|