@airgap/icp 0.13.11-beta.1 → 0.13.11-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/index.d.ts +1 -0
- package/index.js +18 -0
- package/index.js.map +1 -0
- package/package.json +4 -8
- 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 +13 -0
- package/v1/index.js +11 -0
- package/v1/index.js.map +1 -0
- package/v1/module/ICPModule.d.ts +15 -0
- package/v1/module/ICPModule.js +107 -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 +26 -0
- package/v1/protocol/ICPImplementation.js +344 -0
- package/v1/protocol/ICPImplementation.js.map +1 -0
- package/v1/protocol/ICPProtocol.d.ts +42 -0
- package/v1/protocol/ICPProtocol.js +416 -0
- package/v1/protocol/ICPProtocol.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 +174 -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/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/ledger.d.ts +143 -0
- package/v1/types/ledger.js +146 -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 +8 -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 +8 -0
- package/v1/utils/convert.js +80 -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/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,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.ICPV3SerializerCompanion = void 0;
|
|
40
|
+
var coinlib_core_1 = require("@airgap/coinlib-core");
|
|
41
|
+
var validate_1 = require("@airgap/coinlib-core/dependencies/src/validate.js-0.13.1/validate");
|
|
42
|
+
var errors_1 = require("@airgap/coinlib-core/errors");
|
|
43
|
+
var serializer_1 = require("@airgap/serializer");
|
|
44
|
+
var transaction_converter_1 = require("./schemas/converter/transaction-converter");
|
|
45
|
+
var transaction_validator_1 = require("./validators/transaction-validator");
|
|
46
|
+
var validators_1 = require("./validators/validators");
|
|
47
|
+
var icpTransactionSignRequest = require('./schemas/generated/transaction-sign-request-icp.json');
|
|
48
|
+
var icpTransactionSignResponse = require('./schemas/generated/transaction-sign-response-icp.json');
|
|
49
|
+
var ICPV3SerializerCompanion = /** @class */ (function () {
|
|
50
|
+
function ICPV3SerializerCompanion() {
|
|
51
|
+
this.schemas = [
|
|
52
|
+
{
|
|
53
|
+
type: serializer_1.IACMessageType.TransactionSignRequest,
|
|
54
|
+
schema: { schema: icpTransactionSignRequest },
|
|
55
|
+
protocolIdentifier: coinlib_core_1.MainProtocolSymbols.ICP
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
type: serializer_1.IACMessageType.TransactionSignResponse,
|
|
59
|
+
schema: { schema: icpTransactionSignResponse },
|
|
60
|
+
protocolIdentifier: coinlib_core_1.MainProtocolSymbols.ICP
|
|
61
|
+
}
|
|
62
|
+
];
|
|
63
|
+
this.icpTransactionValidator = new transaction_validator_1.ICPTransactionValidator();
|
|
64
|
+
Object.keys(validators_1.icpValidators).forEach(function (key) {
|
|
65
|
+
validate_1.validators[key] = validators_1.icpValidators[key];
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
ICPV3SerializerCompanion.prototype.toTransactionSignRequest = function (identifier, unsignedTransaction, publicKey, callbackUrl) {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
70
|
+
return __generator(this, function (_a) {
|
|
71
|
+
console.log('toTransactionSignRequest : identifier', identifier);
|
|
72
|
+
switch (identifier) {
|
|
73
|
+
case coinlib_core_1.MainProtocolSymbols.ICP:
|
|
74
|
+
return [2 /*return*/, (0, transaction_converter_1.icpUnsignedTransactionToRequest)(unsignedTransaction, publicKey, callbackUrl)];
|
|
75
|
+
default:
|
|
76
|
+
throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ICP, "Protocol ".concat(identifier, " not supported"));
|
|
77
|
+
}
|
|
78
|
+
return [2 /*return*/];
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
ICPV3SerializerCompanion.prototype.fromTransactionSignRequest = function (identifier, transactionSignRequest) {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
84
|
+
return __generator(this, function (_a) {
|
|
85
|
+
switch (identifier) {
|
|
86
|
+
case coinlib_core_1.MainProtocolSymbols.ICP:
|
|
87
|
+
return [2 /*return*/, (0, transaction_converter_1.icpTransactionSignRequestToUnsigned)(transactionSignRequest)];
|
|
88
|
+
default:
|
|
89
|
+
throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ICP, "Protocol ".concat(identifier, " not supported"));
|
|
90
|
+
}
|
|
91
|
+
return [2 /*return*/];
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
ICPV3SerializerCompanion.prototype.validateTransactionSignRequest = function (identifier, transactionSignRequest) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
97
|
+
var _a, _b;
|
|
98
|
+
return __generator(this, function (_c) {
|
|
99
|
+
switch (_c.label) {
|
|
100
|
+
case 0:
|
|
101
|
+
_a = identifier;
|
|
102
|
+
switch (_a) {
|
|
103
|
+
case coinlib_core_1.MainProtocolSymbols.ICP: return [3 /*break*/, 1];
|
|
104
|
+
}
|
|
105
|
+
return [3 /*break*/, 4];
|
|
106
|
+
case 1:
|
|
107
|
+
_c.trys.push([1, 3, , 4]);
|
|
108
|
+
return [4 /*yield*/, this.icpTransactionValidator.validateUnsignedTransaction(transactionSignRequest)];
|
|
109
|
+
case 2:
|
|
110
|
+
_c.sent();
|
|
111
|
+
return [2 /*return*/, true];
|
|
112
|
+
case 3:
|
|
113
|
+
_b = _c.sent();
|
|
114
|
+
return [2 /*return*/, false];
|
|
115
|
+
case 4: throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ICP, "Protocol ".concat(identifier, " not supported"));
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
ICPV3SerializerCompanion.prototype.toTransactionSignResponse = function (identifier, signedTransaction, accountIdentifier) {
|
|
121
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
122
|
+
return __generator(this, function (_a) {
|
|
123
|
+
switch (identifier) {
|
|
124
|
+
case coinlib_core_1.MainProtocolSymbols.ICP:
|
|
125
|
+
return [2 /*return*/, (0, transaction_converter_1.icpSignedTransactionToResponse)(signedTransaction, accountIdentifier)];
|
|
126
|
+
default:
|
|
127
|
+
throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ICP, "Protocol ".concat(identifier, " not supported"));
|
|
128
|
+
}
|
|
129
|
+
return [2 /*return*/];
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
ICPV3SerializerCompanion.prototype.fromTransactionSignResponse = function (identifier, transactionSignResponse) {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
135
|
+
return __generator(this, function (_a) {
|
|
136
|
+
switch (identifier) {
|
|
137
|
+
case coinlib_core_1.MainProtocolSymbols.ICP:
|
|
138
|
+
return [2 /*return*/, (0, transaction_converter_1.icpTransactionSignResponseToSigned)(transactionSignResponse)];
|
|
139
|
+
default:
|
|
140
|
+
throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ICP, "Protocol ".concat(identifier, " not supported"));
|
|
141
|
+
}
|
|
142
|
+
return [2 /*return*/];
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
ICPV3SerializerCompanion.prototype.validateTransactionSignResponse = function (identifier, transactionSignResponse) {
|
|
147
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
148
|
+
var _a, _b;
|
|
149
|
+
return __generator(this, function (_c) {
|
|
150
|
+
switch (_c.label) {
|
|
151
|
+
case 0:
|
|
152
|
+
_a = identifier;
|
|
153
|
+
switch (_a) {
|
|
154
|
+
case coinlib_core_1.MainProtocolSymbols.ICP: return [3 /*break*/, 1];
|
|
155
|
+
}
|
|
156
|
+
return [3 /*break*/, 4];
|
|
157
|
+
case 1:
|
|
158
|
+
_c.trys.push([1, 3, , 4]);
|
|
159
|
+
return [4 /*yield*/, this.icpTransactionValidator.validateSignedTransaction(transactionSignResponse)];
|
|
160
|
+
case 2:
|
|
161
|
+
_c.sent();
|
|
162
|
+
return [2 /*return*/, true];
|
|
163
|
+
case 3:
|
|
164
|
+
_b = _c.sent();
|
|
165
|
+
return [2 /*return*/, false];
|
|
166
|
+
case 4: throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ICP, "Protocol ".concat(identifier, " not supported"));
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
return ICPV3SerializerCompanion;
|
|
172
|
+
}());
|
|
173
|
+
exports.ICPV3SerializerCompanion = ICPV3SerializerCompanion;
|
|
174
|
+
//# sourceMappingURL=serializer-companion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializer-companion.js","sourceRoot":"","sources":["../../../../src/v1/serializer/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AAC,qBAAM,CAAC,GAAG,EAAE,mBAAY,UAAU,mBAAgB,CAAC,CAAA;iBACjF;;;;KACF;IAEY,kEAA+B,GAA5C,UAA6C,UAAkB,EAAE,uBAAgD;;;;;;wBACvG,KAAA,UAAU,CAAA;;iCACX,kCAAmB,CAAC,GAAG,CAAC,CAAxB,wBAAuB;;;;;wBAExB,qBAAM,IAAI,CAAC,uBAAuB,CAAC,yBAAyB,CAAC,uBAAuB,CAAC,EAAA;;wBAArF,SAAqF,CAAA;wBAErF,sBAAO,IAAI,EAAA;;;wBAEX,sBAAO,KAAK,EAAA;4BAGd,MAAM,IAAI,yBAAgB,CAAC,qBAAM,CAAC,GAAG,EAAE,mBAAY,UAAU,mBAAgB,CAAC,CAAA;;;;KAEnF;IACH,+BAAC;AAAD,CAAC,AAvGD,IAuGC;AAvGY,4DAAwB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TransactionValidator, TransactionValidatorFactory } from '@airgap/serializer';
|
|
2
|
+
import { ICPTransactionSignRequest } from '../schemas/definitions/transaction-sign-request-icp';
|
|
3
|
+
import { ICPTransactionSignResponse } from '../schemas/definitions/transaction-sign-response-icp';
|
|
4
|
+
export declare class ICPTransactionValidator implements TransactionValidator {
|
|
5
|
+
validateUnsignedTransaction(request: ICPTransactionSignRequest): Promise<any>;
|
|
6
|
+
validateSignedTransaction(response: ICPTransactionSignResponse): Promise<any>;
|
|
7
|
+
}
|
|
8
|
+
export declare class ICPTransactionValidatorFactory implements TransactionValidatorFactory<ICPTransactionValidator> {
|
|
9
|
+
create(): ICPTransactionValidator;
|
|
10
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.ICPTransactionValidatorFactory = exports.ICPTransactionValidator = void 0;
|
|
40
|
+
// tslint:disable: max-classes-per-file
|
|
41
|
+
var validate_1 = require("@airgap/coinlib-core/dependencies/src/validate.js-0.13.1/validate");
|
|
42
|
+
var serializer_1 = require("@airgap/serializer");
|
|
43
|
+
var unsignedTransactionConstraints = {
|
|
44
|
+
transaction: {
|
|
45
|
+
presence: { allowEmpty: false },
|
|
46
|
+
type: 'String',
|
|
47
|
+
isValidICPTx: true
|
|
48
|
+
},
|
|
49
|
+
networkId: {
|
|
50
|
+
presence: { allowEmpty: false },
|
|
51
|
+
type: 'String',
|
|
52
|
+
isMainNet: true
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var signedTransactionConstraints = {
|
|
56
|
+
transaction: {
|
|
57
|
+
presence: { allowEmpty: false },
|
|
58
|
+
type: 'String',
|
|
59
|
+
isValidICPTx: true
|
|
60
|
+
},
|
|
61
|
+
accountIdentifier: {
|
|
62
|
+
presence: { allowEmpty: false },
|
|
63
|
+
type: 'String'
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var success = function () { return undefined; };
|
|
67
|
+
var error = function (errors) { return errors; };
|
|
68
|
+
var ICPTransactionValidator = /** @class */ (function () {
|
|
69
|
+
function ICPTransactionValidator() {
|
|
70
|
+
}
|
|
71
|
+
ICPTransactionValidator.prototype.validateUnsignedTransaction = function (request) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
73
|
+
var transaction;
|
|
74
|
+
return __generator(this, function (_a) {
|
|
75
|
+
transaction = request.transaction;
|
|
76
|
+
(0, serializer_1.validateSyncScheme)({});
|
|
77
|
+
return [2 /*return*/, (0, validate_1.async)(transaction, unsignedTransactionConstraints).then(success, error)];
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
ICPTransactionValidator.prototype.validateSignedTransaction = function (response) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
83
|
+
return __generator(this, function (_a) {
|
|
84
|
+
return [2 /*return*/, (0, validate_1.async)(response, signedTransactionConstraints).then(success, error)];
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
return ICPTransactionValidator;
|
|
89
|
+
}());
|
|
90
|
+
exports.ICPTransactionValidator = ICPTransactionValidator;
|
|
91
|
+
var ICPTransactionValidatorFactory = /** @class */ (function () {
|
|
92
|
+
function ICPTransactionValidatorFactory() {
|
|
93
|
+
}
|
|
94
|
+
ICPTransactionValidatorFactory.prototype.create = function () {
|
|
95
|
+
return new ICPTransactionValidator();
|
|
96
|
+
};
|
|
97
|
+
return ICPTransactionValidatorFactory;
|
|
98
|
+
}());
|
|
99
|
+
exports.ICPTransactionValidatorFactory = ICPTransactionValidatorFactory;
|
|
100
|
+
//# sourceMappingURL=transaction-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction-validator.js","sourceRoot":"","sources":["../../../../../src/v1/serializer/v3/validators/transaction-validator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAuC;AACvC,8FAAyF;AACzF,iDAA0G;AAK1G,IAAM,8BAA8B,GAAG;IACrC,WAAW,EAAE;QACX,QAAQ,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE;QAC/B,IAAI,EAAE,QAAQ;QACd,YAAY,EAAE,IAAI;KACnB;IACD,SAAS,EAAE;QACT,QAAQ,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE;QAC/B,IAAI,EAAE,QAAQ;QACd,SAAS,EAAE,IAAI;KAChB;CACF,CAAA;AACD,IAAM,4BAA4B,GAAG;IACnC,WAAW,EAAE;QACX,QAAQ,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE;QAC/B,IAAI,EAAE,QAAQ;QACd,YAAY,EAAE,IAAI;KACnB;IACD,iBAAiB,EAAE;QACjB,QAAQ,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE;QAC/B,IAAI,EAAE,QAAQ;KACf;CACF,CAAA;AACD,IAAM,OAAO,GAAG,cAAM,OAAA,SAAS,EAAT,CAAS,CAAA;AAC/B,IAAM,KAAK,GAAG,UAAC,MAAM,IAAK,OAAA,MAAM,EAAN,CAAM,CAAA;AAEhC;IAAA;IAUA,CAAC;IATc,6DAA2B,GAAxC,UAAyC,OAAkC;;;;gBACnE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAA;gBACvC,IAAA,+BAAkB,EAAC,EAAE,CAAC,CAAA;gBAEtB,sBAAO,IAAA,gBAAK,EAAC,WAAW,EAAE,8BAA8B,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,EAAA;;;KAC/E;IACY,2DAAyB,GAAtC,UAAuC,QAAoC;;;gBACzE,sBAAO,IAAA,gBAAK,EAAC,QAAQ,EAAE,4BAA4B,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,EAAA;;;KAC1E;IACH,8BAAC;AAAD,CAAC,AAVD,IAUC;AAVY,0DAAuB;AAYpC;IAAA;IAIA,CAAC;IAHQ,+CAAM,GAAb;QACE,OAAO,IAAI,uBAAuB,EAAE,CAAA;IACtC,CAAC;IACH,qCAAC;AAAD,CAAC,AAJD,IAIC;AAJY,wEAA8B"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const icpValidators: {
|
|
2
|
+
isMainNet: (value: unknown) => "is not on mainnet" | null;
|
|
3
|
+
isValidICPTx: (transaction: unknown) => "invalid tx format" | "isn't base64 encoded" | "isn't a string" | null;
|
|
4
|
+
isValidICPAccount: (accountIdentifier: string) => Promise<void>;
|
|
5
|
+
};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.icpValidators = void 0;
|
|
43
|
+
var base64Check_1 = __importDefault(require("@airgap/coinlib-core/utils/base64Check"));
|
|
44
|
+
var module_kit_1 = require("@airgap/module-kit");
|
|
45
|
+
var ICPProtocol_1 = require("../../../protocol/ICPProtocol");
|
|
46
|
+
exports.icpValidators = {
|
|
47
|
+
isMainNet: function (value) {
|
|
48
|
+
// allow empty values by default (needs to be checked by "presence" check)
|
|
49
|
+
if (value === null || typeof value === 'undefined') {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
if (value !== 'ae_mainnet') {
|
|
53
|
+
return 'is not on mainnet';
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
},
|
|
57
|
+
isValidICPTx: function (transaction) {
|
|
58
|
+
// allow empty values by default (needs to be checked by "presence" check)
|
|
59
|
+
if (transaction === null || typeof transaction === 'undefined') {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
if (typeof transaction === 'string' && !transaction.startsWith('tx_')) {
|
|
63
|
+
return 'invalid tx format';
|
|
64
|
+
}
|
|
65
|
+
else if (typeof transaction === 'string') {
|
|
66
|
+
try {
|
|
67
|
+
base64Check_1.default.decode(transaction.replace('tx_', ''));
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
return "isn't base64 encoded";
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
return "isn't a string";
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
isValidICPAccount: function (accountIdentifier) {
|
|
79
|
+
return new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
|
80
|
+
var protocol, error_1;
|
|
81
|
+
return __generator(this, function (_a) {
|
|
82
|
+
switch (_a.label) {
|
|
83
|
+
case 0:
|
|
84
|
+
if (accountIdentifier === null || typeof accountIdentifier === 'undefined') {
|
|
85
|
+
reject();
|
|
86
|
+
}
|
|
87
|
+
_a.label = 1;
|
|
88
|
+
case 1:
|
|
89
|
+
_a.trys.push([1, 3, , 4]);
|
|
90
|
+
protocol = (0, ICPProtocol_1.createICPProtocol)();
|
|
91
|
+
return [4 /*yield*/, protocol.getTransactionsForPublicKey((0, module_kit_1.newPublicKey)(accountIdentifier, 'hex'), 1)];
|
|
92
|
+
case 2:
|
|
93
|
+
_a.sent();
|
|
94
|
+
resolve();
|
|
95
|
+
return [3 /*break*/, 4];
|
|
96
|
+
case 3:
|
|
97
|
+
error_1 = _a.sent();
|
|
98
|
+
reject('not a valid ICP account');
|
|
99
|
+
return [3 /*break*/, 4];
|
|
100
|
+
case 4: return [2 /*return*/];
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}); });
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
//# sourceMappingURL=validators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../../../../src/v1/serializer/v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