@dynamic-labs-wallet/stellar 0.0.0 → 0.0.273
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 +812 -0
- package/index.esm.d.ts +1 -0
- package/index.esm.js +789 -0
- package/package.json +34 -1
- package/src/client/client.d.ts +59 -0
- package/src/client/client.d.ts.map +1 -0
- package/src/client/constants.d.ts +19 -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 +4 -0
- package/src/index.d.ts.map +1 -0
- package/src/utils/deriveStellarAddress/deriveStellarAddress.d.ts +21 -0
- package/src/utils/deriveStellarAddress/deriveStellarAddress.d.ts.map +1 -0
- package/src/utils/deriveStellarAddress/index.d.ts +2 -0
- package/src/utils/deriveStellarAddress/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.js
ADDED
|
@@ -0,0 +1,812 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var browser = require('@dynamic-labs-wallet/browser');
|
|
4
|
+
var stellarSdk = require('@stellar/stellar-sdk');
|
|
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 Stellar address (public key) from a raw Ed25519 public key
|
|
28
|
+
* Stellar addresses use StrKey encoding with version byte for public keys
|
|
29
|
+
* They start with 'G' and are 56 characters long
|
|
30
|
+
*/ var deriveStellarAddress = function(param) {
|
|
31
|
+
var publicKeyHex = param.publicKeyHex;
|
|
32
|
+
var pubKeyBytes = Buffer.from(publicKeyHex, 'hex');
|
|
33
|
+
if (pubKeyBytes.length !== 32) {
|
|
34
|
+
throw new Error("Invalid public key length: ".concat(pubKeyBytes.length, ", expected 32"));
|
|
35
|
+
}
|
|
36
|
+
// Encode the raw Ed25519 public key to Stellar's StrKey format (G... address)
|
|
37
|
+
return stellarSdk.StrKey.encodeEd25519PublicKey(pubKeyBytes);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
var ERROR_KEYGEN_FAILED = 'Error with keygen';
|
|
41
|
+
var ERROR_CREATE_WALLET_ACCOUNT = 'Error creating stellar wallet account';
|
|
42
|
+
var ERROR_IMPORT_PRIVATE_KEY = 'Error importing private key';
|
|
43
|
+
var ERROR_EXPORT_PRIVATE_KEY = 'Error exporting private key';
|
|
44
|
+
var ERROR_SIGN_MESSAGE = 'Error signing message';
|
|
45
|
+
var ERROR_ACCOUNT_ADDRESS_REQUIRED = 'Account address is required';
|
|
46
|
+
var ERROR_SIGN_TRANSACTION = 'Error signing transaction';
|
|
47
|
+
var STELLAR_NETWORK_PASSPHRASES = {
|
|
48
|
+
MAINNET: 'Public Global Stellar Network ; September 2015',
|
|
49
|
+
TESTNET: 'Test SDF Network ; September 2015',
|
|
50
|
+
FUTURENET: 'Test SDF Future Network ; October 2022'
|
|
51
|
+
};
|
|
52
|
+
/** Horizon API base URLs. Use when fetching account/balance so mainnet UI uses mainnet, testnet uses testnet. */ var STELLAR_HORIZON_URLS = {
|
|
53
|
+
MAINNET: 'https://horizon.stellar.org',
|
|
54
|
+
TESTNET: 'https://horizon-testnet.stellar.org',
|
|
55
|
+
FUTURENET: 'https://horizon-futurenet.stellar.org'
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// eslint-disable-next-line @nx/enforce-module-boundaries
|
|
59
|
+
function _assert_this_initialized(self) {
|
|
60
|
+
if (self === void 0) {
|
|
61
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
62
|
+
}
|
|
63
|
+
return self;
|
|
64
|
+
}
|
|
65
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
66
|
+
try {
|
|
67
|
+
var info = gen[key](arg);
|
|
68
|
+
var value = info.value;
|
|
69
|
+
} catch (error) {
|
|
70
|
+
reject(error);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (info.done) {
|
|
74
|
+
resolve(value);
|
|
75
|
+
} else {
|
|
76
|
+
Promise.resolve(value).then(_next, _throw);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function _async_to_generator(fn) {
|
|
80
|
+
return function() {
|
|
81
|
+
var self = this, args = arguments;
|
|
82
|
+
return new Promise(function(resolve, reject) {
|
|
83
|
+
var gen = fn.apply(self, args);
|
|
84
|
+
function _next(value) {
|
|
85
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
86
|
+
}
|
|
87
|
+
function _throw(err) {
|
|
88
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
89
|
+
}
|
|
90
|
+
_next(undefined);
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function _call_super(_this, derived, args) {
|
|
95
|
+
derived = _get_prototype_of(derived);
|
|
96
|
+
return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
|
|
97
|
+
}
|
|
98
|
+
function _class_call_check(instance, Constructor) {
|
|
99
|
+
if (!(instance instanceof Constructor)) {
|
|
100
|
+
throw new TypeError("Cannot call a class as a function");
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function _defineProperties(target, props) {
|
|
104
|
+
for(var i = 0; i < props.length; i++){
|
|
105
|
+
var descriptor = props[i];
|
|
106
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
107
|
+
descriptor.configurable = true;
|
|
108
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
109
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
113
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
114
|
+
return Constructor;
|
|
115
|
+
}
|
|
116
|
+
function _define_property(obj, key, value) {
|
|
117
|
+
if (key in obj) {
|
|
118
|
+
Object.defineProperty(obj, key, {
|
|
119
|
+
value: value,
|
|
120
|
+
enumerable: true,
|
|
121
|
+
configurable: true,
|
|
122
|
+
writable: true
|
|
123
|
+
});
|
|
124
|
+
} else {
|
|
125
|
+
obj[key] = value;
|
|
126
|
+
}
|
|
127
|
+
return obj;
|
|
128
|
+
}
|
|
129
|
+
function _get_prototype_of(o) {
|
|
130
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
131
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
132
|
+
};
|
|
133
|
+
return _get_prototype_of(o);
|
|
134
|
+
}
|
|
135
|
+
function _inherits(subClass, superClass) {
|
|
136
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
137
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
138
|
+
}
|
|
139
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
140
|
+
constructor: {
|
|
141
|
+
value: subClass,
|
|
142
|
+
writable: true,
|
|
143
|
+
configurable: true
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
147
|
+
}
|
|
148
|
+
function _instanceof(left, right) {
|
|
149
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
150
|
+
return !!right[Symbol.hasInstance](left);
|
|
151
|
+
} else {
|
|
152
|
+
return left instanceof right;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function _object_spread(target) {
|
|
156
|
+
for(var i = 1; i < arguments.length; i++){
|
|
157
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
158
|
+
var ownKeys = Object.keys(source);
|
|
159
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
160
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
161
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
162
|
+
}));
|
|
163
|
+
}
|
|
164
|
+
ownKeys.forEach(function(key) {
|
|
165
|
+
_define_property(target, key, source[key]);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
return target;
|
|
169
|
+
}
|
|
170
|
+
function ownKeys(object, enumerableOnly) {
|
|
171
|
+
var keys = Object.keys(object);
|
|
172
|
+
if (Object.getOwnPropertySymbols) {
|
|
173
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
174
|
+
keys.push.apply(keys, symbols);
|
|
175
|
+
}
|
|
176
|
+
return keys;
|
|
177
|
+
}
|
|
178
|
+
function _object_spread_props(target, source) {
|
|
179
|
+
source = source != null ? source : {};
|
|
180
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
181
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
182
|
+
} else {
|
|
183
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
184
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return target;
|
|
188
|
+
}
|
|
189
|
+
function _possible_constructor_return(self, call) {
|
|
190
|
+
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
191
|
+
return call;
|
|
192
|
+
}
|
|
193
|
+
return _assert_this_initialized(self);
|
|
194
|
+
}
|
|
195
|
+
function _set_prototype_of(o, p) {
|
|
196
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
197
|
+
o.__proto__ = p;
|
|
198
|
+
return o;
|
|
199
|
+
};
|
|
200
|
+
return _set_prototype_of(o, p);
|
|
201
|
+
}
|
|
202
|
+
function _type_of(obj) {
|
|
203
|
+
"@swc/helpers - typeof";
|
|
204
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
205
|
+
}
|
|
206
|
+
function _is_native_reflect_construct() {
|
|
207
|
+
try {
|
|
208
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
209
|
+
} catch (_) {}
|
|
210
|
+
return (_is_native_reflect_construct = function() {
|
|
211
|
+
return !!result;
|
|
212
|
+
})();
|
|
213
|
+
}
|
|
214
|
+
function _ts_generator(thisArg, body) {
|
|
215
|
+
var f, y, t, g, _ = {
|
|
216
|
+
label: 0,
|
|
217
|
+
sent: function() {
|
|
218
|
+
if (t[0] & 1) throw t[1];
|
|
219
|
+
return t[1];
|
|
220
|
+
},
|
|
221
|
+
trys: [],
|
|
222
|
+
ops: []
|
|
223
|
+
};
|
|
224
|
+
return g = {
|
|
225
|
+
next: verb(0),
|
|
226
|
+
"throw": verb(1),
|
|
227
|
+
"return": verb(2)
|
|
228
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
229
|
+
return this;
|
|
230
|
+
}), g;
|
|
231
|
+
function verb(n) {
|
|
232
|
+
return function(v) {
|
|
233
|
+
return step([
|
|
234
|
+
n,
|
|
235
|
+
v
|
|
236
|
+
]);
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
function step(op) {
|
|
240
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
241
|
+
while(_)try {
|
|
242
|
+
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;
|
|
243
|
+
if (y = 0, t) op = [
|
|
244
|
+
op[0] & 2,
|
|
245
|
+
t.value
|
|
246
|
+
];
|
|
247
|
+
switch(op[0]){
|
|
248
|
+
case 0:
|
|
249
|
+
case 1:
|
|
250
|
+
t = op;
|
|
251
|
+
break;
|
|
252
|
+
case 4:
|
|
253
|
+
_.label++;
|
|
254
|
+
return {
|
|
255
|
+
value: op[1],
|
|
256
|
+
done: false
|
|
257
|
+
};
|
|
258
|
+
case 5:
|
|
259
|
+
_.label++;
|
|
260
|
+
y = op[1];
|
|
261
|
+
op = [
|
|
262
|
+
0
|
|
263
|
+
];
|
|
264
|
+
continue;
|
|
265
|
+
case 7:
|
|
266
|
+
op = _.ops.pop();
|
|
267
|
+
_.trys.pop();
|
|
268
|
+
continue;
|
|
269
|
+
default:
|
|
270
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
271
|
+
_ = 0;
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
275
|
+
_.label = op[1];
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
279
|
+
_.label = t[1];
|
|
280
|
+
t = op;
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
if (t && _.label < t[2]) {
|
|
284
|
+
_.label = t[2];
|
|
285
|
+
_.ops.push(op);
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
if (t[2]) _.ops.pop();
|
|
289
|
+
_.trys.pop();
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
op = body.call(thisArg, _);
|
|
293
|
+
} catch (e) {
|
|
294
|
+
op = [
|
|
295
|
+
6,
|
|
296
|
+
e
|
|
297
|
+
];
|
|
298
|
+
y = 0;
|
|
299
|
+
} finally{
|
|
300
|
+
f = t = 0;
|
|
301
|
+
}
|
|
302
|
+
if (op[0] & 5) throw op[1];
|
|
303
|
+
return {
|
|
304
|
+
value: op[0] ? op[1] : void 0,
|
|
305
|
+
done: true
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
var DynamicStellarWalletClient = /*#__PURE__*/ function(DynamicWalletClient) {
|
|
310
|
+
_inherits(DynamicStellarWalletClient, DynamicWalletClient);
|
|
311
|
+
function DynamicStellarWalletClient(param, internalOptions) {
|
|
312
|
+
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;
|
|
313
|
+
_class_call_check(this, DynamicStellarWalletClient);
|
|
314
|
+
var _this;
|
|
315
|
+
_this = _call_super(this, DynamicStellarWalletClient, [
|
|
316
|
+
{
|
|
317
|
+
environmentId: environmentId,
|
|
318
|
+
authToken: authToken,
|
|
319
|
+
baseApiUrl: baseApiUrl,
|
|
320
|
+
baseMPCRelayApiUrl: baseMPCRelayApiUrl,
|
|
321
|
+
storageKey: storageKey,
|
|
322
|
+
debug: debug,
|
|
323
|
+
featureFlags: featureFlags,
|
|
324
|
+
authMode: authMode,
|
|
325
|
+
sdkVersion: sdkVersion,
|
|
326
|
+
forwardMPCClient: forwardMPCClient
|
|
327
|
+
},
|
|
328
|
+
internalOptions
|
|
329
|
+
]), _define_property(_this, "chainName", 'STELLAR');
|
|
330
|
+
return _this;
|
|
331
|
+
}
|
|
332
|
+
_create_class(DynamicStellarWalletClient, [
|
|
333
|
+
{
|
|
334
|
+
key: "createWalletAccount",
|
|
335
|
+
value: function createWalletAccount(param) {
|
|
336
|
+
var thresholdSignatureScheme = param.thresholdSignatureScheme, _param_password = param.password, password = _param_password === void 0 ? undefined : _param_password, onError = param.onError, signedSessionId = param.signedSessionId;
|
|
337
|
+
var _this = this;
|
|
338
|
+
return _async_to_generator(function() {
|
|
339
|
+
var ceremonyCeremonyCompleteResolver, ceremonyCompletePromise, _ref, publicKeyHex, clientKeyShares, accountAddress, pubKeyBytes, error;
|
|
340
|
+
return _ts_generator(this, function(_state) {
|
|
341
|
+
switch(_state.label){
|
|
342
|
+
case 0:
|
|
343
|
+
_state.trys.push([
|
|
344
|
+
0,
|
|
345
|
+
5,
|
|
346
|
+
,
|
|
347
|
+
6
|
|
348
|
+
]);
|
|
349
|
+
ceremonyCompletePromise = new Promise(function(resolve) {
|
|
350
|
+
ceremonyCeremonyCompleteResolver = resolve;
|
|
351
|
+
});
|
|
352
|
+
return [
|
|
353
|
+
4,
|
|
354
|
+
_this.keyGen({
|
|
355
|
+
chainName: _this.chainName,
|
|
356
|
+
thresholdSignatureScheme: thresholdSignatureScheme,
|
|
357
|
+
onError: onError,
|
|
358
|
+
onCeremonyComplete: function(accountAddress, walletId) {
|
|
359
|
+
var chainConfig = browser.getMPCChainConfig(_this.chainName);
|
|
360
|
+
_this.initializeWalletMapEntry({
|
|
361
|
+
accountAddress: accountAddress,
|
|
362
|
+
walletId: walletId,
|
|
363
|
+
chainName: _this.chainName,
|
|
364
|
+
thresholdSignatureScheme: thresholdSignatureScheme,
|
|
365
|
+
derivationPath: JSON.stringify(Object.fromEntries(chainConfig.derivationPath.map(function(value, index) {
|
|
366
|
+
return [
|
|
367
|
+
index,
|
|
368
|
+
value
|
|
369
|
+
];
|
|
370
|
+
})))
|
|
371
|
+
});
|
|
372
|
+
ceremonyCeremonyCompleteResolver(undefined);
|
|
373
|
+
},
|
|
374
|
+
password: password,
|
|
375
|
+
signedSessionId: signedSessionId
|
|
376
|
+
})
|
|
377
|
+
];
|
|
378
|
+
case 1:
|
|
379
|
+
_ref = _state.sent(), publicKeyHex = _ref.rawPublicKey, clientKeyShares = _ref.clientKeyShares;
|
|
380
|
+
// Wait for the ceremony to complete before proceeding
|
|
381
|
+
return [
|
|
382
|
+
4,
|
|
383
|
+
ceremonyCompletePromise
|
|
384
|
+
];
|
|
385
|
+
case 2:
|
|
386
|
+
_state.sent();
|
|
387
|
+
if (!publicKeyHex || !clientKeyShares) {
|
|
388
|
+
throw new Error(ERROR_KEYGEN_FAILED);
|
|
389
|
+
}
|
|
390
|
+
accountAddress = deriveStellarAddress({
|
|
391
|
+
publicKeyHex: publicKeyHex
|
|
392
|
+
});
|
|
393
|
+
// Update client key shares in wallet map
|
|
394
|
+
return [
|
|
395
|
+
4,
|
|
396
|
+
_this.setClientKeySharesToStorage({
|
|
397
|
+
accountAddress: accountAddress,
|
|
398
|
+
clientKeyShares: clientKeyShares,
|
|
399
|
+
overwriteOrMerge: 'overwrite'
|
|
400
|
+
})
|
|
401
|
+
];
|
|
402
|
+
case 3:
|
|
403
|
+
_state.sent();
|
|
404
|
+
return [
|
|
405
|
+
4,
|
|
406
|
+
_this.storeEncryptedBackupByWalletWithRetry({
|
|
407
|
+
accountAddress: accountAddress,
|
|
408
|
+
clientKeyShares: clientKeyShares,
|
|
409
|
+
password: password,
|
|
410
|
+
signedSessionId: signedSessionId
|
|
411
|
+
})
|
|
412
|
+
];
|
|
413
|
+
case 4:
|
|
414
|
+
_state.sent();
|
|
415
|
+
pubKeyBytes = Buffer.from(publicKeyHex, 'hex');
|
|
416
|
+
return [
|
|
417
|
+
2,
|
|
418
|
+
{
|
|
419
|
+
accountAddress: accountAddress,
|
|
420
|
+
publicKeyHex: publicKeyHex,
|
|
421
|
+
rawPublicKey: new Uint8Array(pubKeyBytes)
|
|
422
|
+
}
|
|
423
|
+
];
|
|
424
|
+
case 5:
|
|
425
|
+
error = _state.sent();
|
|
426
|
+
// Re-throw password mismatch errors without wrapping
|
|
427
|
+
if (_instanceof(error, Error) && error.message === browser.ERROR_PASSWORD_MISMATCH) {
|
|
428
|
+
throw error;
|
|
429
|
+
}
|
|
430
|
+
_this.logger.error(ERROR_CREATE_WALLET_ACCOUNT, error);
|
|
431
|
+
throw new Error(ERROR_CREATE_WALLET_ACCOUNT);
|
|
432
|
+
case 6:
|
|
433
|
+
return [
|
|
434
|
+
2
|
|
435
|
+
];
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
})();
|
|
439
|
+
}
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
key: "signMessage",
|
|
443
|
+
value: function signMessage(param) {
|
|
444
|
+
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;
|
|
445
|
+
var _this = this;
|
|
446
|
+
return _async_to_generator(function() {
|
|
447
|
+
var resolvedContext, signatureEd25519, formattedSignature, error;
|
|
448
|
+
return _ts_generator(this, function(_state) {
|
|
449
|
+
switch(_state.label){
|
|
450
|
+
case 0:
|
|
451
|
+
if (!accountAddress) {
|
|
452
|
+
throw new Error(ERROR_ACCOUNT_ADDRESS_REQUIRED);
|
|
453
|
+
}
|
|
454
|
+
return [
|
|
455
|
+
4,
|
|
456
|
+
_this.verifyPassword({
|
|
457
|
+
accountAddress: accountAddress,
|
|
458
|
+
password: password,
|
|
459
|
+
walletOperation: browser.WalletOperation.SIGN_MESSAGE,
|
|
460
|
+
signedSessionId: signedSessionId
|
|
461
|
+
})
|
|
462
|
+
];
|
|
463
|
+
case 1:
|
|
464
|
+
_state.sent();
|
|
465
|
+
resolvedContext = _object_spread_props(_object_spread({}, context), {
|
|
466
|
+
stellarMessage: message
|
|
467
|
+
});
|
|
468
|
+
_state.label = 2;
|
|
469
|
+
case 2:
|
|
470
|
+
_state.trys.push([
|
|
471
|
+
2,
|
|
472
|
+
4,
|
|
473
|
+
,
|
|
474
|
+
5
|
|
475
|
+
]);
|
|
476
|
+
return [
|
|
477
|
+
4,
|
|
478
|
+
_this.sign({
|
|
479
|
+
message: message,
|
|
480
|
+
accountAddress: accountAddress,
|
|
481
|
+
chainName: _this.chainName,
|
|
482
|
+
password: password,
|
|
483
|
+
signedSessionId: signedSessionId,
|
|
484
|
+
mfaToken: mfaToken,
|
|
485
|
+
context: resolvedContext,
|
|
486
|
+
onError: onError
|
|
487
|
+
})
|
|
488
|
+
];
|
|
489
|
+
case 3:
|
|
490
|
+
signatureEd25519 = _state.sent();
|
|
491
|
+
// Return signature as base64 encoded string (common format for Stellar)
|
|
492
|
+
formattedSignature = Buffer.from(signatureEd25519).toString('base64');
|
|
493
|
+
return [
|
|
494
|
+
2,
|
|
495
|
+
formattedSignature
|
|
496
|
+
];
|
|
497
|
+
case 4:
|
|
498
|
+
error = _state.sent();
|
|
499
|
+
_this.logger.error(ERROR_SIGN_MESSAGE, error);
|
|
500
|
+
throw new Error(ERROR_SIGN_MESSAGE);
|
|
501
|
+
case 5:
|
|
502
|
+
return [
|
|
503
|
+
2
|
|
504
|
+
];
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
})();
|
|
508
|
+
}
|
|
509
|
+
},
|
|
510
|
+
{
|
|
511
|
+
key: "signTransaction",
|
|
512
|
+
value: function signTransaction(param) {
|
|
513
|
+
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;
|
|
514
|
+
var _this = this;
|
|
515
|
+
return _async_to_generator(function() {
|
|
516
|
+
var resolvedContext, signatureEd25519, formattedSignature, error;
|
|
517
|
+
return _ts_generator(this, function(_state) {
|
|
518
|
+
switch(_state.label){
|
|
519
|
+
case 0:
|
|
520
|
+
if (!senderAddress) {
|
|
521
|
+
throw new Error(ERROR_ACCOUNT_ADDRESS_REQUIRED);
|
|
522
|
+
}
|
|
523
|
+
return [
|
|
524
|
+
4,
|
|
525
|
+
_this.verifyPassword({
|
|
526
|
+
accountAddress: senderAddress,
|
|
527
|
+
password: password,
|
|
528
|
+
walletOperation: browser.WalletOperation.SIGN_TRANSACTION,
|
|
529
|
+
signedSessionId: signedSessionId
|
|
530
|
+
})
|
|
531
|
+
];
|
|
532
|
+
case 1:
|
|
533
|
+
_state.sent();
|
|
534
|
+
resolvedContext = _object_spread_props(_object_spread({}, context), {
|
|
535
|
+
stellarTransaction: {
|
|
536
|
+
serializedTransaction: transaction
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
_state.label = 2;
|
|
540
|
+
case 2:
|
|
541
|
+
_state.trys.push([
|
|
542
|
+
2,
|
|
543
|
+
4,
|
|
544
|
+
,
|
|
545
|
+
5
|
|
546
|
+
]);
|
|
547
|
+
return [
|
|
548
|
+
4,
|
|
549
|
+
_this.sign({
|
|
550
|
+
message: transaction,
|
|
551
|
+
accountAddress: senderAddress,
|
|
552
|
+
chainName: _this.chainName,
|
|
553
|
+
password: password,
|
|
554
|
+
signedSessionId: signedSessionId,
|
|
555
|
+
mfaToken: mfaToken,
|
|
556
|
+
context: resolvedContext,
|
|
557
|
+
onError: onError
|
|
558
|
+
})
|
|
559
|
+
];
|
|
560
|
+
case 3:
|
|
561
|
+
signatureEd25519 = _state.sent();
|
|
562
|
+
// Return signature as base64 encoded string
|
|
563
|
+
formattedSignature = Buffer.from(signatureEd25519).toString('base64');
|
|
564
|
+
return [
|
|
565
|
+
2,
|
|
566
|
+
formattedSignature
|
|
567
|
+
];
|
|
568
|
+
case 4:
|
|
569
|
+
error = _state.sent();
|
|
570
|
+
_this.logger.error(ERROR_SIGN_TRANSACTION, error);
|
|
571
|
+
throw new Error(ERROR_SIGN_TRANSACTION);
|
|
572
|
+
case 5:
|
|
573
|
+
return [
|
|
574
|
+
2
|
|
575
|
+
];
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
})();
|
|
579
|
+
}
|
|
580
|
+
},
|
|
581
|
+
{
|
|
582
|
+
key: "exportPrivateKey",
|
|
583
|
+
value: function exportPrivateKey(param) {
|
|
584
|
+
var accountAddress = param.accountAddress, _param_password = param.password, password = _param_password === void 0 ? undefined : _param_password, signedSessionId = param.signedSessionId, mfaToken = param.mfaToken, elevatedAccessToken = param.elevatedAccessToken;
|
|
585
|
+
var _this = this;
|
|
586
|
+
return _async_to_generator(function() {
|
|
587
|
+
var derivedPrivateKey, privateScalarHex, privateKeyBytes, stellarSecretKey, error;
|
|
588
|
+
return _ts_generator(this, function(_state) {
|
|
589
|
+
switch(_state.label){
|
|
590
|
+
case 0:
|
|
591
|
+
_state.trys.push([
|
|
592
|
+
0,
|
|
593
|
+
2,
|
|
594
|
+
,
|
|
595
|
+
3
|
|
596
|
+
]);
|
|
597
|
+
return [
|
|
598
|
+
4,
|
|
599
|
+
_this.exportKey({
|
|
600
|
+
accountAddress: accountAddress,
|
|
601
|
+
chainName: _this.chainName,
|
|
602
|
+
password: password,
|
|
603
|
+
signedSessionId: signedSessionId,
|
|
604
|
+
mfaToken: mfaToken,
|
|
605
|
+
elevatedAccessToken: elevatedAccessToken
|
|
606
|
+
})
|
|
607
|
+
];
|
|
608
|
+
case 1:
|
|
609
|
+
derivedPrivateKey = _state.sent().derivedPrivateKey;
|
|
610
|
+
if (!derivedPrivateKey) {
|
|
611
|
+
throw new Error('Derived private key is undefined');
|
|
612
|
+
}
|
|
613
|
+
// Stellar private keys are 64 hex characters (32 bytes)
|
|
614
|
+
// Return the seed portion only (first 32 bytes)
|
|
615
|
+
privateScalarHex = derivedPrivateKey.slice(0, 64);
|
|
616
|
+
// Convert to Stellar secret key format (S...)
|
|
617
|
+
privateKeyBytes = Buffer.from(privateScalarHex, 'hex');
|
|
618
|
+
stellarSecretKey = stellarSdk.StrKey.encodeEd25519SecretSeed(privateKeyBytes);
|
|
619
|
+
return [
|
|
620
|
+
2,
|
|
621
|
+
stellarSecretKey
|
|
622
|
+
];
|
|
623
|
+
case 2:
|
|
624
|
+
error = _state.sent();
|
|
625
|
+
_this.logger.error(ERROR_EXPORT_PRIVATE_KEY, error);
|
|
626
|
+
throw new Error(ERROR_EXPORT_PRIVATE_KEY);
|
|
627
|
+
case 3:
|
|
628
|
+
return [
|
|
629
|
+
2
|
|
630
|
+
];
|
|
631
|
+
}
|
|
632
|
+
});
|
|
633
|
+
})();
|
|
634
|
+
}
|
|
635
|
+
},
|
|
636
|
+
{
|
|
637
|
+
key: "importPrivateKey",
|
|
638
|
+
value: function importPrivateKey(param) {
|
|
639
|
+
var privateKey = param.privateKey, chainName = param.chainName, thresholdSignatureScheme = param.thresholdSignatureScheme, _param_password = param.password, password = _param_password === void 0 ? undefined : _param_password, signedSessionId = param.signedSessionId, onError = param.onError, publicAddressCheck = param.publicAddressCheck, legacyWalletId = param.legacyWalletId;
|
|
640
|
+
var _this = this;
|
|
641
|
+
return _async_to_generator(function() {
|
|
642
|
+
var ceremonyCeremonyCompleteResolver, ceremonyCompletePromise, formattedPrivateKey, secretKeyBytes, publicKeyHex, derivedAddress, _ref, rawPublicKey, clientKeyShares, accountAddress, pubKeyBytes, error;
|
|
643
|
+
return _ts_generator(this, function(_state) {
|
|
644
|
+
switch(_state.label){
|
|
645
|
+
case 0:
|
|
646
|
+
_state.trys.push([
|
|
647
|
+
0,
|
|
648
|
+
5,
|
|
649
|
+
,
|
|
650
|
+
6
|
|
651
|
+
]);
|
|
652
|
+
ceremonyCompletePromise = new Promise(function(resolve) {
|
|
653
|
+
ceremonyCeremonyCompleteResolver = resolve;
|
|
654
|
+
});
|
|
655
|
+
if (privateKey.startsWith('S')) {
|
|
656
|
+
// Stellar secret key format (S...)
|
|
657
|
+
secretKeyBytes = stellarSdk.StrKey.decodeEd25519SecretSeed(privateKey);
|
|
658
|
+
formattedPrivateKey = Array.from(secretKeyBytes).map(function(b) {
|
|
659
|
+
return b.toString(16).padStart(2, '0');
|
|
660
|
+
}).join('');
|
|
661
|
+
} else if (privateKey.startsWith('0x')) {
|
|
662
|
+
formattedPrivateKey = privateKey.slice(2);
|
|
663
|
+
} else {
|
|
664
|
+
formattedPrivateKey = privateKey;
|
|
665
|
+
}
|
|
666
|
+
publicKeyHex = _this.getPublicKeyFromPrivateKey(formattedPrivateKey);
|
|
667
|
+
derivedAddress = deriveStellarAddress({
|
|
668
|
+
publicKeyHex: publicKeyHex
|
|
669
|
+
});
|
|
670
|
+
if (publicAddressCheck && derivedAddress !== publicAddressCheck) {
|
|
671
|
+
throw new Error("Public address mismatch: derived address ".concat(derivedAddress, " !== public address ").concat(publicAddressCheck));
|
|
672
|
+
}
|
|
673
|
+
return [
|
|
674
|
+
4,
|
|
675
|
+
_this.importRawPrivateKey({
|
|
676
|
+
chainName: chainName,
|
|
677
|
+
thresholdSignatureScheme: thresholdSignatureScheme,
|
|
678
|
+
privateKey: formattedPrivateKey,
|
|
679
|
+
onCeremonyComplete: function(accountAddress, walletId) {
|
|
680
|
+
_this.initializeWalletMapEntry({
|
|
681
|
+
accountAddress: accountAddress,
|
|
682
|
+
walletId: walletId,
|
|
683
|
+
chainName: _this.chainName,
|
|
684
|
+
thresholdSignatureScheme: thresholdSignatureScheme
|
|
685
|
+
});
|
|
686
|
+
ceremonyCeremonyCompleteResolver(undefined);
|
|
687
|
+
},
|
|
688
|
+
onError: onError,
|
|
689
|
+
legacyWalletId: legacyWalletId,
|
|
690
|
+
password: password,
|
|
691
|
+
signedSessionId: signedSessionId
|
|
692
|
+
})
|
|
693
|
+
];
|
|
694
|
+
case 1:
|
|
695
|
+
_ref = _state.sent(), rawPublicKey = _ref.rawPublicKey, clientKeyShares = _ref.clientKeyShares;
|
|
696
|
+
return [
|
|
697
|
+
4,
|
|
698
|
+
ceremonyCompletePromise
|
|
699
|
+
];
|
|
700
|
+
case 2:
|
|
701
|
+
_state.sent();
|
|
702
|
+
if (!rawPublicKey || !clientKeyShares) {
|
|
703
|
+
throw new Error(ERROR_IMPORT_PRIVATE_KEY);
|
|
704
|
+
}
|
|
705
|
+
accountAddress = deriveStellarAddress({
|
|
706
|
+
publicKeyHex: rawPublicKey
|
|
707
|
+
});
|
|
708
|
+
if (accountAddress !== derivedAddress) {
|
|
709
|
+
throw new Error("Public key mismatch: derived address ".concat(accountAddress, " !== expected ").concat(derivedAddress));
|
|
710
|
+
}
|
|
711
|
+
// Update client key shares in wallet map
|
|
712
|
+
return [
|
|
713
|
+
4,
|
|
714
|
+
_this.setClientKeySharesToStorage({
|
|
715
|
+
accountAddress: accountAddress,
|
|
716
|
+
clientKeyShares: clientKeyShares,
|
|
717
|
+
overwriteOrMerge: 'overwrite'
|
|
718
|
+
})
|
|
719
|
+
];
|
|
720
|
+
case 3:
|
|
721
|
+
_state.sent();
|
|
722
|
+
return [
|
|
723
|
+
4,
|
|
724
|
+
_this.storeEncryptedBackupByWalletWithRetry({
|
|
725
|
+
accountAddress: accountAddress,
|
|
726
|
+
clientKeyShares: clientKeyShares,
|
|
727
|
+
password: password,
|
|
728
|
+
signedSessionId: signedSessionId
|
|
729
|
+
})
|
|
730
|
+
];
|
|
731
|
+
case 4:
|
|
732
|
+
_state.sent();
|
|
733
|
+
pubKeyBytes = Buffer.from(rawPublicKey, 'hex');
|
|
734
|
+
return [
|
|
735
|
+
2,
|
|
736
|
+
{
|
|
737
|
+
accountAddress: accountAddress,
|
|
738
|
+
publicKeyHex: rawPublicKey,
|
|
739
|
+
rawPublicKey: new Uint8Array(pubKeyBytes),
|
|
740
|
+
clientKeyShares: clientKeyShares
|
|
741
|
+
}
|
|
742
|
+
];
|
|
743
|
+
case 5:
|
|
744
|
+
error = _state.sent();
|
|
745
|
+
_this.logger.error(ERROR_IMPORT_PRIVATE_KEY, error);
|
|
746
|
+
onError === null || onError === void 0 ? void 0 : onError(error);
|
|
747
|
+
throw new Error(ERROR_IMPORT_PRIVATE_KEY);
|
|
748
|
+
case 6:
|
|
749
|
+
return [
|
|
750
|
+
2
|
|
751
|
+
];
|
|
752
|
+
}
|
|
753
|
+
});
|
|
754
|
+
})();
|
|
755
|
+
}
|
|
756
|
+
},
|
|
757
|
+
{
|
|
758
|
+
key: "getPublicKeyFromPrivateKey",
|
|
759
|
+
value: function getPublicKeyFromPrivateKey(privateKeyHex) {
|
|
760
|
+
try {
|
|
761
|
+
var privateKeyBytes = Buffer.from(privateKeyHex, 'hex');
|
|
762
|
+
if (privateKeyBytes.length !== 32) {
|
|
763
|
+
throw new Error("Invalid private key length: ".concat(privateKeyBytes.length, ", expected 32"));
|
|
764
|
+
}
|
|
765
|
+
// Create keypair from raw secret seed
|
|
766
|
+
var keypair = stellarSdk.Keypair.fromRawEd25519Seed(privateKeyBytes);
|
|
767
|
+
// Return the public key as hex
|
|
768
|
+
var raw = keypair.rawPublicKey();
|
|
769
|
+
return Array.from(raw).map(function(b) {
|
|
770
|
+
return b.toString(16).padStart(2, '0');
|
|
771
|
+
}).join('');
|
|
772
|
+
} catch (error) {
|
|
773
|
+
this.logger.error('Unable to derive public key from private key. Check private key format', _instanceof(error, Error) ? error.message : 'Unknown error');
|
|
774
|
+
throw error;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
},
|
|
778
|
+
{
|
|
779
|
+
key: "getStellarWallets",
|
|
780
|
+
value: function getStellarWallets() {
|
|
781
|
+
var _this = this;
|
|
782
|
+
return _async_to_generator(function() {
|
|
783
|
+
var wallets, stellarWallets;
|
|
784
|
+
return _ts_generator(this, function(_state) {
|
|
785
|
+
switch(_state.label){
|
|
786
|
+
case 0:
|
|
787
|
+
return [
|
|
788
|
+
4,
|
|
789
|
+
_this.getWallets()
|
|
790
|
+
];
|
|
791
|
+
case 1:
|
|
792
|
+
wallets = _state.sent();
|
|
793
|
+
stellarWallets = wallets.filter(function(wallet) {
|
|
794
|
+
return wallet.chainName === 'stellar';
|
|
795
|
+
});
|
|
796
|
+
return [
|
|
797
|
+
2,
|
|
798
|
+
stellarWallets
|
|
799
|
+
];
|
|
800
|
+
}
|
|
801
|
+
});
|
|
802
|
+
})();
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
]);
|
|
806
|
+
return DynamicStellarWalletClient;
|
|
807
|
+
}(browser.DynamicWalletClient);
|
|
808
|
+
|
|
809
|
+
exports.sdkApiCore = sdkApiCore__namespace;
|
|
810
|
+
exports.DynamicStellarWalletClient = DynamicStellarWalletClient;
|
|
811
|
+
exports.STELLAR_HORIZON_URLS = STELLAR_HORIZON_URLS;
|
|
812
|
+
exports.STELLAR_NETWORK_PASSPHRASES = STELLAR_NETWORK_PASSPHRASES;
|