@getpara/core-sdk 3.8.0 → 3.9.0
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/cjs/ParaCore.js +2 -1
- package/dist/cjs/constants.js +1 -1
- package/dist/cjs/services/AuthService.js +14 -8
- package/dist/cjs/services/PregenWalletService.js +11 -4
- package/dist/cjs/services/VerificationFlowService.js +2 -2
- package/dist/cjs/services/WalletService.js +11 -3
- package/dist/cjs/state/CoreStateManager.js +70 -0
- package/dist/cjs/utils/formatting.js +29 -1
- package/dist/cjs/utils/wallet.js +2 -1
- package/dist/esm/ParaCore.js +2 -1
- package/dist/esm/constants.js +1 -1
- package/dist/esm/services/AuthService.js +14 -8
- package/dist/esm/services/PregenWalletService.js +11 -4
- package/dist/esm/services/VerificationFlowService.js +2 -2
- package/dist/esm/services/WalletService.js +13 -3
- package/dist/esm/state/CoreStateManager.js +70 -0
- package/dist/esm/utils/formatting.js +27 -1
- package/dist/esm/utils/wallet.js +2 -1
- package/dist/types/state/CoreStateManager.d.ts +11 -0
- package/dist/types/utils/formatting.d.ts +2 -0
- package/package.json +3 -3
package/dist/cjs/ParaCore.js
CHANGED
|
@@ -2898,6 +2898,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2898
2898
|
**/
|
|
2899
2899
|
logout() {
|
|
2900
2900
|
return __async(this, arguments, function* ({ clearPregenWallets = false } = {}) {
|
|
2901
|
+
__privateGet(this, _stateManager).cancelPendingAuthSends("logout");
|
|
2901
2902
|
yield __privateMethod(this, _ParaCore_instances, logout_fn).call(this, { clearPregenWallets });
|
|
2902
2903
|
__privateGet(this, _pollingService).cancelAllPolling();
|
|
2903
2904
|
yield __privateGet(this, _externalWalletService).disconnectAllExternalWallets();
|
|
@@ -3166,7 +3167,7 @@ const _ParaCore = class _ParaCore {
|
|
|
3166
3167
|
return __async(this, arguments, function* ({ config, refetch = false } = {}) {
|
|
3167
3168
|
const { balance } = yield this.ctx.client.getProfileBalance({
|
|
3168
3169
|
config,
|
|
3169
|
-
wallets: this.availableWallets.filter(({ type }) => type !== "COSMOS" && type !== "STELLAR").map(({ type, address }) => ({ type, address })),
|
|
3170
|
+
wallets: this.availableWallets.filter(({ type }) => type !== "COSMOS" && type !== "STELLAR" && type !== "SUI").map(({ type, address }) => ({ type, address })),
|
|
3170
3171
|
refetch
|
|
3171
3172
|
});
|
|
3172
3173
|
return balance;
|
package/dist/cjs/constants.js
CHANGED
|
@@ -46,7 +46,7 @@ __export(constants_exports, {
|
|
|
46
46
|
TRANSACTION_REVIEW_TIMEOUT_MS: () => TRANSACTION_REVIEW_TIMEOUT_MS
|
|
47
47
|
});
|
|
48
48
|
module.exports = __toCommonJS(constants_exports);
|
|
49
|
-
const PARA_CORE_VERSION = "3.
|
|
49
|
+
const PARA_CORE_VERSION = "3.9.0";
|
|
50
50
|
const PREFIX = "@CAPSULE/";
|
|
51
51
|
const PARA_PREFIX = "@PARA/";
|
|
52
52
|
const LOCAL_STORAGE_AUTH_INFO = `${PREFIX}authInfo`;
|
|
@@ -272,7 +272,10 @@ class AuthService {
|
|
|
272
272
|
}
|
|
273
273
|
});
|
|
274
274
|
this.signUpOrLogIn = (params) => __async(this, null, function* () {
|
|
275
|
-
__privateGet(this, _stateManager).
|
|
275
|
+
yield __privateGet(this, _stateManager).sendWhenAccepted({
|
|
276
|
+
type: "AUTHENTICATE_EMAIL_PHONE",
|
|
277
|
+
data: __spreadProps(__spreadValues({}, params), { isLegacy: true })
|
|
278
|
+
});
|
|
276
279
|
return yield (0, import_stateListener.waitForAuthStateChange)({
|
|
277
280
|
stateManager: __privateGet(this, _stateManager),
|
|
278
281
|
resolvePhases: [
|
|
@@ -285,7 +288,10 @@ class AuthService {
|
|
|
285
288
|
});
|
|
286
289
|
});
|
|
287
290
|
this.authenticateWithEmailOrPhone = (params) => __async(this, null, function* () {
|
|
288
|
-
__privateGet(this, _stateManager).
|
|
291
|
+
yield __privateGet(this, _stateManager).sendWhenAccepted({
|
|
292
|
+
type: "AUTHENTICATE_EMAIL_PHONE",
|
|
293
|
+
data: __spreadProps(__spreadValues({}, params), { isLegacy: false })
|
|
294
|
+
});
|
|
289
295
|
const authState = yield (0, import_stateListener.waitForAuthStateChange)({
|
|
290
296
|
stateManager: __privateGet(this, _stateManager),
|
|
291
297
|
resolvePhases: [
|
|
@@ -431,7 +437,7 @@ class AuthService {
|
|
|
431
437
|
return { authState: serverAuthState, opts: urlOptions };
|
|
432
438
|
});
|
|
433
439
|
this.loginExternalWallet = (params) => __async(this, null, function* () {
|
|
434
|
-
__privateGet(this, _stateManager).
|
|
440
|
+
yield __privateGet(this, _stateManager).sendWhenAccepted({ type: "AUTHENTICATE_EXTERNAL_WALLET", data: params });
|
|
435
441
|
return yield (0, import_stateListener.waitForAuthStateChange)({
|
|
436
442
|
stateManager: __privateGet(this, _stateManager),
|
|
437
443
|
resolvePhases: [
|
|
@@ -456,7 +462,7 @@ class AuthService {
|
|
|
456
462
|
});
|
|
457
463
|
});
|
|
458
464
|
this.connectExternalWallet = (params) => __async(this, null, function* () {
|
|
459
|
-
__privateGet(this, _stateManager).
|
|
465
|
+
yield __privateGet(this, _stateManager).sendWhenAccepted({ type: "CONNECT_EXTERNAL_WALLET", data: params });
|
|
460
466
|
return yield (0, import_stateListener.waitForAuthStateChange)({
|
|
461
467
|
stateManager: __privateGet(this, _stateManager),
|
|
462
468
|
resolvePhases: [
|
|
@@ -482,7 +488,7 @@ class AuthService {
|
|
|
482
488
|
});
|
|
483
489
|
});
|
|
484
490
|
this.verifyOAuthProcess = (params) => __async(this, null, function* () {
|
|
485
|
-
__privateGet(this, _stateManager).
|
|
491
|
+
yield __privateGet(this, _stateManager).sendWhenAccepted({
|
|
486
492
|
type: "AUTHENTICATE_OAUTH",
|
|
487
493
|
data: __spreadProps(__spreadValues({}, params), {
|
|
488
494
|
onCancel: params.onCancel,
|
|
@@ -538,7 +544,7 @@ class AuthService {
|
|
|
538
544
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
539
545
|
switch (params.method) {
|
|
540
546
|
case "TELEGRAM": {
|
|
541
|
-
__privateGet(this, _stateManager).
|
|
547
|
+
yield __privateGet(this, _stateManager).sendWhenAccepted({
|
|
542
548
|
type: "AUTHENTICATE_TELEGRAM",
|
|
543
549
|
data: __spreadProps(__spreadValues({}, params), {
|
|
544
550
|
method: params.method,
|
|
@@ -550,7 +556,7 @@ class AuthService {
|
|
|
550
556
|
break;
|
|
551
557
|
}
|
|
552
558
|
case "FARCASTER": {
|
|
553
|
-
__privateGet(this, _stateManager).
|
|
559
|
+
yield __privateGet(this, _stateManager).sendWhenAccepted({
|
|
554
560
|
type: "AUTHENTICATE_FARCASTER",
|
|
555
561
|
data: __spreadProps(__spreadValues({}, params), {
|
|
556
562
|
method: params.method,
|
|
@@ -562,7 +568,7 @@ class AuthService {
|
|
|
562
568
|
break;
|
|
563
569
|
}
|
|
564
570
|
default: {
|
|
565
|
-
__privateGet(this, _stateManager).
|
|
571
|
+
yield __privateGet(this, _stateManager).sendWhenAccepted({
|
|
566
572
|
type: "AUTHENTICATE_OAUTH",
|
|
567
573
|
data: __spreadProps(__spreadValues({}, params), {
|
|
568
574
|
method: params.method,
|
|
@@ -324,6 +324,7 @@ class PregenWalletService {
|
|
|
324
324
|
() => __async(this, null, function* () {
|
|
325
325
|
switch (walletType) {
|
|
326
326
|
case "STELLAR":
|
|
327
|
+
case "SUI":
|
|
327
328
|
case "SOLANA":
|
|
328
329
|
return __privateGet(this, _paraCoreInterface).platformUtils.ed25519PreKeygen(
|
|
329
330
|
__privateGet(this, _paraCoreInterface).ctx,
|
|
@@ -346,14 +347,14 @@ class PregenWalletService {
|
|
|
346
347
|
}),
|
|
347
348
|
{
|
|
348
349
|
"wallet.type": walletType,
|
|
349
|
-
"wallet.scheme": walletType === "SOLANA" || walletType === "STELLAR" ? "ED25519" : "DKLS"
|
|
350
|
+
"wallet.scheme": walletType === "SOLANA" || walletType === "STELLAR" || walletType === "SUI" ? "ED25519" : "DKLS"
|
|
350
351
|
}
|
|
351
352
|
);
|
|
352
353
|
const { signer, walletId } = keygenRes;
|
|
353
354
|
__privateGet(this, _walletService).wallets[walletId] = {
|
|
354
355
|
id: walletId,
|
|
355
356
|
signer,
|
|
356
|
-
scheme: walletType === "SOLANA" || walletType === "STELLAR" ? "ED25519" : "DKLS",
|
|
357
|
+
scheme: walletType === "SOLANA" || walletType === "STELLAR" || walletType === "SUI" ? "ED25519" : "DKLS",
|
|
357
358
|
type: walletType,
|
|
358
359
|
isPregen: true,
|
|
359
360
|
pregenIdentifier,
|
|
@@ -436,10 +437,16 @@ class PregenWalletService {
|
|
|
436
437
|
}
|
|
437
438
|
});
|
|
438
439
|
this.createGuestWallets = () => __async(this, null, function* () {
|
|
439
|
-
__privateGet(this, _stateManager).
|
|
440
|
+
const state = __privateGet(this, _stateManager).getSnapshot();
|
|
441
|
+
if (state.phase === "guest_mode") {
|
|
442
|
+
if (state.guestWallets) return state.guestWallets;
|
|
443
|
+
const guestWalletIds = new Set(this.guestWalletIdsArray.map(([id]) => id));
|
|
444
|
+
return [...guestWalletIds].map((id) => __privateGet(this, _walletService).wallets[id]);
|
|
445
|
+
}
|
|
446
|
+
yield __privateGet(this, _stateManager).sendWhenAccepted({ type: "INITIALIZE_GUEST_MODE" });
|
|
440
447
|
return yield (0, import_stateListener.waitForCoreStateChange)({
|
|
441
448
|
stateManager: __privateGet(this, _stateManager),
|
|
442
|
-
resolvePhases: [{ phase: "guest_mode", onPhase: (
|
|
449
|
+
resolvePhases: [{ phase: "guest_mode", onPhase: (state2) => state2.guestWallets }]
|
|
443
450
|
});
|
|
444
451
|
});
|
|
445
452
|
__privateSet(this, _paraCoreInterface, paraCore.getPregenWalletServiceInterface());
|
|
@@ -214,7 +214,7 @@ class VerificationFlowService extends import_BaseAuthFlowService.BaseAuthFlowSer
|
|
|
214
214
|
return { authState: serverAuthState, opts: urlOptions, sessionLookupId };
|
|
215
215
|
});
|
|
216
216
|
this.verifyTelegram = (params) => __async(this, null, function* () {
|
|
217
|
-
this.stateManager.
|
|
217
|
+
yield this.stateManager.sendWhenAccepted({ type: "AUTHENTICATE_TELEGRAM_LEGACY", data: params });
|
|
218
218
|
return yield (0, import_stateListener.waitForAuthStateChange)({
|
|
219
219
|
stateManager: this.stateManager,
|
|
220
220
|
resolvePhases: [
|
|
@@ -231,7 +231,7 @@ class VerificationFlowService extends import_BaseAuthFlowService.BaseAuthFlowSer
|
|
|
231
231
|
return { authState: serverAuthState, opts: urlOptions, sessionLookupId };
|
|
232
232
|
});
|
|
233
233
|
this.verifyFarcaster = (params) => __async(this, null, function* () {
|
|
234
|
-
this.stateManager.
|
|
234
|
+
yield this.stateManager.sendWhenAccepted({ type: "AUTHENTICATE_FARCASTER_LEGACY", data: params });
|
|
235
235
|
return yield (0, import_stateListener.waitForAuthStateChange)({
|
|
236
236
|
stateManager: this.stateManager,
|
|
237
237
|
resolvePhases: [
|
|
@@ -157,9 +157,13 @@ class WalletService {
|
|
|
157
157
|
this.getTypesToCreate = (types) => __async(this, null, function* () {
|
|
158
158
|
const { supportedWalletTypes } = yield __privateGet(this, _paraCoreInterface).assertPartner();
|
|
159
159
|
return (0, import_wallet2.getSchemes)(types != null ? types : yield __privateGet(this, _getMissingTypes).call(this)).map((scheme) => {
|
|
160
|
+
const requestedType = types == null ? void 0 : types.find((type) => import_wallet2.WalletSchemeTypeMap[scheme][type]);
|
|
161
|
+
if (requestedType) return requestedType;
|
|
160
162
|
switch (scheme) {
|
|
161
163
|
case "ED25519":
|
|
162
|
-
|
|
164
|
+
if (supportedWalletTypes.some(({ type, optional }) => type === "STELLAR" && !optional)) return "STELLAR";
|
|
165
|
+
if (supportedWalletTypes.some(({ type, optional }) => type === "SUI" && !optional)) return "SUI";
|
|
166
|
+
return "SOLANA";
|
|
163
167
|
default:
|
|
164
168
|
return supportedWalletTypes.some(({ type, optional }) => type === "COSMOS" && !optional) ? "COSMOS" : "EVM";
|
|
165
169
|
}
|
|
@@ -223,6 +227,7 @@ class WalletService {
|
|
|
223
227
|
() => __async(this, null, function* () {
|
|
224
228
|
switch (walletType) {
|
|
225
229
|
case "STELLAR":
|
|
230
|
+
case "SUI":
|
|
226
231
|
case "SOLANA":
|
|
227
232
|
return __privateGet(this, _paraCoreInterface).platformUtils.ed25519Keygen(
|
|
228
233
|
__privateGet(this, _paraCoreInterface).ctx,
|
|
@@ -244,11 +249,11 @@ class WalletService {
|
|
|
244
249
|
}),
|
|
245
250
|
{
|
|
246
251
|
"wallet.type": walletType,
|
|
247
|
-
"wallet.scheme": walletType === "SOLANA" || walletType === "STELLAR" ? "ED25519" : "DKLS"
|
|
252
|
+
"wallet.scheme": walletType === "SOLANA" || walletType === "STELLAR" || walletType === "SUI" ? "ED25519" : "DKLS"
|
|
248
253
|
}
|
|
249
254
|
);
|
|
250
255
|
const walletId = keygenRes.walletId;
|
|
251
|
-
const walletScheme = walletType === "SOLANA" || walletType === "STELLAR" ? "ED25519" : "DKLS";
|
|
256
|
+
const walletScheme = walletType === "SOLANA" || walletType === "STELLAR" || walletType === "SUI" ? "ED25519" : "DKLS";
|
|
252
257
|
signer = keygenRes.signer;
|
|
253
258
|
yield __privateGet(this, _pollingService).poll({
|
|
254
259
|
checkCondition: __privateGet(this, _pollingService).waitForWalletAddress({ walletId }),
|
|
@@ -400,6 +405,9 @@ class WalletService {
|
|
|
400
405
|
case "STELLAR":
|
|
401
406
|
str = wallet.publicKey ? (0, import_utils.getStellarAddress)(wallet.publicKey) : (0, import_utils.getStellarAddressFromSolana)(wallet.address);
|
|
402
407
|
break;
|
|
408
|
+
case "SUI":
|
|
409
|
+
str = wallet.publicKey ? (0, import_utils.getSuiAddress)(wallet.publicKey) : (0, import_utils.getSuiAddressFromSolana)(wallet.address);
|
|
410
|
+
break;
|
|
403
411
|
default:
|
|
404
412
|
prefix = __privateGet(this, _paraCoreInterface).cosmosPrefix;
|
|
405
413
|
str = wallet.address;
|
|
@@ -46,6 +46,7 @@ const _CoreStateManager = class _CoreStateManager {
|
|
|
46
46
|
this.currentAuthRefId = null;
|
|
47
47
|
this.currentWalletRefId = null;
|
|
48
48
|
this.lastNotifiedState = null;
|
|
49
|
+
this.pendingAuthSendCancels = /* @__PURE__ */ new Set();
|
|
49
50
|
const stateMachineInterface = paraCore.getStateMachineInterface();
|
|
50
51
|
this.devLog = stateMachineInterface.devLog;
|
|
51
52
|
const machine = (0, import_coreStateMachine.createCoreStateMachine)(stateMachineInterface);
|
|
@@ -82,6 +83,7 @@ const _CoreStateManager = class _CoreStateManager {
|
|
|
82
83
|
this.service.start();
|
|
83
84
|
}
|
|
84
85
|
stop() {
|
|
86
|
+
this.cancelPendingAuthSends("state manager stopped");
|
|
85
87
|
this.childSubscriptions.forEach((unsubscribe) => unsubscribe());
|
|
86
88
|
this.childSubscriptions.clear();
|
|
87
89
|
this.currentAuthRefId = null;
|
|
@@ -90,8 +92,70 @@ const _CoreStateManager = class _CoreStateManager {
|
|
|
90
92
|
this.service.stop();
|
|
91
93
|
}
|
|
92
94
|
send(event) {
|
|
95
|
+
if (event.type === "LOGOUT" || event.type === "CANCEL") {
|
|
96
|
+
this.cancelPendingAuthSends(event.type.toLowerCase());
|
|
97
|
+
}
|
|
93
98
|
this.service.send(event);
|
|
94
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Sends an auth-flow entry event once both the core and auth machines can
|
|
102
|
+
* accept it. Entry events wait only while initialization is moving toward an
|
|
103
|
+
* accepting state; stable or busy states reject immediately.
|
|
104
|
+
*/
|
|
105
|
+
sendWhenAccepted(event, timeoutMs = 3e5) {
|
|
106
|
+
return new Promise((resolve, reject) => {
|
|
107
|
+
let settled = false;
|
|
108
|
+
let timer;
|
|
109
|
+
let unsubscribe;
|
|
110
|
+
const settle = (error) => {
|
|
111
|
+
if (settled) return;
|
|
112
|
+
settled = true;
|
|
113
|
+
if (timer) clearTimeout(timer);
|
|
114
|
+
unsubscribe == null ? void 0 : unsubscribe();
|
|
115
|
+
this.pendingAuthSendCancels.delete(cancel);
|
|
116
|
+
if (error) reject(error);
|
|
117
|
+
else resolve();
|
|
118
|
+
};
|
|
119
|
+
const cancel = (reason) => settle(new Error(`${event.type} cancelled: ${reason}`));
|
|
120
|
+
const trySend = () => {
|
|
121
|
+
void Promise.resolve().then(() => {
|
|
122
|
+
if (settled) return;
|
|
123
|
+
try {
|
|
124
|
+
if (this.canAcceptAuthEvent(event)) {
|
|
125
|
+
this.service.send(event);
|
|
126
|
+
settle();
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const { phase, authStatePhase } = this.getSnapshot();
|
|
130
|
+
const waitable = _CoreStateManager.ENTRY_WAITABLE_CORE_PHASES.has(phase) || phase === "auth_flow" && _CoreStateManager.ENTRY_WAITABLE_AUTH_PHASES.has(authStatePhase);
|
|
131
|
+
if (!waitable) {
|
|
132
|
+
settle(
|
|
133
|
+
new Error(
|
|
134
|
+
`${event.type} not accepted: core phase '${phase}', auth phase '${authStatePhase}' cannot handle it`
|
|
135
|
+
)
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
} catch (error) {
|
|
139
|
+
settle(error instanceof Error ? error : new Error(String(error)));
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
timer = setTimeout(() => {
|
|
144
|
+
const { phase, authStatePhase } = this.getSnapshot();
|
|
145
|
+
settle(new Error(`Timed out waiting to send ${event.type}: core phase '${phase}', auth phase '${authStatePhase}'`));
|
|
146
|
+
}, timeoutMs);
|
|
147
|
+
this.pendingAuthSendCancels.add(cancel);
|
|
148
|
+
unsubscribe = this.onStateChange(trySend);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
cancelPendingAuthSends(reason) {
|
|
152
|
+
this.pendingAuthSendCancels.forEach((cancel) => cancel(reason));
|
|
153
|
+
}
|
|
154
|
+
canAcceptAuthEvent(event) {
|
|
155
|
+
const snapshot = this.service.getSnapshot();
|
|
156
|
+
const authRef = snapshot.context.authMachineRef;
|
|
157
|
+
return snapshot.can(event) && !!(authRef == null ? void 0 : authRef.getSnapshot().can(event));
|
|
158
|
+
}
|
|
95
159
|
getSnapshot() {
|
|
96
160
|
return this.mapXStateToCoreState(this.service.getSnapshot());
|
|
97
161
|
}
|
|
@@ -333,6 +397,12 @@ _CoreStateManager.CORE_LOADING_STATES = /* @__PURE__ */ new Set([
|
|
|
333
397
|
"waiting_for_external_wallet_providers",
|
|
334
398
|
"logging_out"
|
|
335
399
|
]);
|
|
400
|
+
_CoreStateManager.ENTRY_WAITABLE_CORE_PHASES = /* @__PURE__ */ new Set([
|
|
401
|
+
"setting_up",
|
|
402
|
+
"waiting_for_external_wallet_providers",
|
|
403
|
+
"logging_out"
|
|
404
|
+
]);
|
|
405
|
+
_CoreStateManager.ENTRY_WAITABLE_AUTH_PHASES = /* @__PURE__ */ new Set(["checking_state", "clearing_state"]);
|
|
336
406
|
_CoreStateManager.AUTH_LOADING_STATES = /* @__PURE__ */ new Set([
|
|
337
407
|
"authenticating_email_phone",
|
|
338
408
|
"authenticating_oauth",
|
|
@@ -33,6 +33,8 @@ __export(formatting_exports, {
|
|
|
33
33
|
getCosmosAddress: () => getCosmosAddress,
|
|
34
34
|
getStellarAddress: () => getStellarAddress,
|
|
35
35
|
getStellarAddressFromSolana: () => getStellarAddressFromSolana,
|
|
36
|
+
getSuiAddress: () => getSuiAddress,
|
|
37
|
+
getSuiAddressFromSolana: () => getSuiAddressFromSolana,
|
|
36
38
|
hexStringToBase64: () => hexStringToBase64,
|
|
37
39
|
hexToDecimal: () => hexToDecimal,
|
|
38
40
|
hexToSignature: () => hexToSignature,
|
|
@@ -44,6 +46,7 @@ module.exports = __toCommonJS(formatting_exports);
|
|
|
44
46
|
var import_encoding = require("@cosmjs/encoding");
|
|
45
47
|
var import_sha256 = require("@noble/hashes/sha256");
|
|
46
48
|
var import_ripemd160 = require("@noble/hashes/ripemd160");
|
|
49
|
+
var import_blake2b = require("@noble/hashes/blake2b");
|
|
47
50
|
var import_elliptic = __toESM(require("elliptic"));
|
|
48
51
|
const secp256k1 = new import_elliptic.default.ec("secp256k1");
|
|
49
52
|
function hexStringToBase64(hexString) {
|
|
@@ -183,6 +186,29 @@ function getStellarAddressFromSolana(solanaAddress) {
|
|
|
183
186
|
}
|
|
184
187
|
return encodeEd25519PublicKey(base58Decode(solanaAddress));
|
|
185
188
|
}
|
|
189
|
+
function suiAddressFromEd25519PublicKey(pubKeyBytes) {
|
|
190
|
+
if (pubKeyBytes.length !== 32) {
|
|
191
|
+
throw new Error(`Invalid Ed25519 public key length: expected 32 bytes, got ${pubKeyBytes.length}`);
|
|
192
|
+
}
|
|
193
|
+
const data = new Uint8Array(1 + pubKeyBytes.length);
|
|
194
|
+
data[0] = 0;
|
|
195
|
+
data.set(pubKeyBytes, 1);
|
|
196
|
+
const digest = (0, import_blake2b.blake2b)(data, { dkLen: 32 });
|
|
197
|
+
return "0x" + Buffer.from(digest).toString("hex");
|
|
198
|
+
}
|
|
199
|
+
function getSuiAddress(publicKey) {
|
|
200
|
+
if (!publicKey || publicKey.length === 0) {
|
|
201
|
+
return "";
|
|
202
|
+
}
|
|
203
|
+
const pubKeyBytes = Buffer.from(publicKey.startsWith("0x") ? publicKey.slice(2) : publicKey, "hex");
|
|
204
|
+
return suiAddressFromEd25519PublicKey(pubKeyBytes);
|
|
205
|
+
}
|
|
206
|
+
function getSuiAddressFromSolana(solanaAddress) {
|
|
207
|
+
if (!solanaAddress || solanaAddress.length === 0) {
|
|
208
|
+
return "";
|
|
209
|
+
}
|
|
210
|
+
return suiAddressFromEd25519PublicKey(base58Decode(solanaAddress));
|
|
211
|
+
}
|
|
186
212
|
function getCosmosAddress(publicKey, prefix) {
|
|
187
213
|
if (!publicKey || publicKey.length === 0) {
|
|
188
214
|
return "";
|
|
@@ -200,7 +226,7 @@ function truncateAddress(str, addressType, {
|
|
|
200
226
|
if (!str || str.length === 0) {
|
|
201
227
|
return "";
|
|
202
228
|
}
|
|
203
|
-
const minimum = addressType === "COSMOS" ? prefix.length : addressType === "EVM" ? 2 : 0;
|
|
229
|
+
const minimum = addressType === "COSMOS" ? prefix.length : addressType === "EVM" || addressType === "SUI" ? 2 : 0;
|
|
204
230
|
const margin = targetLength !== void 0 ? (targetLength - minimum) / 2 : 4;
|
|
205
231
|
return `${str.slice(0, minimum + margin)}...${str.slice(-1 * margin)}`;
|
|
206
232
|
}
|
|
@@ -212,6 +238,8 @@ function truncateAddress(str, addressType, {
|
|
|
212
238
|
getCosmosAddress,
|
|
213
239
|
getStellarAddress,
|
|
214
240
|
getStellarAddressFromSolana,
|
|
241
|
+
getSuiAddress,
|
|
242
|
+
getSuiAddressFromSolana,
|
|
215
243
|
hexStringToBase64,
|
|
216
244
|
hexToDecimal,
|
|
217
245
|
hexToSignature,
|
package/dist/cjs/utils/wallet.js
CHANGED
package/dist/esm/ParaCore.js
CHANGED
|
@@ -2843,6 +2843,7 @@ const _ParaCore = class _ParaCore {
|
|
|
2843
2843
|
**/
|
|
2844
2844
|
logout() {
|
|
2845
2845
|
return __async(this, arguments, function* ({ clearPregenWallets = false } = {}) {
|
|
2846
|
+
__privateGet(this, _stateManager).cancelPendingAuthSends("logout");
|
|
2846
2847
|
yield __privateMethod(this, _ParaCore_instances, logout_fn).call(this, { clearPregenWallets });
|
|
2847
2848
|
__privateGet(this, _pollingService).cancelAllPolling();
|
|
2848
2849
|
yield __privateGet(this, _externalWalletService).disconnectAllExternalWallets();
|
|
@@ -3111,7 +3112,7 @@ const _ParaCore = class _ParaCore {
|
|
|
3111
3112
|
return __async(this, arguments, function* ({ config, refetch = false } = {}) {
|
|
3112
3113
|
const { balance } = yield this.ctx.client.getProfileBalance({
|
|
3113
3114
|
config,
|
|
3114
|
-
wallets: this.availableWallets.filter(({ type }) => type !== "COSMOS" && type !== "STELLAR").map(({ type, address }) => ({ type, address })),
|
|
3115
|
+
wallets: this.availableWallets.filter(({ type }) => type !== "COSMOS" && type !== "STELLAR" && type !== "SUI").map(({ type, address }) => ({ type, address })),
|
|
3115
3116
|
refetch
|
|
3116
3117
|
});
|
|
3117
3118
|
return balance;
|
package/dist/esm/constants.js
CHANGED
|
@@ -203,7 +203,10 @@ class AuthService {
|
|
|
203
203
|
}
|
|
204
204
|
});
|
|
205
205
|
this.signUpOrLogIn = (params) => __async(this, null, function* () {
|
|
206
|
-
__privateGet(this, _stateManager).
|
|
206
|
+
yield __privateGet(this, _stateManager).sendWhenAccepted({
|
|
207
|
+
type: "AUTHENTICATE_EMAIL_PHONE",
|
|
208
|
+
data: __spreadProps(__spreadValues({}, params), { isLegacy: true })
|
|
209
|
+
});
|
|
207
210
|
return yield waitForAuthStateChange({
|
|
208
211
|
stateManager: __privateGet(this, _stateManager),
|
|
209
212
|
resolvePhases: [
|
|
@@ -216,7 +219,10 @@ class AuthService {
|
|
|
216
219
|
});
|
|
217
220
|
});
|
|
218
221
|
this.authenticateWithEmailOrPhone = (params) => __async(this, null, function* () {
|
|
219
|
-
__privateGet(this, _stateManager).
|
|
222
|
+
yield __privateGet(this, _stateManager).sendWhenAccepted({
|
|
223
|
+
type: "AUTHENTICATE_EMAIL_PHONE",
|
|
224
|
+
data: __spreadProps(__spreadValues({}, params), { isLegacy: false })
|
|
225
|
+
});
|
|
220
226
|
const authState = yield waitForAuthStateChange({
|
|
221
227
|
stateManager: __privateGet(this, _stateManager),
|
|
222
228
|
resolvePhases: [
|
|
@@ -362,7 +368,7 @@ class AuthService {
|
|
|
362
368
|
return { authState: serverAuthState, opts: urlOptions };
|
|
363
369
|
});
|
|
364
370
|
this.loginExternalWallet = (params) => __async(this, null, function* () {
|
|
365
|
-
__privateGet(this, _stateManager).
|
|
371
|
+
yield __privateGet(this, _stateManager).sendWhenAccepted({ type: "AUTHENTICATE_EXTERNAL_WALLET", data: params });
|
|
366
372
|
return yield waitForAuthStateChange({
|
|
367
373
|
stateManager: __privateGet(this, _stateManager),
|
|
368
374
|
resolvePhases: [
|
|
@@ -387,7 +393,7 @@ class AuthService {
|
|
|
387
393
|
});
|
|
388
394
|
});
|
|
389
395
|
this.connectExternalWallet = (params) => __async(this, null, function* () {
|
|
390
|
-
__privateGet(this, _stateManager).
|
|
396
|
+
yield __privateGet(this, _stateManager).sendWhenAccepted({ type: "CONNECT_EXTERNAL_WALLET", data: params });
|
|
391
397
|
return yield waitForAuthStateChange({
|
|
392
398
|
stateManager: __privateGet(this, _stateManager),
|
|
393
399
|
resolvePhases: [
|
|
@@ -413,7 +419,7 @@ class AuthService {
|
|
|
413
419
|
});
|
|
414
420
|
});
|
|
415
421
|
this.verifyOAuthProcess = (params) => __async(this, null, function* () {
|
|
416
|
-
__privateGet(this, _stateManager).
|
|
422
|
+
yield __privateGet(this, _stateManager).sendWhenAccepted({
|
|
417
423
|
type: "AUTHENTICATE_OAUTH",
|
|
418
424
|
data: __spreadProps(__spreadValues({}, params), {
|
|
419
425
|
onCancel: params.onCancel,
|
|
@@ -469,7 +475,7 @@ class AuthService {
|
|
|
469
475
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
470
476
|
switch (params.method) {
|
|
471
477
|
case "TELEGRAM": {
|
|
472
|
-
__privateGet(this, _stateManager).
|
|
478
|
+
yield __privateGet(this, _stateManager).sendWhenAccepted({
|
|
473
479
|
type: "AUTHENTICATE_TELEGRAM",
|
|
474
480
|
data: __spreadProps(__spreadValues({}, params), {
|
|
475
481
|
method: params.method,
|
|
@@ -481,7 +487,7 @@ class AuthService {
|
|
|
481
487
|
break;
|
|
482
488
|
}
|
|
483
489
|
case "FARCASTER": {
|
|
484
|
-
__privateGet(this, _stateManager).
|
|
490
|
+
yield __privateGet(this, _stateManager).sendWhenAccepted({
|
|
485
491
|
type: "AUTHENTICATE_FARCASTER",
|
|
486
492
|
data: __spreadProps(__spreadValues({}, params), {
|
|
487
493
|
method: params.method,
|
|
@@ -493,7 +499,7 @@ class AuthService {
|
|
|
493
499
|
break;
|
|
494
500
|
}
|
|
495
501
|
default: {
|
|
496
|
-
__privateGet(this, _stateManager).
|
|
502
|
+
yield __privateGet(this, _stateManager).sendWhenAccepted({
|
|
497
503
|
type: "AUTHENTICATE_OAUTH",
|
|
498
504
|
data: __spreadProps(__spreadValues({}, params), {
|
|
499
505
|
method: params.method,
|
|
@@ -276,6 +276,7 @@ class PregenWalletService {
|
|
|
276
276
|
() => __async(this, null, function* () {
|
|
277
277
|
switch (walletType) {
|
|
278
278
|
case "STELLAR":
|
|
279
|
+
case "SUI":
|
|
279
280
|
case "SOLANA":
|
|
280
281
|
return __privateGet(this, _paraCoreInterface).platformUtils.ed25519PreKeygen(
|
|
281
282
|
__privateGet(this, _paraCoreInterface).ctx,
|
|
@@ -298,14 +299,14 @@ class PregenWalletService {
|
|
|
298
299
|
}),
|
|
299
300
|
{
|
|
300
301
|
"wallet.type": walletType,
|
|
301
|
-
"wallet.scheme": walletType === "SOLANA" || walletType === "STELLAR" ? "ED25519" : "DKLS"
|
|
302
|
+
"wallet.scheme": walletType === "SOLANA" || walletType === "STELLAR" || walletType === "SUI" ? "ED25519" : "DKLS"
|
|
302
303
|
}
|
|
303
304
|
);
|
|
304
305
|
const { signer, walletId } = keygenRes;
|
|
305
306
|
__privateGet(this, _walletService).wallets[walletId] = {
|
|
306
307
|
id: walletId,
|
|
307
308
|
signer,
|
|
308
|
-
scheme: walletType === "SOLANA" || walletType === "STELLAR" ? "ED25519" : "DKLS",
|
|
309
|
+
scheme: walletType === "SOLANA" || walletType === "STELLAR" || walletType === "SUI" ? "ED25519" : "DKLS",
|
|
309
310
|
type: walletType,
|
|
310
311
|
isPregen: true,
|
|
311
312
|
pregenIdentifier,
|
|
@@ -388,10 +389,16 @@ class PregenWalletService {
|
|
|
388
389
|
}
|
|
389
390
|
});
|
|
390
391
|
this.createGuestWallets = () => __async(this, null, function* () {
|
|
391
|
-
__privateGet(this, _stateManager).
|
|
392
|
+
const state = __privateGet(this, _stateManager).getSnapshot();
|
|
393
|
+
if (state.phase === "guest_mode") {
|
|
394
|
+
if (state.guestWallets) return state.guestWallets;
|
|
395
|
+
const guestWalletIds = new Set(this.guestWalletIdsArray.map(([id]) => id));
|
|
396
|
+
return [...guestWalletIds].map((id) => __privateGet(this, _walletService).wallets[id]);
|
|
397
|
+
}
|
|
398
|
+
yield __privateGet(this, _stateManager).sendWhenAccepted({ type: "INITIALIZE_GUEST_MODE" });
|
|
392
399
|
return yield waitForCoreStateChange({
|
|
393
400
|
stateManager: __privateGet(this, _stateManager),
|
|
394
|
-
resolvePhases: [{ phase: "guest_mode", onPhase: (
|
|
401
|
+
resolvePhases: [{ phase: "guest_mode", onPhase: (state2) => state2.guestWallets }]
|
|
395
402
|
});
|
|
396
403
|
});
|
|
397
404
|
__privateSet(this, _paraCoreInterface, paraCore.getPregenWalletServiceInterface());
|
|
@@ -151,7 +151,7 @@ class VerificationFlowService extends BaseAuthFlowService {
|
|
|
151
151
|
return { authState: serverAuthState, opts: urlOptions, sessionLookupId };
|
|
152
152
|
});
|
|
153
153
|
this.verifyTelegram = (params) => __async(this, null, function* () {
|
|
154
|
-
this.stateManager.
|
|
154
|
+
yield this.stateManager.sendWhenAccepted({ type: "AUTHENTICATE_TELEGRAM_LEGACY", data: params });
|
|
155
155
|
return yield waitForAuthStateChange({
|
|
156
156
|
stateManager: this.stateManager,
|
|
157
157
|
resolvePhases: [
|
|
@@ -168,7 +168,7 @@ class VerificationFlowService extends BaseAuthFlowService {
|
|
|
168
168
|
return { authState: serverAuthState, opts: urlOptions, sessionLookupId };
|
|
169
169
|
});
|
|
170
170
|
this.verifyFarcaster = (params) => __async(this, null, function* () {
|
|
171
|
-
this.stateManager.
|
|
171
|
+
yield this.stateManager.sendWhenAccepted({ type: "AUTHENTICATE_FARCASTER_LEGACY", data: params });
|
|
172
172
|
return yield waitForAuthStateChange({
|
|
173
173
|
stateManager: this.stateManager,
|
|
174
174
|
resolvePhases: [
|
|
@@ -22,6 +22,8 @@ import {
|
|
|
22
22
|
getCosmosAddress,
|
|
23
23
|
getStellarAddress,
|
|
24
24
|
getStellarAddressFromSolana,
|
|
25
|
+
getSuiAddress,
|
|
26
|
+
getSuiAddressFromSolana,
|
|
25
27
|
truncateAddress
|
|
26
28
|
} from "../utils/index.js";
|
|
27
29
|
import { ParaEvent } from "../types/events.js";
|
|
@@ -101,9 +103,13 @@ class WalletService {
|
|
|
101
103
|
this.getTypesToCreate = (types) => __async(this, null, function* () {
|
|
102
104
|
const { supportedWalletTypes } = yield __privateGet(this, _paraCoreInterface).assertPartner();
|
|
103
105
|
return getSchemes(types != null ? types : yield __privateGet(this, _getMissingTypes).call(this)).map((scheme) => {
|
|
106
|
+
const requestedType = types == null ? void 0 : types.find((type) => WalletSchemeTypeMap[scheme][type]);
|
|
107
|
+
if (requestedType) return requestedType;
|
|
104
108
|
switch (scheme) {
|
|
105
109
|
case "ED25519":
|
|
106
|
-
|
|
110
|
+
if (supportedWalletTypes.some(({ type, optional }) => type === "STELLAR" && !optional)) return "STELLAR";
|
|
111
|
+
if (supportedWalletTypes.some(({ type, optional }) => type === "SUI" && !optional)) return "SUI";
|
|
112
|
+
return "SOLANA";
|
|
107
113
|
default:
|
|
108
114
|
return supportedWalletTypes.some(({ type, optional }) => type === "COSMOS" && !optional) ? "COSMOS" : "EVM";
|
|
109
115
|
}
|
|
@@ -167,6 +173,7 @@ class WalletService {
|
|
|
167
173
|
() => __async(this, null, function* () {
|
|
168
174
|
switch (walletType) {
|
|
169
175
|
case "STELLAR":
|
|
176
|
+
case "SUI":
|
|
170
177
|
case "SOLANA":
|
|
171
178
|
return __privateGet(this, _paraCoreInterface).platformUtils.ed25519Keygen(
|
|
172
179
|
__privateGet(this, _paraCoreInterface).ctx,
|
|
@@ -188,11 +195,11 @@ class WalletService {
|
|
|
188
195
|
}),
|
|
189
196
|
{
|
|
190
197
|
"wallet.type": walletType,
|
|
191
|
-
"wallet.scheme": walletType === "SOLANA" || walletType === "STELLAR" ? "ED25519" : "DKLS"
|
|
198
|
+
"wallet.scheme": walletType === "SOLANA" || walletType === "STELLAR" || walletType === "SUI" ? "ED25519" : "DKLS"
|
|
192
199
|
}
|
|
193
200
|
);
|
|
194
201
|
const walletId = keygenRes.walletId;
|
|
195
|
-
const walletScheme = walletType === "SOLANA" || walletType === "STELLAR" ? "ED25519" : "DKLS";
|
|
202
|
+
const walletScheme = walletType === "SOLANA" || walletType === "STELLAR" || walletType === "SUI" ? "ED25519" : "DKLS";
|
|
196
203
|
signer = keygenRes.signer;
|
|
197
204
|
yield __privateGet(this, _pollingService).poll({
|
|
198
205
|
checkCondition: __privateGet(this, _pollingService).waitForWalletAddress({ walletId }),
|
|
@@ -344,6 +351,9 @@ class WalletService {
|
|
|
344
351
|
case "STELLAR":
|
|
345
352
|
str = wallet.publicKey ? getStellarAddress(wallet.publicKey) : getStellarAddressFromSolana(wallet.address);
|
|
346
353
|
break;
|
|
354
|
+
case "SUI":
|
|
355
|
+
str = wallet.publicKey ? getSuiAddress(wallet.publicKey) : getSuiAddressFromSolana(wallet.address);
|
|
356
|
+
break;
|
|
347
357
|
default:
|
|
348
358
|
prefix = __privateGet(this, _paraCoreInterface).cosmosPrefix;
|
|
349
359
|
str = wallet.address;
|
|
@@ -11,6 +11,7 @@ const _CoreStateManager = class _CoreStateManager {
|
|
|
11
11
|
this.currentAuthRefId = null;
|
|
12
12
|
this.currentWalletRefId = null;
|
|
13
13
|
this.lastNotifiedState = null;
|
|
14
|
+
this.pendingAuthSendCancels = /* @__PURE__ */ new Set();
|
|
14
15
|
const stateMachineInterface = paraCore.getStateMachineInterface();
|
|
15
16
|
this.devLog = stateMachineInterface.devLog;
|
|
16
17
|
const machine = createCoreStateMachine(stateMachineInterface);
|
|
@@ -47,6 +48,7 @@ const _CoreStateManager = class _CoreStateManager {
|
|
|
47
48
|
this.service.start();
|
|
48
49
|
}
|
|
49
50
|
stop() {
|
|
51
|
+
this.cancelPendingAuthSends("state manager stopped");
|
|
50
52
|
this.childSubscriptions.forEach((unsubscribe) => unsubscribe());
|
|
51
53
|
this.childSubscriptions.clear();
|
|
52
54
|
this.currentAuthRefId = null;
|
|
@@ -55,8 +57,70 @@ const _CoreStateManager = class _CoreStateManager {
|
|
|
55
57
|
this.service.stop();
|
|
56
58
|
}
|
|
57
59
|
send(event) {
|
|
60
|
+
if (event.type === "LOGOUT" || event.type === "CANCEL") {
|
|
61
|
+
this.cancelPendingAuthSends(event.type.toLowerCase());
|
|
62
|
+
}
|
|
58
63
|
this.service.send(event);
|
|
59
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Sends an auth-flow entry event once both the core and auth machines can
|
|
67
|
+
* accept it. Entry events wait only while initialization is moving toward an
|
|
68
|
+
* accepting state; stable or busy states reject immediately.
|
|
69
|
+
*/
|
|
70
|
+
sendWhenAccepted(event, timeoutMs = 3e5) {
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
72
|
+
let settled = false;
|
|
73
|
+
let timer;
|
|
74
|
+
let unsubscribe;
|
|
75
|
+
const settle = (error) => {
|
|
76
|
+
if (settled) return;
|
|
77
|
+
settled = true;
|
|
78
|
+
if (timer) clearTimeout(timer);
|
|
79
|
+
unsubscribe == null ? void 0 : unsubscribe();
|
|
80
|
+
this.pendingAuthSendCancels.delete(cancel);
|
|
81
|
+
if (error) reject(error);
|
|
82
|
+
else resolve();
|
|
83
|
+
};
|
|
84
|
+
const cancel = (reason) => settle(new Error(`${event.type} cancelled: ${reason}`));
|
|
85
|
+
const trySend = () => {
|
|
86
|
+
void Promise.resolve().then(() => {
|
|
87
|
+
if (settled) return;
|
|
88
|
+
try {
|
|
89
|
+
if (this.canAcceptAuthEvent(event)) {
|
|
90
|
+
this.service.send(event);
|
|
91
|
+
settle();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const { phase, authStatePhase } = this.getSnapshot();
|
|
95
|
+
const waitable = _CoreStateManager.ENTRY_WAITABLE_CORE_PHASES.has(phase) || phase === "auth_flow" && _CoreStateManager.ENTRY_WAITABLE_AUTH_PHASES.has(authStatePhase);
|
|
96
|
+
if (!waitable) {
|
|
97
|
+
settle(
|
|
98
|
+
new Error(
|
|
99
|
+
`${event.type} not accepted: core phase '${phase}', auth phase '${authStatePhase}' cannot handle it`
|
|
100
|
+
)
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
} catch (error) {
|
|
104
|
+
settle(error instanceof Error ? error : new Error(String(error)));
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
timer = setTimeout(() => {
|
|
109
|
+
const { phase, authStatePhase } = this.getSnapshot();
|
|
110
|
+
settle(new Error(`Timed out waiting to send ${event.type}: core phase '${phase}', auth phase '${authStatePhase}'`));
|
|
111
|
+
}, timeoutMs);
|
|
112
|
+
this.pendingAuthSendCancels.add(cancel);
|
|
113
|
+
unsubscribe = this.onStateChange(trySend);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
cancelPendingAuthSends(reason) {
|
|
117
|
+
this.pendingAuthSendCancels.forEach((cancel) => cancel(reason));
|
|
118
|
+
}
|
|
119
|
+
canAcceptAuthEvent(event) {
|
|
120
|
+
const snapshot = this.service.getSnapshot();
|
|
121
|
+
const authRef = snapshot.context.authMachineRef;
|
|
122
|
+
return snapshot.can(event) && !!(authRef == null ? void 0 : authRef.getSnapshot().can(event));
|
|
123
|
+
}
|
|
60
124
|
getSnapshot() {
|
|
61
125
|
return this.mapXStateToCoreState(this.service.getSnapshot());
|
|
62
126
|
}
|
|
@@ -298,6 +362,12 @@ _CoreStateManager.CORE_LOADING_STATES = /* @__PURE__ */ new Set([
|
|
|
298
362
|
"waiting_for_external_wallet_providers",
|
|
299
363
|
"logging_out"
|
|
300
364
|
]);
|
|
365
|
+
_CoreStateManager.ENTRY_WAITABLE_CORE_PHASES = /* @__PURE__ */ new Set([
|
|
366
|
+
"setting_up",
|
|
367
|
+
"waiting_for_external_wallet_providers",
|
|
368
|
+
"logging_out"
|
|
369
|
+
]);
|
|
370
|
+
_CoreStateManager.ENTRY_WAITABLE_AUTH_PHASES = /* @__PURE__ */ new Set(["checking_state", "clearing_state"]);
|
|
301
371
|
_CoreStateManager.AUTH_LOADING_STATES = /* @__PURE__ */ new Set([
|
|
302
372
|
"authenticating_email_phone",
|
|
303
373
|
"authenticating_oauth",
|
|
@@ -2,6 +2,7 @@ import "../chunk-7B52C2XE.js";
|
|
|
2
2
|
import { toBech32 } from "@cosmjs/encoding";
|
|
3
3
|
import { sha256 } from "@noble/hashes/sha256";
|
|
4
4
|
import { ripemd160 } from "@noble/hashes/ripemd160";
|
|
5
|
+
import { blake2b } from "@noble/hashes/blake2b";
|
|
5
6
|
import elliptic from "elliptic";
|
|
6
7
|
const secp256k1 = new elliptic.ec("secp256k1");
|
|
7
8
|
function hexStringToBase64(hexString) {
|
|
@@ -141,6 +142,29 @@ function getStellarAddressFromSolana(solanaAddress) {
|
|
|
141
142
|
}
|
|
142
143
|
return encodeEd25519PublicKey(base58Decode(solanaAddress));
|
|
143
144
|
}
|
|
145
|
+
function suiAddressFromEd25519PublicKey(pubKeyBytes) {
|
|
146
|
+
if (pubKeyBytes.length !== 32) {
|
|
147
|
+
throw new Error(`Invalid Ed25519 public key length: expected 32 bytes, got ${pubKeyBytes.length}`);
|
|
148
|
+
}
|
|
149
|
+
const data = new Uint8Array(1 + pubKeyBytes.length);
|
|
150
|
+
data[0] = 0;
|
|
151
|
+
data.set(pubKeyBytes, 1);
|
|
152
|
+
const digest = blake2b(data, { dkLen: 32 });
|
|
153
|
+
return "0x" + Buffer.from(digest).toString("hex");
|
|
154
|
+
}
|
|
155
|
+
function getSuiAddress(publicKey) {
|
|
156
|
+
if (!publicKey || publicKey.length === 0) {
|
|
157
|
+
return "";
|
|
158
|
+
}
|
|
159
|
+
const pubKeyBytes = Buffer.from(publicKey.startsWith("0x") ? publicKey.slice(2) : publicKey, "hex");
|
|
160
|
+
return suiAddressFromEd25519PublicKey(pubKeyBytes);
|
|
161
|
+
}
|
|
162
|
+
function getSuiAddressFromSolana(solanaAddress) {
|
|
163
|
+
if (!solanaAddress || solanaAddress.length === 0) {
|
|
164
|
+
return "";
|
|
165
|
+
}
|
|
166
|
+
return suiAddressFromEd25519PublicKey(base58Decode(solanaAddress));
|
|
167
|
+
}
|
|
144
168
|
function getCosmosAddress(publicKey, prefix) {
|
|
145
169
|
if (!publicKey || publicKey.length === 0) {
|
|
146
170
|
return "";
|
|
@@ -158,7 +182,7 @@ function truncateAddress(str, addressType, {
|
|
|
158
182
|
if (!str || str.length === 0) {
|
|
159
183
|
return "";
|
|
160
184
|
}
|
|
161
|
-
const minimum = addressType === "COSMOS" ? prefix.length : addressType === "EVM" ? 2 : 0;
|
|
185
|
+
const minimum = addressType === "COSMOS" ? prefix.length : addressType === "EVM" || addressType === "SUI" ? 2 : 0;
|
|
162
186
|
const margin = targetLength !== void 0 ? (targetLength - minimum) / 2 : 4;
|
|
163
187
|
return `${str.slice(0, minimum + margin)}...${str.slice(-1 * margin)}`;
|
|
164
188
|
}
|
|
@@ -169,6 +193,8 @@ export {
|
|
|
169
193
|
getCosmosAddress,
|
|
170
194
|
getStellarAddress,
|
|
171
195
|
getStellarAddressFromSolana,
|
|
196
|
+
getSuiAddress,
|
|
197
|
+
getSuiAddressFromSolana,
|
|
172
198
|
hexStringToBase64,
|
|
173
199
|
hexToDecimal,
|
|
174
200
|
hexToSignature,
|
package/dist/esm/utils/wallet.js
CHANGED
|
@@ -10,12 +10,21 @@ export declare class CoreStateManager {
|
|
|
10
10
|
private currentWalletRefId;
|
|
11
11
|
private lastNotifiedState;
|
|
12
12
|
private devLog;
|
|
13
|
+
private pendingAuthSendCancels;
|
|
13
14
|
constructor(paraCore: ParaCore);
|
|
14
15
|
private subscribeToChildMachines;
|
|
15
16
|
private subscribeToChildRef;
|
|
16
17
|
start(): void;
|
|
17
18
|
stop(): void;
|
|
18
19
|
send(event: CoreEvents | AuthEvents | WalletEvents): void;
|
|
20
|
+
/**
|
|
21
|
+
* Sends an auth-flow entry event once both the core and auth machines can
|
|
22
|
+
* accept it. Entry events wait only while initialization is moving toward an
|
|
23
|
+
* accepting state; stable or busy states reject immediately.
|
|
24
|
+
*/
|
|
25
|
+
sendWhenAccepted(event: AuthEvents, timeoutMs?: number): Promise<void>;
|
|
26
|
+
cancelPendingAuthSends(reason: string): void;
|
|
27
|
+
private canAcceptAuthEvent;
|
|
19
28
|
getSnapshot(): CoreState;
|
|
20
29
|
onStateChange(listener: (state: CoreState) => void): () => void;
|
|
21
30
|
private getAuthMachineState;
|
|
@@ -27,6 +36,8 @@ export declare class CoreStateManager {
|
|
|
27
36
|
private computeAuthStateInfo;
|
|
28
37
|
private mapXStateToCoreState;
|
|
29
38
|
private static readonly CORE_LOADING_STATES;
|
|
39
|
+
private static readonly ENTRY_WAITABLE_CORE_PHASES;
|
|
40
|
+
private static readonly ENTRY_WAITABLE_AUTH_PHASES;
|
|
30
41
|
private static readonly AUTH_LOADING_STATES;
|
|
31
42
|
private static readonly WALLET_LOADING_STATES;
|
|
32
43
|
private isLoadingState;
|
|
@@ -15,6 +15,8 @@ export declare function compressPubkey(pubkey: Uint8Array): Uint8Array;
|
|
|
15
15
|
export declare function rawSecp256k1PubkeyToRawAddress(pubkeyData: Uint8Array): Uint8Array;
|
|
16
16
|
export declare function getStellarAddress(publicKey: string): string;
|
|
17
17
|
export declare function getStellarAddressFromSolana(solanaAddress: string): string;
|
|
18
|
+
export declare function getSuiAddress(publicKey: string): string;
|
|
19
|
+
export declare function getSuiAddressFromSolana(solanaAddress: string): string;
|
|
18
20
|
export declare function getCosmosAddress(publicKey: string, prefix: string): string;
|
|
19
21
|
export declare function truncateAddress(str: string, addressType: TWalletType, { prefix, targetLength, }?: {
|
|
20
22
|
prefix?: string;
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/core-sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.0",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@celo/utils": "^8.0.2",
|
|
6
6
|
"@cosmjs/encoding": "^0.32.4",
|
|
7
7
|
"@ethereumjs/util": "^9.1.0",
|
|
8
|
-
"@getpara/user-management-client": "3.
|
|
8
|
+
"@getpara/user-management-client": "3.9.0",
|
|
9
9
|
"@noble/hashes": "^1.5.0",
|
|
10
10
|
"@opentelemetry/api": "^1.9.1",
|
|
11
11
|
"@opentelemetry/context-zone": "^2.9.0",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"dist",
|
|
42
42
|
"package.json"
|
|
43
43
|
],
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "0ce96d513e4690451e371054e2e75bdcad379639",
|
|
45
45
|
"main": "dist/cjs/index.js",
|
|
46
46
|
"module": "dist/esm/index.js",
|
|
47
47
|
"scripts": {
|