@airgap/icp 0.13.11-beta.1 → 0.13.11-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/index.d.ts +1 -0
  2. package/index.js +18 -0
  3. package/index.js.map +1 -0
  4. package/package.json +4 -8
  5. package/v1/block-explorer/ICPBlockExplorer.d.ts +9 -0
  6. package/v1/block-explorer/ICPBlockExplorer.js +74 -0
  7. package/v1/block-explorer/ICPBlockExplorer.js.map +1 -0
  8. package/v1/index.d.ts +13 -0
  9. package/v1/index.js +11 -0
  10. package/v1/index.js.map +1 -0
  11. package/v1/module/ICPModule.d.ts +15 -0
  12. package/v1/module/ICPModule.js +107 -0
  13. package/v1/module/ICPModule.js.map +1 -0
  14. package/v1/module.d.ts +3 -0
  15. package/v1/module.js +24 -0
  16. package/v1/module.js.map +1 -0
  17. package/v1/protocol/ICPImplementation.d.ts +26 -0
  18. package/v1/protocol/ICPImplementation.js +344 -0
  19. package/v1/protocol/ICPImplementation.js.map +1 -0
  20. package/v1/protocol/ICPProtocol.d.ts +42 -0
  21. package/v1/protocol/ICPProtocol.js +416 -0
  22. package/v1/protocol/ICPProtocol.js.map +1 -0
  23. package/v1/serializer/v3/schemas/converter/transaction-converter.d.ts +7 -0
  24. package/v1/serializer/v3/schemas/converter/transaction-converter.js +21 -0
  25. package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -0
  26. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-icp.d.ts +4 -0
  27. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-icp.js +3 -0
  28. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-icp.js.map +1 -0
  29. package/v1/serializer/v3/schemas/definitions/transaction-sign-response-icp.d.ts +3 -0
  30. package/v1/serializer/v3/schemas/definitions/transaction-sign-response-icp.js +3 -0
  31. package/v1/serializer/v3/schemas/definitions/transaction-sign-response-icp.js.map +1 -0
  32. package/v1/serializer/v3/schemas/generated/transaction-sign-request-icp.json +32 -0
  33. package/v1/serializer/v3/schemas/generated/transaction-sign-response-icp.json +19 -0
  34. package/v1/serializer/v3/serializer-companion.d.ts +14 -0
  35. package/v1/serializer/v3/serializer-companion.js +174 -0
  36. package/v1/serializer/v3/serializer-companion.js.map +1 -0
  37. package/v1/serializer/v3/validators/transaction-validator.d.ts +10 -0
  38. package/v1/serializer/v3/validators/transaction-validator.js +100 -0
  39. package/v1/serializer/v3/validators/transaction-validator.js.map +1 -0
  40. package/v1/serializer/v3/validators/validators.d.ts +5 -0
  41. package/v1/serializer/v3/validators/validators.js +106 -0
  42. package/v1/serializer/v3/validators/validators.js.map +1 -0
  43. package/v1/types/crypto.d.ts +2 -0
  44. package/v1/types/crypto.js +3 -0
  45. package/v1/types/crypto.js.map +1 -0
  46. package/v1/types/governance.d.ts +580 -0
  47. package/v1/types/governance.js +796 -0
  48. package/v1/types/governance.js.map +1 -0
  49. package/v1/types/ledger.d.ts +143 -0
  50. package/v1/types/ledger.js +146 -0
  51. package/v1/types/ledger.js.map +1 -0
  52. package/v1/types/management_idl.d.ts +7 -0
  53. package/v1/types/management_idl.js +72 -0
  54. package/v1/types/management_idl.js.map +1 -0
  55. package/v1/types/protocol.d.ts +8 -0
  56. package/v1/types/protocol.js +3 -0
  57. package/v1/types/protocol.js.map +1 -0
  58. package/v1/types/transaction.d.ts +11 -0
  59. package/v1/types/transaction.js +3 -0
  60. package/v1/types/transaction.js.map +1 -0
  61. package/v1/utils/account.d.ts +24 -0
  62. package/v1/utils/account.js +112 -0
  63. package/v1/utils/account.js.map +1 -0
  64. package/v1/utils/actor.d.ts +246 -0
  65. package/v1/utils/actor.js +458 -0
  66. package/v1/utils/actor.js.map +1 -0
  67. package/v1/utils/agent.d.ts +156 -0
  68. package/v1/utils/agent.js +16 -0
  69. package/v1/utils/agent.js.map +1 -0
  70. package/v1/utils/auth.d.ts +110 -0
  71. package/v1/utils/auth.js +261 -0
  72. package/v1/utils/auth.js.map +1 -0
  73. package/v1/utils/bls.d.ts +38 -0
  74. package/v1/utils/bls.js +204 -0
  75. package/v1/utils/bls.js.map +1 -0
  76. package/v1/utils/buffer.d.ts +70 -0
  77. package/v1/utils/buffer.js +216 -0
  78. package/v1/utils/buffer.js.map +1 -0
  79. package/v1/utils/cbor.d.ts +9 -0
  80. package/v1/utils/cbor.js +178 -0
  81. package/v1/utils/cbor.js.map +1 -0
  82. package/v1/utils/certificate.d.ts +74 -0
  83. package/v1/utils/certificate.js +396 -0
  84. package/v1/utils/certificate.js.map +1 -0
  85. package/v1/utils/convert.d.ts +8 -0
  86. package/v1/utils/convert.js +80 -0
  87. package/v1/utils/convert.js.map +1 -0
  88. package/v1/utils/crypto.d.ts +0 -0
  89. package/v1/utils/crypto.js +104 -0
  90. package/v1/utils/crypto.js.map +1 -0
  91. package/v1/utils/der.d.ts +35 -0
  92. package/v1/utils/der.js +176 -0
  93. package/v1/utils/der.js.map +1 -0
  94. package/v1/utils/errors.d.ts +7 -0
  95. package/v1/utils/errors.js +38 -0
  96. package/v1/utils/errors.js.map +1 -0
  97. package/v1/utils/hdkey.d.ts +13 -0
  98. package/v1/utils/hdkey.js +265 -0
  99. package/v1/utils/hdkey.js.map +1 -0
  100. package/v1/utils/http.d.ts +284 -0
  101. package/v1/utils/http.js +614 -0
  102. package/v1/utils/http.js.map +1 -0
  103. package/v1/utils/idl.d.ts +515 -0
  104. package/v1/utils/idl.js +2103 -0
  105. package/v1/utils/idl.js.map +1 -0
  106. package/v1/utils/leb128.d.ts +63 -0
  107. package/v1/utils/leb128.js +224 -0
  108. package/v1/utils/leb128.js.map +1 -0
  109. package/v1/utils/polling.d.ts +59 -0
  110. package/v1/utils/polling.js +325 -0
  111. package/v1/utils/polling.js.map +1 -0
  112. package/v1/utils/principal.d.ts +58 -0
  113. package/v1/utils/principal.js +543 -0
  114. package/v1/utils/principal.js.map +1 -0
  115. package/v1/utils/secp256k1.d.ts +79 -0
  116. package/v1/utils/secp256k1.js +278 -0
  117. package/v1/utils/secp256k1.js.map +1 -0
  118. package/v1/utils/transaction.d.ts +3 -0
  119. package/v1/utils/transaction.js +56 -0
  120. package/v1/utils/transaction.js.map +1 -0
@@ -0,0 +1,278 @@
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
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ var desc = Object.getOwnPropertyDescriptor(m, k);
20
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
+ desc = { enumerable: true, get: function() { return m[k]; } };
22
+ }
23
+ Object.defineProperty(o, k2, desc);
24
+ }) : (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ o[k2] = m[k];
27
+ }));
28
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
30
+ }) : function(o, v) {
31
+ o["default"] = v;
32
+ });
33
+ var __importStar = (this && this.__importStar) || function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
41
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
42
+ return new (P || (P = Promise))(function (resolve, reject) {
43
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
44
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
45
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
46
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
47
+ });
48
+ };
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
93
+ return (mod && mod.__esModule) ? mod : { "default": mod };
94
+ };
95
+ Object.defineProperty(exports, "__esModule", { value: true });
96
+ exports.Secp256k1KeyIdentity = exports.Secp256k1PublicKey = void 0;
97
+ /* eslint-disable no-underscore-dangle */
98
+ // tslint:disable: max-classes-per-file
99
+ var nacl = __importStar(require("@airgap/coinlib-core/dependencies/src/tweetnacl-1.0.1/nacl"));
100
+ var bip39_1 = require("bip39");
101
+ var js_sha256_1 = require("js-sha256");
102
+ var secp256k1_1 = __importDefault(require("secp256k1"));
103
+ var auth_1 = require("./auth");
104
+ var buffer_1 = require("./buffer");
105
+ var der_1 = require("./der");
106
+ var hdkey_1 = __importDefault(require("./hdkey"));
107
+ var Secp256k1PublicKey = /** @class */ (function () {
108
+ // `fromRaw` and `fromDer` should be used for instantiation, not this constructor.
109
+ function Secp256k1PublicKey(key) {
110
+ key.byteLength;
111
+ this.rawKey = key;
112
+ this.derKey = Secp256k1PublicKey.derEncode(key);
113
+ }
114
+ /**
115
+ * Construct Secp256k1PublicKey from an existing PublicKey
116
+ * @param {PublicKey} key
117
+ * @returns {Secp256k1PublicKey} Instance of Secp256k1PublicKey
118
+ */
119
+ Secp256k1PublicKey.from = function (key) {
120
+ return this.fromDer(key.toDer());
121
+ };
122
+ Secp256k1PublicKey.fromRaw = function (rawKey) {
123
+ return new Secp256k1PublicKey(rawKey);
124
+ };
125
+ Secp256k1PublicKey.fromDer = function (derKey) {
126
+ return new Secp256k1PublicKey(this.derDecode(derKey));
127
+ };
128
+ Secp256k1PublicKey.derEncode = function (publicKey) {
129
+ return (0, der_1.wrapDER)(publicKey, der_1.SECP256K1_OID).buffer;
130
+ };
131
+ Secp256k1PublicKey.derDecode = function (key) {
132
+ return (0, der_1.unwrapDER)(key, der_1.SECP256K1_OID);
133
+ };
134
+ Secp256k1PublicKey.prototype.toDer = function () {
135
+ return this.derKey;
136
+ };
137
+ Secp256k1PublicKey.prototype.toRaw = function () {
138
+ return this.rawKey;
139
+ };
140
+ return Secp256k1PublicKey;
141
+ }());
142
+ exports.Secp256k1PublicKey = Secp256k1PublicKey;
143
+ var Secp256k1KeyIdentity = /** @class */ (function (_super) {
144
+ __extends(Secp256k1KeyIdentity, _super);
145
+ function Secp256k1KeyIdentity(publicKey, _privateKey) {
146
+ var _this = _super.call(this) || this;
147
+ _this._privateKey = _privateKey;
148
+ _this._publicKey = publicKey;
149
+ return _this;
150
+ }
151
+ /**
152
+ * Generates an identity. If a seed is provided, the keys are generated from the
153
+ * seed according to BIP 0032. Otherwise, the key pair is randomly generated.
154
+ * This method throws an error in case the seed is not 32 bytes long or invalid
155
+ * for use as a private key.
156
+ * @param {Uint8Array} seed the optional seed
157
+ * @returns {Secp256k1KeyIdentity}
158
+ */
159
+ Secp256k1KeyIdentity.generate = function (seed) {
160
+ if (seed && seed.byteLength !== 32) {
161
+ throw new Error('Secp256k1 Seed needs to be 32 bytes long.');
162
+ }
163
+ var privateKey;
164
+ if (seed) {
165
+ // private key from seed according to https://en.bitcoin.it/wiki/BIP_0032
166
+ // master key generation:
167
+ privateKey = seed;
168
+ if (!secp256k1_1.default.privateKeyVerify(privateKey)) {
169
+ throw new Error('The seed is invalid.');
170
+ }
171
+ }
172
+ else {
173
+ privateKey = new Uint8Array(nacl.randomBytes(32));
174
+ while (!secp256k1_1.default.privateKeyVerify(privateKey)) {
175
+ privateKey = new Uint8Array(nacl.randomBytes(32));
176
+ }
177
+ }
178
+ var publicKeyRaw = secp256k1_1.default.publicKeyCreate(privateKey, false);
179
+ var publicKey = Secp256k1PublicKey.fromRaw(publicKeyRaw);
180
+ return new this(publicKey, privateKey);
181
+ };
182
+ Secp256k1KeyIdentity.fromParsedJson = function (obj) {
183
+ var _a = __read(obj, 2), publicKeyRaw = _a[0], privateKeyRaw = _a[1];
184
+ return new Secp256k1KeyIdentity(Secp256k1PublicKey.fromRaw((0, buffer_1.fromHexString)(publicKeyRaw)), (0, buffer_1.fromHexString)(privateKeyRaw));
185
+ };
186
+ Secp256k1KeyIdentity.fromJSON = function (json) {
187
+ var parsed = JSON.parse(json);
188
+ if (Array.isArray(parsed)) {
189
+ if (typeof parsed[0] === 'string' && typeof parsed[1] === 'string') {
190
+ return this.fromParsedJson([parsed[0], parsed[1]]);
191
+ }
192
+ throw new Error('Deserialization error: JSON must have at least 2 items.');
193
+ }
194
+ throw new Error("Deserialization error: Invalid JSON type for string: ".concat(JSON.stringify(json)));
195
+ };
196
+ /**
197
+ * 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
+ * @param {ArrayBuffer} publicKey
199
+ * @param {ArrayBuffer} privateKey
200
+ * @returns {Secp256k1KeyIdentity}
201
+ */
202
+ Secp256k1KeyIdentity.fromKeyPair = function (publicKey, privateKey) {
203
+ return new Secp256k1KeyIdentity(Secp256k1PublicKey.fromRaw(publicKey), privateKey);
204
+ };
205
+ /**
206
+ * 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
+ * @param {ArrayBuffer} secretKey
208
+ * @returns {Secp256k1KeyIdentity}
209
+ */
210
+ Secp256k1KeyIdentity.fromSecretKey = function (secretKey) {
211
+ var publicKey = secp256k1_1.default.publicKeyCreate(new Uint8Array(secretKey), false);
212
+ var identity = Secp256k1KeyIdentity.fromKeyPair(publicKey, new Uint8Array(secretKey));
213
+ return identity;
214
+ };
215
+ /**
216
+ * 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
+ * @param {string | string[]} seedPhrase - either an array of words or a string of words separated by spaces.
218
+ * @param password - optional password to be used by bip39
219
+ * @returns Secp256k1KeyIdentity
220
+ */
221
+ Secp256k1KeyIdentity.fromSeedPhrase = function (seedPhrase, password, derivationPath) {
222
+ if (derivationPath === void 0) { derivationPath = "m/44'/223'/0'/0/0"; }
223
+ // Convert to string for convenience
224
+ var phrase = Array.isArray(seedPhrase) ? seedPhrase.join(' ') : seedPhrase;
225
+ // Warn if provided phrase is not conventional
226
+ if (phrase.split(' ').length < 12 || phrase.split(' ').length > 24) {
227
+ console.warn('Warning - an unusually formatted seed phrase has been provided. Decoding may not work as expected');
228
+ }
229
+ var seed = (0, bip39_1.mnemonicToSeedSync)(phrase, password);
230
+ var root = hdkey_1.default.fromMasterSeed(seed);
231
+ var addrnode = root.derive(derivationPath);
232
+ return Secp256k1KeyIdentity.fromSecretKey(addrnode.privateKey);
233
+ };
234
+ /**
235
+ * Serialize this key to JSON-serializable object.
236
+ * @returns {JsonableSecp256k1Identity}
237
+ */
238
+ Secp256k1KeyIdentity.prototype.toJSON = function () {
239
+ return [(0, buffer_1.toHexString)(this._publicKey.toRaw()), (0, buffer_1.toHexString)(this._privateKey)];
240
+ };
241
+ /**
242
+ * Return a copy of the key pair.
243
+ * @returns {KeyPair}
244
+ */
245
+ Secp256k1KeyIdentity.prototype.getKeyPair = function () {
246
+ return {
247
+ secretKey: this._privateKey,
248
+ publicKey: this._publicKey
249
+ };
250
+ };
251
+ /**
252
+ * Return the public key.
253
+ * @returns {Secp256k1PublicKey}
254
+ */
255
+ Secp256k1KeyIdentity.prototype.getPublicKey = function () {
256
+ return this._publicKey;
257
+ };
258
+ /**
259
+ * Signs a blob of data, with this identity's private key.
260
+ * @param {ArrayBuffer} challenge - challenge to sign with this identity's secretKey, producing a signature
261
+ * @returns {Promise<Signature>} signature
262
+ */
263
+ Secp256k1KeyIdentity.prototype.sign = function (challenge) {
264
+ return __awaiter(this, void 0, void 0, function () {
265
+ var hash, signature;
266
+ return __generator(this, function (_a) {
267
+ hash = js_sha256_1.sha256.create();
268
+ hash.update(challenge);
269
+ signature = secp256k1_1.default.ecdsaSign(new Uint8Array(hash.digest()), new Uint8Array(this._privateKey)).signature.buffer;
270
+ return [2 /*return*/, signature];
271
+ });
272
+ });
273
+ };
274
+ return Secp256k1KeyIdentity;
275
+ }(auth_1.SignIdentity));
276
+ exports.Secp256k1KeyIdentity = Secp256k1KeyIdentity;
277
+ exports.default = Secp256k1KeyIdentity;
278
+ //# sourceMappingURL=secp256k1.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secp256k1.js","sourceRoot":"","sources":["../../../src/v1/utils/secp256k1.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAAyC;AACzC,uCAAuC;AACvC,+FAAkF;AAClF,+BAA0C;AAC1C,uCAAkC;AAClC,wDAAiC;AAEjC,+BAAyF;AACzF,mCAAqD;AACrD,6BAAyD;AACzD,kDAA2B;AAM3B;IA8BE,kFAAkF;IAClF,4BAAoB,GAAgB;QAClC,GAAG,CAAC,UAAU,CAAA;QACd,IAAI,CAAC,MAAM,GAAG,GAAG,CAAA;QACjB,IAAI,CAAC,MAAM,GAAG,kBAAkB,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;IACjD,CAAC;IAlCD;;;;OAIG;IACW,uBAAI,GAAlB,UAAmB,GAAc;QAC/B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAA;IAClC,CAAC;IAEa,0BAAO,GAArB,UAAsB,MAAmB;QACvC,OAAO,IAAI,kBAAkB,CAAC,MAAM,CAA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ACI,qCAAM,GAAb;QACE,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,yCAAU,GAAjB;QACE,OAAO;YACL,SAAS,EAAE,IAAI,CAAC,WAAW;YAC3B,SAAS,EAAE,IAAI,CAAC,UAAU;SAC3B,CAAA;IACH,CAAC;IAED;;;OAGG;IACI,2CAAY,GAAnB;QACE,OAAO,IAAI,CAAC,UAAU,CAAA;IACxB,CAAC;IAED;;;;OAIG;IACU,mCAAI,GAAjB,UAAkB,SAAsB;;;;gBAChC,IAAI,GAAG,kBAAM,CAAC,MAAM,EAAE,CAAA;gBAC5B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;gBAChB,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;gBACvH,sBAAO,SAAsB,EAAA;;;KAC9B;IACH,2BAAC;AAAD,CAAC,AA9ID,CAA0C,mBAAY,GA8IrD;AA9IY,oDAAoB;AAgJjC,kBAAe,oBAAoB,CAAA"}
@@ -0,0 +1,3 @@
1
+ /// <reference types="node" />
2
+ export declare function encodeTx(transaction: any): string;
3
+ export declare function decodeTx(transaction: string): Buffer;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.decodeTx = exports.encodeTx = void 0;
30
+ var coinlib_core_1 = require("@airgap/coinlib-core");
31
+ var bs58check = __importStar(require("@airgap/coinlib-core/dependencies/src/bs58check-2.1.2/index"));
32
+ var errors_1 = require("@airgap/coinlib-core/errors");
33
+ var base64Check_1 = __importDefault(require("@airgap/coinlib-core/utils/base64Check"));
34
+ var TRANSACTION_PREFIX = 'tx_';
35
+ function encodeTx(transaction) {
36
+ return "".concat(TRANSACTION_PREFIX).concat(base64Check_1.default.encode(transaction));
37
+ }
38
+ exports.encodeTx = encodeTx;
39
+ function decodeTx(transaction) {
40
+ var encoded = transaction.replace(TRANSACTION_PREFIX, '');
41
+ try {
42
+ return base64Check_1.default.decode(encoded);
43
+ }
44
+ catch (error) {
45
+ //
46
+ }
47
+ try {
48
+ return bs58check.decode(encoded);
49
+ }
50
+ catch (error) {
51
+ //
52
+ }
53
+ throw new errors_1.InvalidValueError(coinlib_core_1.Domain.AETERNITY, 'invalid TX-encoding');
54
+ }
55
+ exports.decodeTx = decodeTx;
56
+ //# sourceMappingURL=transaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../../src/v1/utils/transaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAA6C;AAC7C,qGAAwF;AACxF,sDAA+D;AAC/D,uFAA8D;AAE9D,IAAM,kBAAkB,GAAW,KAAK,CAAA;AAExC,SAAgB,QAAQ,CAAC,WAAgB;IACvC,OAAO,UAAG,kBAAkB,SAAG,qBAAS,CAAC,MAAM,CAAC,WAAW,CAAC,CAAE,CAAA;AAChE,CAAC;AAFD,4BAEC;AAED,SAAgB,QAAQ,CAAC,WAAmB;IAC1C,IAAM,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"}