@dynamic-labs-wallet/ton 0.0.230
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.cjs.d.ts +1 -0
- package/index.cjs.js +644 -0
- package/index.esm.d.ts +1 -0
- package/index.esm.js +623 -0
- package/package.json +31 -0
- package/src/client/client.d.ts +42 -0
- package/src/client/client.d.ts.map +1 -0
- package/src/client/constants.d.ts +10 -0
- package/src/client/constants.d.ts.map +1 -0
- package/src/client/index.d.ts +2 -0
- package/src/client/index.d.ts.map +1 -0
- package/src/index.d.ts +3 -0
- package/src/index.d.ts.map +1 -0
- package/src/utils/deriveTonAddress/deriveTonAddress.d.ts +9 -0
- package/src/utils/deriveTonAddress/deriveTonAddress.d.ts.map +1 -0
- package/src/utils/deriveTonAddress/index.d.ts +2 -0
- package/src/utils/deriveTonAddress/index.d.ts.map +1 -0
- package/src/utils/index.d.ts +2 -0
- package/src/utils/index.d.ts.map +1 -0
package/index.cjs.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|
package/index.cjs.js
ADDED
|
@@ -0,0 +1,644 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var browser = require('@dynamic-labs-wallet/browser');
|
|
4
|
+
var ton = require('@ton/ton');
|
|
5
|
+
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
6
|
+
|
|
7
|
+
function _interopNamespaceDefault(e) {
|
|
8
|
+
var n = Object.create(null);
|
|
9
|
+
if (e) {
|
|
10
|
+
Object.keys(e).forEach(function (k) {
|
|
11
|
+
if (k !== 'default') {
|
|
12
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return e[k]; }
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
n.default = e;
|
|
21
|
+
return Object.freeze(n);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var sdkApiCore__namespace = /*#__PURE__*/_interopNamespaceDefault(sdkApiCore);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Derives a TON address from a public key
|
|
28
|
+
* TON addresses are derived from the wallet contract state init
|
|
29
|
+
*/ var deriveTonAddress = function(param) {
|
|
30
|
+
var publicKeyHex = param.publicKeyHex, _param_workchain = param.workchain, workchain = _param_workchain === void 0 ? 0 : _param_workchain;
|
|
31
|
+
var pubKeyBytes = Buffer.from(publicKeyHex, 'hex');
|
|
32
|
+
if (pubKeyBytes.length !== 32) {
|
|
33
|
+
throw new Error("Invalid public key length: ".concat(pubKeyBytes.length, ", expected 32"));
|
|
34
|
+
}
|
|
35
|
+
var walletContract = ton.WalletContractV5R1.create({
|
|
36
|
+
workchain: workchain,
|
|
37
|
+
publicKey: pubKeyBytes
|
|
38
|
+
});
|
|
39
|
+
return walletContract.address.toString({
|
|
40
|
+
urlSafe: true,
|
|
41
|
+
bounceable: false,
|
|
42
|
+
testOnly: false
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
var ERROR_KEYGEN_FAILED = 'Error with keygen';
|
|
47
|
+
var ERROR_CREATE_WALLET_ACCOUNT = 'Error creating ton wallet account';
|
|
48
|
+
var ERROR_EXPORT_PRIVATE_KEY = 'Error exporting private key';
|
|
49
|
+
var ERROR_SIGN_MESSAGE = 'Error signing message';
|
|
50
|
+
var ERROR_ACCOUNT_ADDRESS_REQUIRED = 'Account address is required';
|
|
51
|
+
var ERROR_SIGN_TRANSACTION = 'Error signing transaction';
|
|
52
|
+
|
|
53
|
+
function _assert_this_initialized(self) {
|
|
54
|
+
if (self === void 0) {
|
|
55
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
56
|
+
}
|
|
57
|
+
return self;
|
|
58
|
+
}
|
|
59
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
60
|
+
try {
|
|
61
|
+
var info = gen[key](arg);
|
|
62
|
+
var value = info.value;
|
|
63
|
+
} catch (error) {
|
|
64
|
+
reject(error);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (info.done) {
|
|
68
|
+
resolve(value);
|
|
69
|
+
} else {
|
|
70
|
+
Promise.resolve(value).then(_next, _throw);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function _async_to_generator(fn) {
|
|
74
|
+
return function() {
|
|
75
|
+
var self = this, args = arguments;
|
|
76
|
+
return new Promise(function(resolve, reject) {
|
|
77
|
+
var gen = fn.apply(self, args);
|
|
78
|
+
function _next(value) {
|
|
79
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
80
|
+
}
|
|
81
|
+
function _throw(err) {
|
|
82
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
83
|
+
}
|
|
84
|
+
_next(undefined);
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function _call_super(_this, derived, args) {
|
|
89
|
+
derived = _get_prototype_of(derived);
|
|
90
|
+
return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
|
|
91
|
+
}
|
|
92
|
+
function _class_call_check(instance, Constructor) {
|
|
93
|
+
if (!(instance instanceof Constructor)) {
|
|
94
|
+
throw new TypeError("Cannot call a class as a function");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function _defineProperties(target, props) {
|
|
98
|
+
for(var i = 0; i < props.length; i++){
|
|
99
|
+
var descriptor = props[i];
|
|
100
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
101
|
+
descriptor.configurable = true;
|
|
102
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
103
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
107
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
108
|
+
return Constructor;
|
|
109
|
+
}
|
|
110
|
+
function _define_property(obj, key, value) {
|
|
111
|
+
if (key in obj) {
|
|
112
|
+
Object.defineProperty(obj, key, {
|
|
113
|
+
value: value,
|
|
114
|
+
enumerable: true,
|
|
115
|
+
configurable: true,
|
|
116
|
+
writable: true
|
|
117
|
+
});
|
|
118
|
+
} else {
|
|
119
|
+
obj[key] = value;
|
|
120
|
+
}
|
|
121
|
+
return obj;
|
|
122
|
+
}
|
|
123
|
+
function _get_prototype_of(o) {
|
|
124
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
125
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
126
|
+
};
|
|
127
|
+
return _get_prototype_of(o);
|
|
128
|
+
}
|
|
129
|
+
function _inherits(subClass, superClass) {
|
|
130
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
131
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
132
|
+
}
|
|
133
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
134
|
+
constructor: {
|
|
135
|
+
value: subClass,
|
|
136
|
+
writable: true,
|
|
137
|
+
configurable: true
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
141
|
+
}
|
|
142
|
+
function _object_spread(target) {
|
|
143
|
+
for(var i = 1; i < arguments.length; i++){
|
|
144
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
145
|
+
var ownKeys = Object.keys(source);
|
|
146
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
147
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
148
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
149
|
+
}));
|
|
150
|
+
}
|
|
151
|
+
ownKeys.forEach(function(key) {
|
|
152
|
+
_define_property(target, key, source[key]);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return target;
|
|
156
|
+
}
|
|
157
|
+
function ownKeys(object, enumerableOnly) {
|
|
158
|
+
var keys = Object.keys(object);
|
|
159
|
+
if (Object.getOwnPropertySymbols) {
|
|
160
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
161
|
+
keys.push.apply(keys, symbols);
|
|
162
|
+
}
|
|
163
|
+
return keys;
|
|
164
|
+
}
|
|
165
|
+
function _object_spread_props(target, source) {
|
|
166
|
+
source = source != null ? source : {};
|
|
167
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
168
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
169
|
+
} else {
|
|
170
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
171
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
return target;
|
|
175
|
+
}
|
|
176
|
+
function _possible_constructor_return(self, call) {
|
|
177
|
+
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
178
|
+
return call;
|
|
179
|
+
}
|
|
180
|
+
return _assert_this_initialized(self);
|
|
181
|
+
}
|
|
182
|
+
function _set_prototype_of(o, p) {
|
|
183
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
184
|
+
o.__proto__ = p;
|
|
185
|
+
return o;
|
|
186
|
+
};
|
|
187
|
+
return _set_prototype_of(o, p);
|
|
188
|
+
}
|
|
189
|
+
function _type_of(obj) {
|
|
190
|
+
"@swc/helpers - typeof";
|
|
191
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
192
|
+
}
|
|
193
|
+
function _is_native_reflect_construct() {
|
|
194
|
+
try {
|
|
195
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
196
|
+
} catch (_) {}
|
|
197
|
+
return (_is_native_reflect_construct = function() {
|
|
198
|
+
return !!result;
|
|
199
|
+
})();
|
|
200
|
+
}
|
|
201
|
+
function _ts_generator(thisArg, body) {
|
|
202
|
+
var f, y, t, g, _ = {
|
|
203
|
+
label: 0,
|
|
204
|
+
sent: function() {
|
|
205
|
+
if (t[0] & 1) throw t[1];
|
|
206
|
+
return t[1];
|
|
207
|
+
},
|
|
208
|
+
trys: [],
|
|
209
|
+
ops: []
|
|
210
|
+
};
|
|
211
|
+
return g = {
|
|
212
|
+
next: verb(0),
|
|
213
|
+
"throw": verb(1),
|
|
214
|
+
"return": verb(2)
|
|
215
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
216
|
+
return this;
|
|
217
|
+
}), g;
|
|
218
|
+
function verb(n) {
|
|
219
|
+
return function(v) {
|
|
220
|
+
return step([
|
|
221
|
+
n,
|
|
222
|
+
v
|
|
223
|
+
]);
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
function step(op) {
|
|
227
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
228
|
+
while(_)try {
|
|
229
|
+
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;
|
|
230
|
+
if (y = 0, t) op = [
|
|
231
|
+
op[0] & 2,
|
|
232
|
+
t.value
|
|
233
|
+
];
|
|
234
|
+
switch(op[0]){
|
|
235
|
+
case 0:
|
|
236
|
+
case 1:
|
|
237
|
+
t = op;
|
|
238
|
+
break;
|
|
239
|
+
case 4:
|
|
240
|
+
_.label++;
|
|
241
|
+
return {
|
|
242
|
+
value: op[1],
|
|
243
|
+
done: false
|
|
244
|
+
};
|
|
245
|
+
case 5:
|
|
246
|
+
_.label++;
|
|
247
|
+
y = op[1];
|
|
248
|
+
op = [
|
|
249
|
+
0
|
|
250
|
+
];
|
|
251
|
+
continue;
|
|
252
|
+
case 7:
|
|
253
|
+
op = _.ops.pop();
|
|
254
|
+
_.trys.pop();
|
|
255
|
+
continue;
|
|
256
|
+
default:
|
|
257
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
258
|
+
_ = 0;
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
262
|
+
_.label = op[1];
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
266
|
+
_.label = t[1];
|
|
267
|
+
t = op;
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
if (t && _.label < t[2]) {
|
|
271
|
+
_.label = t[2];
|
|
272
|
+
_.ops.push(op);
|
|
273
|
+
break;
|
|
274
|
+
}
|
|
275
|
+
if (t[2]) _.ops.pop();
|
|
276
|
+
_.trys.pop();
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
op = body.call(thisArg, _);
|
|
280
|
+
} catch (e) {
|
|
281
|
+
op = [
|
|
282
|
+
6,
|
|
283
|
+
e
|
|
284
|
+
];
|
|
285
|
+
y = 0;
|
|
286
|
+
} finally{
|
|
287
|
+
f = t = 0;
|
|
288
|
+
}
|
|
289
|
+
if (op[0] & 5) throw op[1];
|
|
290
|
+
return {
|
|
291
|
+
value: op[0] ? op[1] : void 0,
|
|
292
|
+
done: true
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
var DynamicTonWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
297
|
+
_inherits(DynamicTonWalletClient, DynamicWalletClient);
|
|
298
|
+
function DynamicTonWalletClient(param) {
|
|
299
|
+
var environmentId = param.environmentId, authToken = param.authToken, baseApiUrl = param.baseApiUrl, baseMPCRelayApiUrl = param.baseMPCRelayApiUrl, storageKey = param.storageKey, debug = param.debug, featureFlags = param.featureFlags, _param_authMode = param.authMode, authMode = _param_authMode === void 0 ? browser.AuthMode.HEADER : _param_authMode, sdkVersion = param.sdkVersion, forwardMPCClient = param.forwardMPCClient;
|
|
300
|
+
_class_call_check(this, DynamicTonWalletClient);
|
|
301
|
+
var _this;
|
|
302
|
+
_this = _call_super(this, DynamicTonWalletClient, [
|
|
303
|
+
{
|
|
304
|
+
environmentId: environmentId,
|
|
305
|
+
authToken: authToken,
|
|
306
|
+
baseApiUrl: baseApiUrl,
|
|
307
|
+
baseMPCRelayApiUrl: baseMPCRelayApiUrl,
|
|
308
|
+
storageKey: storageKey,
|
|
309
|
+
debug: debug,
|
|
310
|
+
featureFlags: featureFlags,
|
|
311
|
+
authMode: authMode,
|
|
312
|
+
sdkVersion: sdkVersion,
|
|
313
|
+
forwardMPCClient: forwardMPCClient
|
|
314
|
+
}
|
|
315
|
+
]), _define_property(_this, "chainName", 'TON');
|
|
316
|
+
return _this;
|
|
317
|
+
}
|
|
318
|
+
_create_class(DynamicTonWalletClient, [
|
|
319
|
+
{
|
|
320
|
+
key: "createWalletAccount",
|
|
321
|
+
value: function createWalletAccount(param) {
|
|
322
|
+
var thresholdSignatureScheme = param.thresholdSignatureScheme, _param_password = param.password, password = _param_password === void 0 ? undefined : _param_password, onError = param.onError, signedSessionId = param.signedSessionId;
|
|
323
|
+
var _this = this;
|
|
324
|
+
return _async_to_generator(function() {
|
|
325
|
+
var ceremonyCeremonyCompleteResolver, ceremonyCompletePromise, _ref, publicKeyHex, clientKeyShares, accountAddress, pubKeyBytes, error;
|
|
326
|
+
return _ts_generator(this, function(_state) {
|
|
327
|
+
switch(_state.label){
|
|
328
|
+
case 0:
|
|
329
|
+
_state.trys.push([
|
|
330
|
+
0,
|
|
331
|
+
5,
|
|
332
|
+
,
|
|
333
|
+
6
|
|
334
|
+
]);
|
|
335
|
+
ceremonyCompletePromise = new Promise(function(resolve) {
|
|
336
|
+
ceremonyCeremonyCompleteResolver = resolve;
|
|
337
|
+
});
|
|
338
|
+
return [
|
|
339
|
+
4,
|
|
340
|
+
_this.keyGen({
|
|
341
|
+
chainName: _this.chainName,
|
|
342
|
+
thresholdSignatureScheme: thresholdSignatureScheme,
|
|
343
|
+
onError: onError,
|
|
344
|
+
onCeremonyComplete: function(accountAddress, walletId) {
|
|
345
|
+
// update wallet map
|
|
346
|
+
_this.walletMap[accountAddress] = _object_spread_props(_object_spread({}, _this.walletMap[accountAddress]), {
|
|
347
|
+
accountAddress: accountAddress,
|
|
348
|
+
walletId: walletId,
|
|
349
|
+
chainName: _this.chainName,
|
|
350
|
+
thresholdSignatureScheme: thresholdSignatureScheme,
|
|
351
|
+
clientKeySharesBackupInfo: browser.getClientKeyShareBackupInfo()
|
|
352
|
+
});
|
|
353
|
+
_this.logger.debug('walletMap updated for wallet', {
|
|
354
|
+
context: {
|
|
355
|
+
accountAddress: accountAddress,
|
|
356
|
+
walletId: walletId,
|
|
357
|
+
walletMap: _this.walletMap
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
ceremonyCeremonyCompleteResolver(undefined);
|
|
361
|
+
}
|
|
362
|
+
})
|
|
363
|
+
];
|
|
364
|
+
case 1:
|
|
365
|
+
_ref = _state.sent(), publicKeyHex = _ref.rawPublicKey, clientKeyShares = _ref.clientKeyShares;
|
|
366
|
+
// Wait for the ceremony to complete before proceeding
|
|
367
|
+
return [
|
|
368
|
+
4,
|
|
369
|
+
ceremonyCompletePromise
|
|
370
|
+
];
|
|
371
|
+
case 2:
|
|
372
|
+
_state.sent();
|
|
373
|
+
if (!publicKeyHex || !clientKeyShares) {
|
|
374
|
+
throw new Error(ERROR_KEYGEN_FAILED);
|
|
375
|
+
}
|
|
376
|
+
accountAddress = deriveTonAddress({
|
|
377
|
+
publicKeyHex: publicKeyHex,
|
|
378
|
+
workchain: 0
|
|
379
|
+
});
|
|
380
|
+
// Update client key shares in wallet map
|
|
381
|
+
return [
|
|
382
|
+
4,
|
|
383
|
+
_this.setClientKeySharesToLocalStorage({
|
|
384
|
+
accountAddress: accountAddress,
|
|
385
|
+
clientKeyShares: clientKeyShares,
|
|
386
|
+
overwriteOrMerge: 'overwrite'
|
|
387
|
+
})
|
|
388
|
+
];
|
|
389
|
+
case 3:
|
|
390
|
+
_state.sent();
|
|
391
|
+
return [
|
|
392
|
+
4,
|
|
393
|
+
_this.storeEncryptedBackupByWalletWithRetry({
|
|
394
|
+
accountAddress: accountAddress,
|
|
395
|
+
clientKeyShares: clientKeyShares,
|
|
396
|
+
password: password,
|
|
397
|
+
signedSessionId: signedSessionId
|
|
398
|
+
})
|
|
399
|
+
];
|
|
400
|
+
case 4:
|
|
401
|
+
_state.sent();
|
|
402
|
+
pubKeyBytes = Buffer.from(publicKeyHex, 'hex');
|
|
403
|
+
return [
|
|
404
|
+
2,
|
|
405
|
+
{
|
|
406
|
+
accountAddress: accountAddress,
|
|
407
|
+
publicKeyHex: publicKeyHex,
|
|
408
|
+
rawPublicKey: new Uint8Array(pubKeyBytes)
|
|
409
|
+
}
|
|
410
|
+
];
|
|
411
|
+
case 5:
|
|
412
|
+
error = _state.sent();
|
|
413
|
+
_this.logger.error(ERROR_CREATE_WALLET_ACCOUNT, error);
|
|
414
|
+
throw new Error(ERROR_CREATE_WALLET_ACCOUNT);
|
|
415
|
+
case 6:
|
|
416
|
+
return [
|
|
417
|
+
2
|
|
418
|
+
];
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
})();
|
|
422
|
+
}
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
key: "signMessage",
|
|
426
|
+
value: function signMessage(param) {
|
|
427
|
+
var message = param.message, accountAddress = param.accountAddress, _param_password = param.password, password = _param_password === void 0 ? undefined : _param_password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, context = param.context, onError = param.onError;
|
|
428
|
+
var _this = this;
|
|
429
|
+
return _async_to_generator(function() {
|
|
430
|
+
var resolvedContext, signatureEd25519, formattedSignature, error;
|
|
431
|
+
return _ts_generator(this, function(_state) {
|
|
432
|
+
switch(_state.label){
|
|
433
|
+
case 0:
|
|
434
|
+
if (!accountAddress) {
|
|
435
|
+
throw new Error(ERROR_ACCOUNT_ADDRESS_REQUIRED);
|
|
436
|
+
}
|
|
437
|
+
return [
|
|
438
|
+
4,
|
|
439
|
+
_this.verifyPassword({
|
|
440
|
+
accountAddress: accountAddress,
|
|
441
|
+
password: password,
|
|
442
|
+
walletOperation: browser.WalletOperation.SIGN_MESSAGE,
|
|
443
|
+
signedSessionId: signedSessionId
|
|
444
|
+
})
|
|
445
|
+
];
|
|
446
|
+
case 1:
|
|
447
|
+
_state.sent();
|
|
448
|
+
resolvedContext = _object_spread_props(_object_spread({}, context), {
|
|
449
|
+
tonMessage: message
|
|
450
|
+
});
|
|
451
|
+
_state.label = 2;
|
|
452
|
+
case 2:
|
|
453
|
+
_state.trys.push([
|
|
454
|
+
2,
|
|
455
|
+
4,
|
|
456
|
+
,
|
|
457
|
+
5
|
|
458
|
+
]);
|
|
459
|
+
return [
|
|
460
|
+
4,
|
|
461
|
+
_this.sign({
|
|
462
|
+
message: message,
|
|
463
|
+
accountAddress: accountAddress,
|
|
464
|
+
chainName: _this.chainName,
|
|
465
|
+
password: password,
|
|
466
|
+
signedSessionId: signedSessionId,
|
|
467
|
+
mfaToken: mfaToken,
|
|
468
|
+
context: resolvedContext,
|
|
469
|
+
onError: onError
|
|
470
|
+
})
|
|
471
|
+
];
|
|
472
|
+
case 3:
|
|
473
|
+
signatureEd25519 = _state.sent();
|
|
474
|
+
formattedSignature = Buffer.from(signatureEd25519).toString('base64');
|
|
475
|
+
return [
|
|
476
|
+
2,
|
|
477
|
+
formattedSignature
|
|
478
|
+
];
|
|
479
|
+
case 4:
|
|
480
|
+
error = _state.sent();
|
|
481
|
+
_this.logger.error(ERROR_SIGN_MESSAGE, error);
|
|
482
|
+
throw new Error(ERROR_SIGN_MESSAGE);
|
|
483
|
+
case 5:
|
|
484
|
+
return [
|
|
485
|
+
2
|
|
486
|
+
];
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
})();
|
|
490
|
+
}
|
|
491
|
+
},
|
|
492
|
+
{
|
|
493
|
+
key: "signTransaction",
|
|
494
|
+
value: function signTransaction(param) {
|
|
495
|
+
var senderAddress = param.senderAddress, transaction = param.transaction, _param_password = param.password, password = _param_password === void 0 ? undefined : _param_password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, context = param.context, onError = param.onError;
|
|
496
|
+
var _this = this;
|
|
497
|
+
return _async_to_generator(function() {
|
|
498
|
+
var resolvedContext, signatureEd25519, formattedSignature, error;
|
|
499
|
+
return _ts_generator(this, function(_state) {
|
|
500
|
+
switch(_state.label){
|
|
501
|
+
case 0:
|
|
502
|
+
if (!senderAddress) {
|
|
503
|
+
throw new Error(ERROR_ACCOUNT_ADDRESS_REQUIRED);
|
|
504
|
+
}
|
|
505
|
+
return [
|
|
506
|
+
4,
|
|
507
|
+
_this.verifyPassword({
|
|
508
|
+
accountAddress: senderAddress,
|
|
509
|
+
password: password,
|
|
510
|
+
walletOperation: browser.WalletOperation.SIGN_TRANSACTION,
|
|
511
|
+
signedSessionId: signedSessionId
|
|
512
|
+
})
|
|
513
|
+
];
|
|
514
|
+
case 1:
|
|
515
|
+
_state.sent();
|
|
516
|
+
resolvedContext = _object_spread_props(_object_spread({}, context), {
|
|
517
|
+
tonTransaction: {
|
|
518
|
+
serializedTransaction: transaction
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
_state.label = 2;
|
|
522
|
+
case 2:
|
|
523
|
+
_state.trys.push([
|
|
524
|
+
2,
|
|
525
|
+
4,
|
|
526
|
+
,
|
|
527
|
+
5
|
|
528
|
+
]);
|
|
529
|
+
return [
|
|
530
|
+
4,
|
|
531
|
+
_this.sign({
|
|
532
|
+
message: transaction,
|
|
533
|
+
accountAddress: senderAddress,
|
|
534
|
+
chainName: _this.chainName,
|
|
535
|
+
password: password,
|
|
536
|
+
signedSessionId: signedSessionId,
|
|
537
|
+
mfaToken: mfaToken,
|
|
538
|
+
context: resolvedContext,
|
|
539
|
+
onError: onError
|
|
540
|
+
})
|
|
541
|
+
];
|
|
542
|
+
case 3:
|
|
543
|
+
signatureEd25519 = _state.sent();
|
|
544
|
+
formattedSignature = Buffer.from(signatureEd25519).toString('base64');
|
|
545
|
+
return [
|
|
546
|
+
2,
|
|
547
|
+
formattedSignature
|
|
548
|
+
];
|
|
549
|
+
case 4:
|
|
550
|
+
error = _state.sent();
|
|
551
|
+
_this.logger.error(ERROR_SIGN_TRANSACTION, error);
|
|
552
|
+
throw new Error(ERROR_SIGN_TRANSACTION);
|
|
553
|
+
case 5:
|
|
554
|
+
return [
|
|
555
|
+
2
|
|
556
|
+
];
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
})();
|
|
560
|
+
}
|
|
561
|
+
},
|
|
562
|
+
{
|
|
563
|
+
key: "exportPrivateKey",
|
|
564
|
+
value: function exportPrivateKey(param) {
|
|
565
|
+
var accountAddress = param.accountAddress, _param_password = param.password, password = _param_password === void 0 ? undefined : _param_password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken;
|
|
566
|
+
var _this = this;
|
|
567
|
+
return _async_to_generator(function() {
|
|
568
|
+
var derivedPrivateKey, privateScalarHex, error;
|
|
569
|
+
return _ts_generator(this, function(_state) {
|
|
570
|
+
switch(_state.label){
|
|
571
|
+
case 0:
|
|
572
|
+
_state.trys.push([
|
|
573
|
+
0,
|
|
574
|
+
2,
|
|
575
|
+
,
|
|
576
|
+
3
|
|
577
|
+
]);
|
|
578
|
+
return [
|
|
579
|
+
4,
|
|
580
|
+
_this.exportKey({
|
|
581
|
+
accountAddress: accountAddress,
|
|
582
|
+
chainName: _this.chainName,
|
|
583
|
+
password: password,
|
|
584
|
+
signedSessionId: signedSessionId,
|
|
585
|
+
mfaToken: mfaToken
|
|
586
|
+
})
|
|
587
|
+
];
|
|
588
|
+
case 1:
|
|
589
|
+
derivedPrivateKey = _state.sent().derivedPrivateKey;
|
|
590
|
+
if (!derivedPrivateKey) {
|
|
591
|
+
throw new Error('Derived private key is undefined');
|
|
592
|
+
}
|
|
593
|
+
// TON private keys are 64 hex characters (32 bytes)
|
|
594
|
+
privateScalarHex = derivedPrivateKey.slice(0, 64);
|
|
595
|
+
return [
|
|
596
|
+
2,
|
|
597
|
+
privateScalarHex
|
|
598
|
+
];
|
|
599
|
+
case 2:
|
|
600
|
+
error = _state.sent();
|
|
601
|
+
_this.logger.error(ERROR_EXPORT_PRIVATE_KEY, error);
|
|
602
|
+
throw new Error(ERROR_EXPORT_PRIVATE_KEY);
|
|
603
|
+
case 3:
|
|
604
|
+
return [
|
|
605
|
+
2
|
|
606
|
+
];
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
})();
|
|
610
|
+
}
|
|
611
|
+
},
|
|
612
|
+
{
|
|
613
|
+
key: "getTonWallets",
|
|
614
|
+
value: function getTonWallets() {
|
|
615
|
+
var _this = this;
|
|
616
|
+
return _async_to_generator(function() {
|
|
617
|
+
var wallets, tonWallets;
|
|
618
|
+
return _ts_generator(this, function(_state) {
|
|
619
|
+
switch(_state.label){
|
|
620
|
+
case 0:
|
|
621
|
+
return [
|
|
622
|
+
4,
|
|
623
|
+
_this.getWallets()
|
|
624
|
+
];
|
|
625
|
+
case 1:
|
|
626
|
+
wallets = _state.sent();
|
|
627
|
+
tonWallets = wallets.filter(function(wallet) {
|
|
628
|
+
return wallet.chainName === 'ton';
|
|
629
|
+
});
|
|
630
|
+
return [
|
|
631
|
+
2,
|
|
632
|
+
tonWallets
|
|
633
|
+
];
|
|
634
|
+
}
|
|
635
|
+
});
|
|
636
|
+
})();
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
]);
|
|
640
|
+
return DynamicTonWalletClient;
|
|
641
|
+
}(browser.DynamicWalletClient);
|
|
642
|
+
|
|
643
|
+
exports.sdkApiCore = sdkApiCore__namespace;
|
|
644
|
+
exports.DynamicTonWalletClient = DynamicTonWalletClient;
|
package/index.esm.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|