@initia/initia.js 0.0.28 → 0.0.29
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/dist/bundle.js +1 -1
- package/dist/bundle.js.map +1 -1
- package/dist/bundle.node.js +1 -1
- package/dist/bundle.node.js.map +1 -1
- package/dist/key/CLIKey.d.ts +3 -3
- package/dist/key/CLIKey.js +68 -18
- package/dist/key/CLIKey.js.map +1 -1
- package/dist/key/Key.d.ts +4 -4
- package/dist/key/Key.js +102 -32
- package/dist/key/Key.js.map +1 -1
- package/dist/key/RawKey.d.ts +1 -1
- package/dist/key/RawKey.js +43 -2
- package/dist/key/RawKey.js.map +1 -1
- package/package.json +1 -1
package/dist/key/CLIKey.d.ts
CHANGED
|
@@ -37,8 +37,8 @@ export declare class CLIKey extends Key {
|
|
|
37
37
|
* Initia validator address. `initvaloper-` prefixed.
|
|
38
38
|
*/
|
|
39
39
|
get valAddress(): ValAddress;
|
|
40
|
-
sign(): Buffer
|
|
41
|
-
createSignature(tx: SignDoc): SignatureV2
|
|
42
|
-
createSignatureAmino(tx: SignDoc): SignatureV2
|
|
40
|
+
sign(): Promise<Buffer>;
|
|
41
|
+
createSignature(tx: SignDoc): Promise<SignatureV2>;
|
|
42
|
+
createSignatureAmino(tx: SignDoc): Promise<SignatureV2>;
|
|
43
43
|
}
|
|
44
44
|
export {};
|
package/dist/key/CLIKey.js
CHANGED
|
@@ -14,6 +14,42 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
14
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
15
|
};
|
|
16
16
|
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (_) try {
|
|
33
|
+
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;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
17
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
54
|
exports.CLIKey = void 0;
|
|
19
55
|
var Key_1 = require("./Key");
|
|
@@ -85,28 +121,42 @@ var CLIKey = /** @class */ (function (_super) {
|
|
|
85
121
|
configurable: true
|
|
86
122
|
});
|
|
87
123
|
CLIKey.prototype.sign = function () {
|
|
88
|
-
|
|
124
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
125
|
+
return __generator(this, function (_a) {
|
|
126
|
+
throw new Error('CLIKey does not use sign() -- use createSignature() directly.');
|
|
127
|
+
});
|
|
128
|
+
});
|
|
89
129
|
};
|
|
90
130
|
CLIKey.prototype.createSignature = function (tx) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
131
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
132
|
+
var tmpobj, result;
|
|
133
|
+
return __generator(this, function (_a) {
|
|
134
|
+
if (this.params.multisig) {
|
|
135
|
+
throw new Error('multisig is not supported in direct sign mode');
|
|
136
|
+
}
|
|
137
|
+
tmpobj = (0, tmp_1.fileSync)({ postfix: '.json' });
|
|
138
|
+
(0, fs_1.writeFileSync)(tmpobj.fd, JSON.stringify(tx.toUnSignedTx().toData()));
|
|
139
|
+
result = (0, child_process_1.execSync)(this.generateCommand("tx sign ".concat(tmpobj.name, " --yes --signature-only --from ").concat(this.params.keyName, " --offline ") +
|
|
140
|
+
"--chain-id ".concat(tx.chain_id, " --account-number ").concat(tx.account_number, " --sequence ").concat(tx.sequence, " ") +
|
|
141
|
+
"".concat(this.params.multisig ? "--multisig ".concat(this.params.multisig) : '', " --sign-mode direct"))).toString();
|
|
142
|
+
tmpobj.removeCallback();
|
|
143
|
+
return [2 /*return*/, SignatureV2_1.SignatureV2.fromData(JSON.parse(result)['signatures'][0])];
|
|
144
|
+
});
|
|
145
|
+
});
|
|
101
146
|
};
|
|
102
147
|
CLIKey.prototype.createSignatureAmino = function (tx) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
148
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
149
|
+
var tmpobj, result;
|
|
150
|
+
return __generator(this, function (_a) {
|
|
151
|
+
tmpobj = (0, tmp_1.fileSync)({ postfix: '.json' });
|
|
152
|
+
(0, fs_1.writeFileSync)(tmpobj.fd, JSON.stringify(tx.toUnSignedTx().toData()));
|
|
153
|
+
result = (0, child_process_1.execSync)(this.generateCommand("tx sign ".concat(tmpobj.name, " --yes --signature-only --from ").concat(this.params.keyName, " --offline ") +
|
|
154
|
+
"--chain-id ".concat(tx.chain_id, " --account-number ").concat(tx.account_number, " --sequence ").concat(tx.sequence, " ") +
|
|
155
|
+
"".concat(this.params.multisig ? "--multisig ".concat(this.params.multisig) : '', " --sign-mode amino-json"))).toString();
|
|
156
|
+
tmpobj.removeCallback();
|
|
157
|
+
return [2 /*return*/, SignatureV2_1.SignatureV2.fromData(JSON.parse(result)['signatures'][0])];
|
|
158
|
+
});
|
|
159
|
+
});
|
|
110
160
|
};
|
|
111
161
|
return CLIKey;
|
|
112
162
|
}(Key_1.Key));
|
package/dist/key/CLIKey.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CLIKey.js","sourceRoot":"","sources":["../../src/key/CLIKey.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CLIKey.js","sourceRoot":"","sources":["../../src/key/CLIKey.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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E,CAAC;gBACxB,sBAAO,yBAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC;;;KAClE;IAEY,qCAAoB,GAAjC,UAAkC,EAAW;;;;gBACrC,MAAM,GAAG,IAAA,cAAQ,EAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;gBAC9C,IAAA,kBAAa,EAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,YAAY,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;gBAE/D,MAAM,GAAG,IAAA,wBAAQ,EACrB,IAAI,CAAC,eAAe,CAClB,kBAAW,MAAM,CAAC,IAAI,4CAAkC,IAAI,CAAC,MAAM,CAAC,OAAO,gBAAa;oBACtF,qBAAc,EAAE,CAAC,QAAQ,+BAAqB,EAAE,CAAC,cAAc,yBAAe,EAAE,CAAC,QAAQ,MAAG;oBAC5F,UACE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,qBAAc,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAE,CAAC,CAAC,CAAC,EAAE,4BACzC,CAC5B,CACF,CAAC,QAAQ,EAAE,CAAC;gBAEb,MAAM,CAAC,cAAc,EAAE,CAAC;gBACxB,sBAAO,yBAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC;;;KAClE;IACH,aAAC;AAAD,CAAC,AAnGD,CAA4B,SAAG,GAmG9B;AAnGY,wBAAM"}
|
package/dist/key/Key.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare abstract class Key {
|
|
|
17
17
|
*
|
|
18
18
|
* @param payload the data to be signed
|
|
19
19
|
*/
|
|
20
|
-
abstract sign(payload: Buffer): Buffer
|
|
20
|
+
abstract sign(payload: Buffer): Promise<Buffer>;
|
|
21
21
|
/**
|
|
22
22
|
* Initia account address. `init-` prefixed.
|
|
23
23
|
*/
|
|
@@ -39,18 +39,18 @@ export declare abstract class Key {
|
|
|
39
39
|
*
|
|
40
40
|
* @param tx sign-message of the transaction to sign
|
|
41
41
|
*/
|
|
42
|
-
createSignatureAmino(tx: SignDoc): SignatureV2
|
|
42
|
+
createSignatureAmino(tx: SignDoc): Promise<SignatureV2>;
|
|
43
43
|
/**
|
|
44
44
|
* Signs a [[SignDoc]] with the method supplied by the child class.
|
|
45
45
|
*
|
|
46
46
|
* @param tx sign-message of the transaction to sign
|
|
47
47
|
*/
|
|
48
|
-
createSignature(signDoc: SignDoc): SignatureV2
|
|
48
|
+
createSignature(signDoc: SignDoc): Promise<SignatureV2>;
|
|
49
49
|
/**
|
|
50
50
|
* Signs a [[Tx]] and adds the signature to a generated StdTx that is ready to be broadcasted.
|
|
51
51
|
* @param tx
|
|
52
52
|
*/
|
|
53
|
-
signTx(tx: Tx, options: SignOptions): Tx
|
|
53
|
+
signTx(tx: Tx, options: SignOptions): Promise<Tx>;
|
|
54
54
|
}
|
|
55
55
|
export interface SignOptions {
|
|
56
56
|
accountNumber: number;
|
package/dist/key/Key.js
CHANGED
|
@@ -1,4 +1,40 @@
|
|
|
1
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
|
+
};
|
|
2
38
|
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
39
|
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
40
|
if (ar || !(i in from)) {
|
|
@@ -64,10 +100,25 @@ var Key = /** @class */ (function () {
|
|
|
64
100
|
* @param tx sign-message of the transaction to sign
|
|
65
101
|
*/
|
|
66
102
|
Key.prototype.createSignatureAmino = function (tx) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
103
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
104
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
105
|
+
return __generator(this, function (_h) {
|
|
106
|
+
switch (_h.label) {
|
|
107
|
+
case 0:
|
|
108
|
+
if (!this.publicKey) {
|
|
109
|
+
throw new Error('Signature could not be created: Key instance missing publicKey');
|
|
110
|
+
}
|
|
111
|
+
_a = SignatureV2_1.SignatureV2.bind;
|
|
112
|
+
_b = [void 0, this.publicKey];
|
|
113
|
+
_d = (_c = SignatureV2_1.SignatureV2.Descriptor).bind;
|
|
114
|
+
_f = (_e = SignatureV2_1.SignatureV2.Descriptor.Single).bind;
|
|
115
|
+
_g = [void 0, signing_1.SignMode.SIGN_MODE_LEGACY_AMINO_JSON];
|
|
116
|
+
return [4 /*yield*/, this.sign(Buffer.from(tx.toAminoJSON()))];
|
|
117
|
+
case 1: return [2 /*return*/, new (_a.apply(SignatureV2_1.SignatureV2, _b.concat([new (_d.apply(_c, [void 0, new (_f.apply(_e, _g.concat([(_h.sent()).toString('base64')])))()]))(),
|
|
118
|
+
tx.sequence])))()];
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
});
|
|
71
122
|
};
|
|
72
123
|
/**
|
|
73
124
|
* Signs a [[SignDoc]] with the method supplied by the child class.
|
|
@@ -75,40 +126,59 @@ var Key = /** @class */ (function () {
|
|
|
75
126
|
* @param tx sign-message of the transaction to sign
|
|
76
127
|
*/
|
|
77
128
|
Key.prototype.createSignature = function (signDoc) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
129
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
130
|
+
var signerInfos, sigBytes;
|
|
131
|
+
return __generator(this, function (_a) {
|
|
132
|
+
switch (_a.label) {
|
|
133
|
+
case 0:
|
|
134
|
+
if (!this.publicKey) {
|
|
135
|
+
throw new Error('Signature could not be created: Key instance missing publicKey');
|
|
136
|
+
}
|
|
137
|
+
signerInfos = signDoc.auth_info.signer_infos;
|
|
138
|
+
signDoc.auth_info.signer_infos = [
|
|
139
|
+
new core_1.SignerInfo(this.publicKey, signDoc.sequence, new core_1.ModeInfo(new core_1.ModeInfo.Single(signing_1.SignMode.SIGN_MODE_DIRECT))),
|
|
140
|
+
];
|
|
141
|
+
return [4 /*yield*/, this.sign(Buffer.from(signDoc.toBytes()))];
|
|
142
|
+
case 1:
|
|
143
|
+
sigBytes = (_a.sent())
|
|
144
|
+
.toString('base64');
|
|
145
|
+
// restore signDoc to origin
|
|
146
|
+
signDoc.auth_info.signer_infos = signerInfos;
|
|
147
|
+
return [2 /*return*/, new SignatureV2_1.SignatureV2(this.publicKey, new SignatureV2_1.SignatureV2.Descriptor(new SignatureV2_1.SignatureV2.Descriptor.Single(signing_1.SignMode.SIGN_MODE_DIRECT, sigBytes)), signDoc.sequence)];
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
});
|
|
92
151
|
};
|
|
93
152
|
/**
|
|
94
153
|
* Signs a [[Tx]] and adds the signature to a generated StdTx that is ready to be broadcasted.
|
|
95
154
|
* @param tx
|
|
96
155
|
*/
|
|
97
156
|
Key.prototype.signTx = function (tx, options) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
157
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
158
|
+
var copyTx, sign_doc, signature, sigData;
|
|
159
|
+
var _a, _b;
|
|
160
|
+
return __generator(this, function (_c) {
|
|
161
|
+
switch (_c.label) {
|
|
162
|
+
case 0:
|
|
163
|
+
copyTx = new core_1.Tx(tx.body, new core_1.AuthInfo([], tx.auth_info.fee), []);
|
|
164
|
+
sign_doc = new core_1.SignDoc(options.chainId, options.accountNumber, options.sequence, copyTx.auth_info, copyTx.body);
|
|
165
|
+
if (!(options.signMode === signing_1.SignMode.SIGN_MODE_LEGACY_AMINO_JSON)) return [3 /*break*/, 2];
|
|
166
|
+
return [4 /*yield*/, this.createSignatureAmino(sign_doc)];
|
|
167
|
+
case 1:
|
|
168
|
+
signature = _c.sent();
|
|
169
|
+
return [3 /*break*/, 4];
|
|
170
|
+
case 2: return [4 /*yield*/, this.createSignature(sign_doc)];
|
|
171
|
+
case 3:
|
|
172
|
+
signature = _c.sent();
|
|
173
|
+
_c.label = 4;
|
|
174
|
+
case 4:
|
|
175
|
+
sigData = signature.data.single;
|
|
176
|
+
(_a = copyTx.signatures).push.apply(_a, __spreadArray(__spreadArray([], tx.signatures, false), [sigData.signature], false));
|
|
177
|
+
(_b = copyTx.auth_info.signer_infos).push.apply(_b, __spreadArray(__spreadArray([], tx.auth_info.signer_infos, false), [new core_1.SignerInfo(signature.public_key, signature.sequence, new core_1.ModeInfo(new core_1.ModeInfo.Single(sigData.mode)))], false));
|
|
178
|
+
return [2 /*return*/, copyTx];
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
});
|
|
112
182
|
};
|
|
113
183
|
return Key;
|
|
114
184
|
}());
|
package/dist/key/Key.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Key.js","sourceRoot":"","sources":["../../src/key/Key.ts"],"names":[],"mappings":"
|
|
1
|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C,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;wBACjE,QAAQ,GAAG,IAAI,cAAO,CAC1B,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,aAAa,EACrB,OAAO,CAAC,QAAQ,EAChB,MAAM,CAAC,SAAS,EAChB,MAAM,CAAC,IAAI,CACZ,CAAC;6BAGE,CAAA,OAAO,CAAC,QAAQ,KAAK,kBAAQ,CAAC,2BAA2B,CAAA,EAAzD,wBAAyD;wBAC/C,qBAAM,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAC,EAAA;;wBAArD,SAAS,GAAG,SAAyC,CAAC;;4BAE1C,qBAAM,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAA;;wBAAhD,SAAS,GAAG,SAAoC,CAAC;;;wBAG7C,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,MAAuC,CAAC;wBACvE,CAAA,KAAA,MAAM,CAAC,UAAU,CAAA,CAAC,IAAI,2CAAI,EAAE,CAAC,UAAU,WAAE,OAAO,CAAC,SAAS,WAAE;wBAC5D,CAAA,KAAA,MAAM,CAAC,SAAS,CAAC,YAAY,CAAA,CAAC,IAAI,2CAC7B,EAAE,CAAC,SAAS,CAAC,YAAY,WAC5B,IAAI,iBAAU,CACZ,SAAS,CAAC,UAAU,EACpB,SAAS,CAAC,QAAQ,EAClB,IAAI,eAAQ,CAAC,IAAI,eAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAChD,WACD;wBAEF,sBAAO,MAAM,EAAC;;;;KACf;IACH,UAAC;AAAD,CAAC,AA1ID,IA0IC;AA1IqB,kBAAG"}
|
package/dist/key/RawKey.d.ts
CHANGED
package/dist/key/RawKey.js
CHANGED
|
@@ -37,6 +37,42 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
37
37
|
__setModuleDefault(result, mod);
|
|
38
38
|
return result;
|
|
39
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
|
+
};
|
|
40
76
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
77
|
exports.RawKey = void 0;
|
|
42
78
|
var jscrypto_1 = require("jscrypto");
|
|
@@ -60,8 +96,13 @@ var RawKey = /** @class */ (function (_super) {
|
|
|
60
96
|
return secp256k1.ecdsaSign(Uint8Array.from(hash), Uint8Array.from(this.privateKey));
|
|
61
97
|
};
|
|
62
98
|
RawKey.prototype.sign = function (payload) {
|
|
63
|
-
|
|
64
|
-
|
|
99
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
100
|
+
var signature;
|
|
101
|
+
return __generator(this, function (_a) {
|
|
102
|
+
signature = this.ecdsaSign(payload).signature;
|
|
103
|
+
return [2 /*return*/, Buffer.from(signature)];
|
|
104
|
+
});
|
|
105
|
+
});
|
|
65
106
|
};
|
|
66
107
|
return RawKey;
|
|
67
108
|
}(Key_1.Key));
|
package/dist/key/RawKey.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RawKey.js","sourceRoot":"","sources":["../../src/key/RawKey.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RawKey.js","sourceRoot":"","sources":["../../src/key/RawKey.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAA+C;AAC/C,mDAAuC;AACvC,6BAA4B;AAC5B,+CAAoD;AAEpD;;GAEG;AACH;IAA4B,0BAAG;IAM7B,gBAAY,UAAkB;QAA9B,iBAOC;QANC,IAAM,SAAS,GAAG,SAAS,CAAC,eAAe,CACzC,IAAI,UAAU,CAAC,UAAU,CAAC,EAC1B,IAAI,CACL,CAAC;gBACF,kBAAM,IAAI,2BAAe,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;QACrE,KAAI,CAAC,UAAU,GAAG,UAAU,CAAC;;IAC/B,CAAC;IAEM,0BAAS,GAAhB,UAAiB,OAAe;QAC9B,IAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CACtB,iBAAM,CAAC,IAAI,CAAC,IAAI,sBAAW,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,EAAE,EAChD,KAAK,CACN,CAAC;QACF,OAAO,SAAS,CAAC,SAAS,CACxB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EACrB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CACjC,CAAC;IACJ,CAAC;IAEY,qBAAI,GAAjB,UAAkB,OAAe;;;;gBACvB,SAAS,GAAK,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAA5B,CAA6B;gBAC9C,sBAAO,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EAAC;;;KAC/B;IACH,aAAC;AAAD,CAAC,AA9BD,CAA4B,SAAG,GA8B9B;AA9BY,wBAAM"}
|