@meshconnect/uwc-ton-connector 0.5.4 → 0.5.5-snapshot.16b2139
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/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/ton-connect-connector.d.ts +0 -1
- package/dist/ton-connect-connector.d.ts.map +1 -1
- package/dist/ton-connect-connector.js +39 -37
- package/dist/ton-connect-connector.js.map +1 -1
- package/dist/ton-connect-injected-restore.d.ts +50 -0
- package/dist/ton-connect-injected-restore.d.ts.map +1 -0
- package/dist/ton-connect-injected-restore.js +75 -0
- package/dist/ton-connect-injected-restore.js.map +1 -0
- package/dist/ton-connect-session-restore.d.ts +112 -0
- package/dist/ton-connect-session-restore.d.ts.map +1 -0
- package/dist/ton-connect-session-restore.js +202 -0
- package/dist/ton-connect-session-restore.js.map +1 -0
- package/package.json +3 -3
- package/src/index.ts +6 -0
- package/src/ton-connect-connector.test.ts +346 -7
- package/src/ton-connect-connector.ts +49 -52
- package/src/ton-connect-injected-restore.test.ts +340 -0
- package/src/ton-connect-injected-restore.ts +110 -0
- package/src/ton-connect-session-restore.test.ts +286 -0
- package/src/ton-connect-session-restore.ts +269 -0
package/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,6 @@ export { isValidBase64 } from './validation';
|
|
|
3
3
|
export { buildTonTransactionRequest, buildSignDataPayload, executeSignData, unwrapBoc, bocToHash, toFriendlyAddress } from './ton-transaction-utils';
|
|
4
4
|
export { buildJettonTransferPayload, buildTonNativeRequestFromJettonTransfer } from './jetton-transfer';
|
|
5
5
|
export { TonConnectConnector } from './ton-connect-connector';
|
|
6
|
+
export { clearStoredBridgeConnection } from './ton-connect-session-restore';
|
|
7
|
+
export { TON_CONNECT_INJECTED_STORAGE_PREFIX, readStoredInjectedConnection, tryRestoreInjectedSession } from './ton-connect-injected-restore';
|
|
6
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,EACpB,eAAe,EACf,SAAS,EACT,SAAS,EACT,iBAAiB,EAClB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EACL,0BAA0B,EAC1B,uCAAuC,EACxC,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,EACpB,eAAe,EACf,SAAS,EACT,SAAS,EACT,iBAAiB,EAClB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EACL,0BAA0B,EAC1B,uCAAuC,EACxC,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAA;AAC3E,OAAO,EACL,mCAAmC,EACnC,4BAA4B,EAC5B,yBAAyB,EAC1B,MAAM,gCAAgC,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -3,4 +3,6 @@ export { isValidBase64 } from './validation';
|
|
|
3
3
|
export { buildTonTransactionRequest, buildSignDataPayload, executeSignData, unwrapBoc, bocToHash, toFriendlyAddress } from './ton-transaction-utils';
|
|
4
4
|
export { buildJettonTransferPayload, buildTonNativeRequestFromJettonTransfer } from './jetton-transfer';
|
|
5
5
|
export { TonConnectConnector } from './ton-connect-connector';
|
|
6
|
+
export { clearStoredBridgeConnection } from './ton-connect-session-restore';
|
|
7
|
+
export { TON_CONNECT_INJECTED_STORAGE_PREFIX, readStoredInjectedConnection, tryRestoreInjectedSession } from './ton-connect-injected-restore';
|
|
6
8
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,EACpB,eAAe,EACf,SAAS,EACT,SAAS,EACT,iBAAiB,EAClB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EACL,0BAA0B,EAC1B,uCAAuC,EACxC,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,EACpB,eAAe,EACf,SAAS,EACT,SAAS,EACT,iBAAiB,EAClB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EACL,0BAA0B,EAC1B,uCAAuC,EACxC,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAA;AAC3E,OAAO,EACL,mCAAmC,EACnC,4BAA4B,EAC5B,yBAAyB,EAC1B,MAAM,gCAAgC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ton-connect-connector.d.ts","sourceRoot":"","sources":["../src/ton-connect-connector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,SAAS,EACT,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,wBAAwB,EAExB,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,
|
|
1
|
+
{"version":3,"file":"ton-connect-connector.d.ts","sourceRoot":"","sources":["../src/ton-connect-connector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,SAAS,EACT,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,wBAAwB,EAExB,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EAEd,MAAM,wBAAwB,CAAA;AAgC/B,qBAAa,mBAAoB,YAAW,SAAS;IACnD,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,GAAG,CAA2B;IACtC,OAAO,CAAC,aAAa,CAAoB;IACzC,OAAO,CAAC,gBAAgB,CAAsB;IAC9C,OAAO,CAAC,kBAAkB,CAAyB;IACnD,OAAO,CAAC,cAAc,CAA6C;IACnE,OAAO,CAAC,uBAAuB,CAEhB;IACf,OAAO,CAAC,qBAAqB,CAAiD;IAC9E,OAAO,CAAC,eAAe,CAAQ;IAC/B,OAAO,CAAC,mBAAmB,CAA4B;IACvD,OAAO,CAAC,qBAAqB,CAAwC;IACrE,OAAO,CAAC,iBAAiB,CAAI;gBAEjB,MAAM,EAAE,gBAAgB;IAIpC,oEAAoE;IAC9D,OAAO,CACX,OAAO,EAAE,OAAO,EAChB,QAAQ,CAAC,EAAE,wBAAwB,GAClC,OAAO,CAAC,eAAe,CAAC;YA6Bb,cAAc;IAqG5B,sEAAsE;IACtE,gBAAgB,IAAI,MAAM;IAO1B,iDAAiD;IAC3C,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAsB1D,uDAAuD;IACjD,eAAe,CACnB,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,iBAAiB,CAAC;IA2B7B,qEAAqE;IAC/D,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAOnE,yDAAyD;IACnD,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAmBjC,4DAA4D;IACtD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;YAIhB,qBAAqB;IAuEnC,OAAO,CAAC,sBAAsB;YAWhB,UAAU;IAWxB,OAAO,CAAC,mBAAmB;CAM5B"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { WalletConnectorError } from '@meshconnect/uwc-types';
|
|
2
2
|
import { NamespacedStorage } from './namespaced-storage';
|
|
3
|
-
import { buildTonTransactionRequest, buildSignDataPayload, executeSignData, unwrapBoc, bocToHash
|
|
3
|
+
import { buildTonTransactionRequest, buildSignDataPayload, executeSignData, unwrapBoc, bocToHash } from './ton-transaction-utils';
|
|
4
|
+
import { TON_CONNECT_STORAGE_PREFIX, buildConnectorResult, tryRestoreSession } from './ton-connect-session-restore';
|
|
4
5
|
// 5 minutes matches WalletConnect's proposal expiry. The TonConnect protocol
|
|
5
6
|
// has no built-in timeout — without this, a pending connect hangs indefinitely.
|
|
6
7
|
const CONNECT_TIMEOUT_MS = 5 * 60 * 1000;
|
|
@@ -53,7 +54,7 @@ export class TonConnectConnector {
|
|
|
53
54
|
? this.config.manifestUrl()
|
|
54
55
|
: this.config.manifestUrl;
|
|
55
56
|
const sdkOptions = {
|
|
56
|
-
storage: new NamespacedStorage(
|
|
57
|
+
storage: new NamespacedStorage(TON_CONNECT_STORAGE_PREFIX),
|
|
57
58
|
manifestUrl: resolvedManifestUrl,
|
|
58
59
|
analytics: { mode: 'off' }
|
|
59
60
|
};
|
|
@@ -61,45 +62,51 @@ export class TonConnectConnector {
|
|
|
61
62
|
sdkOptions.walletsListSource = this.config.walletsListSource;
|
|
62
63
|
}
|
|
63
64
|
this.sdk = new TonConnect(sdkOptions);
|
|
64
|
-
// ONC-2717: The SDK supports restoreConnection() to resume a previous
|
|
65
|
-
// session from NamespacedStorage without a new QR scan. Currently we
|
|
66
|
-
// always start fresh (disconnect stale sessions below). Adding session
|
|
67
|
-
// resumption would let users stay connected across page reloads —
|
|
68
|
-
// call sdk.restoreConnection() here and skip the QR flow if it succeeds.
|
|
69
|
-
if (this.sdk.connected) {
|
|
70
|
-
// Can't reuse: the SDK binds one provider (JS or HTTP bridge) per instance.
|
|
71
|
-
// A stale HTTP session from a previous wallet would corrupt the new one.
|
|
72
|
-
try {
|
|
73
|
-
await this.sdk.disconnect();
|
|
74
|
-
}
|
|
75
|
-
catch {
|
|
76
|
-
/* best effort — clear stale session from NamespacedStorage */
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
65
|
const sdkRef = this.sdk;
|
|
66
|
+
// Outer connect() validates this is non-empty; narrow for the rest of executeConnect.
|
|
67
|
+
const walletAppName = provider.walletListAppName;
|
|
68
|
+
if (!walletAppName) {
|
|
69
|
+
throw new Error('TonConnectWalletProvider.walletListAppName is required');
|
|
70
|
+
}
|
|
71
|
+
const restored = await tryRestoreSession({
|
|
72
|
+
network,
|
|
73
|
+
provider,
|
|
74
|
+
requestedAppName: walletAppName,
|
|
75
|
+
sdk: sdkRef,
|
|
76
|
+
generation
|
|
77
|
+
}, {
|
|
78
|
+
getCurrentGeneration: () => this.connectGeneration,
|
|
79
|
+
setAbortHook: fn => {
|
|
80
|
+
this.abortPendingConnect = fn;
|
|
81
|
+
},
|
|
82
|
+
toUserFriendlyAddressFn: this.toUserFriendlyAddressFn,
|
|
83
|
+
...(this.config.onSessionRestored
|
|
84
|
+
? { onSessionRestored: this.config.onSessionRestored }
|
|
85
|
+
: {})
|
|
86
|
+
});
|
|
87
|
+
if (restored) {
|
|
88
|
+
this.connectedAddress = restored.address;
|
|
89
|
+
this.connectedNetworkId = network.id;
|
|
90
|
+
return restored;
|
|
91
|
+
}
|
|
80
92
|
// Resolve bridge URLs from the SDK's wallet list (built-in or custom walletsListSource)
|
|
81
93
|
const wallets = await sdkRef.getWallets();
|
|
82
94
|
const remoteWallets = wallets.filter((w) => 'bridgeUrl' in w && 'universalLink' in w);
|
|
83
|
-
const walletInfo = remoteWallets.find(w => w.appName ===
|
|
95
|
+
const walletInfo = remoteWallets.find(w => w.appName === walletAppName);
|
|
84
96
|
if (!walletInfo) {
|
|
85
|
-
throw new Error(`Wallet '${
|
|
97
|
+
throw new Error(`Wallet '${walletAppName}' not found in TonConnect wallet list, or missing bridge/universalLink`);
|
|
86
98
|
}
|
|
87
99
|
const walletResult = await this.waitForWalletApproval(sdkRef, walletInfo.universalLink, walletInfo.bridgeUrl);
|
|
88
100
|
this.connectionURI = undefined; // URI consumed — clear before notify fires
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
101
|
+
const result = buildConnectorResult({
|
|
102
|
+
account: walletResult,
|
|
103
|
+
network,
|
|
104
|
+
provider,
|
|
105
|
+
toUserFriendlyAddressFn: this.toUserFriendlyAddressFn
|
|
106
|
+
});
|
|
107
|
+
this.connectedAddress = result.address;
|
|
93
108
|
this.connectedNetworkId = network.id;
|
|
94
|
-
|
|
95
|
-
return {
|
|
96
|
-
networkId: network.id,
|
|
97
|
-
address: friendlyAddress,
|
|
98
|
-
...(walletResult.publicKey
|
|
99
|
-
? { publicKey: walletResult.publicKey }
|
|
100
|
-
: {}),
|
|
101
|
-
availableAddresses
|
|
102
|
-
};
|
|
109
|
+
return result;
|
|
103
110
|
}
|
|
104
111
|
finally {
|
|
105
112
|
if (this.connectGeneration === generation) {
|
|
@@ -277,10 +284,5 @@ export class TonConnectConnector {
|
|
|
277
284
|
this.connectTimeout = null;
|
|
278
285
|
}
|
|
279
286
|
}
|
|
280
|
-
buildAvailableAddresses(supportedNetworkIds, address) {
|
|
281
|
-
return supportedNetworkIds
|
|
282
|
-
.filter(id => id.startsWith('tvm:'))
|
|
283
|
-
.map(networkId => ({ address, networkId: networkId }));
|
|
284
|
-
}
|
|
285
287
|
}
|
|
286
288
|
//# sourceMappingURL=ton-connect-connector.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ton-connect-connector.js","sourceRoot":"","sources":["../src/ton-connect-connector.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ton-connect-connector.js","sourceRoot":"","sources":["../src/ton-connect-connector.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAM7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,EACpB,eAAe,EACf,SAAS,EACT,SAAS,EACV,MAAM,yBAAyB,CAAA;AAChC,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,EACpB,iBAAiB,EAClB,MAAM,+BAA+B,CAAA;AAEtC,6EAA6E;AAC7E,gFAAgF;AAChF,MAAM,kBAAkB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAA;AASxC,MAAM,OAAO,mBAAmB;IACtB,MAAM,CAAkB;IACxB,GAAG,GAAuB,IAAI,CAAA;IAC9B,aAAa,CAAoB;IACjC,gBAAgB,GAAkB,IAAI,CAAA;IACtC,kBAAkB,GAAqB,IAAI,CAAA;IAC3C,cAAc,GAAyC,IAAI,CAAA;IAC3D,uBAAuB,GAEpB,IAAI,CAAA;IACP,qBAAqB,GAA6C,IAAI,CAAA;IACtE,eAAe,GAAG,KAAK,CAAA;IACvB,mBAAmB,GAAwB,IAAI,CAAA;IAC/C,qBAAqB,GAAoC,IAAI,CAAA;IAC7D,iBAAiB,GAAG,CAAC,CAAA;IAE7B,YAAY,MAAwB;QAClC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED,oEAAoE;IACpE,KAAK,CAAC,OAAO,CACX,OAAgB,EAChB,QAAmC;QAEnC,IAAI,CAAC,QAAQ,EAAE,CAAC;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AAM,GAAG,CAAC,EAAE,CAAC;gBACrB,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;YAChC,CAAC;QACH,CAAC;QACD,OAAO,SAAS,CAAA;IAClB,CAAC;IAEO,KAAK,CAAC,UAAU,CAAC,GAAgB;QACvC,IAAI,CAAC;YACH,MAAM,GAAG,CAAC,UAAU,EAAE,CAAA;QACxB,CAAC;QAAC,MAAM,CAAC;YACP,iBAAiB;QACnB,CAAC;QACD,IAAI,IAAI,CAAC,GAAG,KAAK,GAAG,EAAE,CAAC;YACrB,IAAI,CAAC,GAAG,GAAG,IAAI,CAAA;QACjB,CAAC;IACH,CAAC;IAEO,mBAAmB;QACzB,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;YACjC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAA;QAC5B,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ITonConnect } from '@tonconnect/sdk';
|
|
2
|
+
/**
|
|
3
|
+
* Pure helpers + free orchestrator that back `TonWalletService`'s restore
|
|
4
|
+
* preflight for the injected (JS Bridge) TON path — ONC-2717 phase 2.
|
|
5
|
+
* Mirrors the HTTP-bridge path in `ton-connect-session-restore.ts` and
|
|
6
|
+
* shares its account-extraction primitive. Lives in `@meshconnect/uwc-ton-connector`
|
|
7
|
+
* because the storage contract and SDK shape are the same on both sides;
|
|
8
|
+
* the only differences are the storage prefix and the match criterion.
|
|
9
|
+
*/
|
|
10
|
+
export declare const TON_CONNECT_INJECTED_STORAGE_PREFIX = "uwc-ton-injected";
|
|
11
|
+
/**
|
|
12
|
+
* Read the SDK's stored injected-connection blob and surface the wallet's
|
|
13
|
+
* `jsBridgeKey` if present. Returns null for empty, malformed, or non-injected
|
|
14
|
+
* entries — caller falls through to the fresh-connect path.
|
|
15
|
+
*/
|
|
16
|
+
export declare function readStoredInjectedConnection(): Promise<{
|
|
17
|
+
jsBridgeKey: string;
|
|
18
|
+
} | null>;
|
|
19
|
+
export interface TryRestoreInjectedSessionArgs {
|
|
20
|
+
requestedJsBridgeKey: string;
|
|
21
|
+
sdk: ITonConnect;
|
|
22
|
+
generation: number;
|
|
23
|
+
}
|
|
24
|
+
export interface TryRestoreInjectedSessionDeps {
|
|
25
|
+
/** Current connectGeneration for cancellation detection. */
|
|
26
|
+
getCurrentGeneration: () => number;
|
|
27
|
+
/** Register/clear the abort hook on the host (TonWalletService). */
|
|
28
|
+
setAbortHook: (fn: (() => void) | null) => void;
|
|
29
|
+
/** SDK's `toUserFriendlyAddress`, captured by the host after dynamic import. */
|
|
30
|
+
toUserFriendlyAddressFn: ((hex: string, testOnly?: boolean) => string) | null;
|
|
31
|
+
/** Optional host telemetry callback fired exactly once on successful restore. */
|
|
32
|
+
onSessionRestored?: () => void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Try to resume an existing injected TON Connect session before falling back
|
|
36
|
+
* to a fresh JS-Bridge handshake. Returns `null` on any non-success path so
|
|
37
|
+
* the caller falls through cleanly; throws `'TON Connect connection was
|
|
38
|
+
* cancelled'` if `connectGeneration` changes mid-flight (caller must surface
|
|
39
|
+
* this as a rejection).
|
|
40
|
+
*
|
|
41
|
+
* The wallet (Tonkeeper, etc.) is the source of truth — it decides via its
|
|
42
|
+
* injected `restoreConnection` API whether to silently re-issue the connect
|
|
43
|
+
* event or drop the session. The SDK clears its own storage on failure
|
|
44
|
+
* (see `InjectedProvider.restoreConnection` in @tonconnect/sdk).
|
|
45
|
+
*/
|
|
46
|
+
export declare function tryRestoreInjectedSession(args: TryRestoreInjectedSessionArgs, deps: TryRestoreInjectedSessionDeps): Promise<{
|
|
47
|
+
address: string;
|
|
48
|
+
publicKey?: string;
|
|
49
|
+
} | null>;
|
|
50
|
+
//# sourceMappingURL=ton-connect-injected-restore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ton-connect-injected-restore.d.ts","sourceRoot":"","sources":["../src/ton-connect-injected-restore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AASlD;;;;;;;GAOG;AAIH,eAAO,MAAM,mCAAmC,qBAAqB,CAAA;AASrE;;;;GAIG;AACH,wBAAsB,4BAA4B,IAAI,OAAO,CAAC;IAC5D,WAAW,EAAE,MAAM,CAAA;CACpB,GAAG,IAAI,CAAC,CAcR;AAED,MAAM,WAAW,6BAA6B;IAC5C,oBAAoB,EAAE,MAAM,CAAA;IAC5B,GAAG,EAAE,WAAW,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,6BAA6B;IAC5C,4DAA4D;IAC5D,oBAAoB,EAAE,MAAM,MAAM,CAAA;IAClC,oEAAoE;IACpE,YAAY,EAAE,CAAC,EAAE,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,KAAK,IAAI,CAAA;IAC/C,gFAAgF;IAChF,uBAAuB,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,KAAK,MAAM,CAAC,GAAG,IAAI,CAAA;IAC7E,iFAAiF;IACjF,iBAAiB,CAAC,EAAE,MAAM,IAAI,CAAA;CAC/B;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,yBAAyB,CAC7C,IAAI,EAAE,6BAA6B,EACnC,IAAI,EAAE,6BAA6B,GAClC,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CAyBzD"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { NamespacedStorage } from './namespaced-storage';
|
|
2
|
+
import { toFriendlyAddress } from './ton-transaction-utils';
|
|
3
|
+
import { TON_CONNECT_BRIDGE_CONNECTION_KEY, awaitRestoredAccount, clearStoredBridgeConnection } from './ton-connect-session-restore';
|
|
4
|
+
/**
|
|
5
|
+
* Pure helpers + free orchestrator that back `TonWalletService`'s restore
|
|
6
|
+
* preflight for the injected (JS Bridge) TON path — ONC-2717 phase 2.
|
|
7
|
+
* Mirrors the HTTP-bridge path in `ton-connect-session-restore.ts` and
|
|
8
|
+
* shares its account-extraction primitive. Lives in `@meshconnect/uwc-ton-connector`
|
|
9
|
+
* because the storage contract and SDK shape are the same on both sides;
|
|
10
|
+
* the only differences are the storage prefix and the match criterion.
|
|
11
|
+
*/
|
|
12
|
+
// NamespacedStorage prefix used by the injected TON path. Kept in sync with
|
|
13
|
+
// the prefix passed at `injected-connector/src/services/ton/ton-wallet-service.ts`.
|
|
14
|
+
export const TON_CONNECT_INJECTED_STORAGE_PREFIX = 'uwc-ton-injected';
|
|
15
|
+
/**
|
|
16
|
+
* Read the SDK's stored injected-connection blob and surface the wallet's
|
|
17
|
+
* `jsBridgeKey` if present. Returns null for empty, malformed, or non-injected
|
|
18
|
+
* entries — caller falls through to the fresh-connect path.
|
|
19
|
+
*/
|
|
20
|
+
export async function readStoredInjectedConnection() {
|
|
21
|
+
try {
|
|
22
|
+
const storage = new NamespacedStorage(TON_CONNECT_INJECTED_STORAGE_PREFIX);
|
|
23
|
+
const raw = await storage.getItem(TON_CONNECT_BRIDGE_CONNECTION_KEY);
|
|
24
|
+
if (!raw)
|
|
25
|
+
return null;
|
|
26
|
+
const parsed = JSON.parse(raw);
|
|
27
|
+
if (parsed.type !== 'injected')
|
|
28
|
+
return null;
|
|
29
|
+
if (typeof parsed.jsBridgeKey !== 'string' || !parsed.jsBridgeKey) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return { jsBridgeKey: parsed.jsBridgeKey };
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Try to resume an existing injected TON Connect session before falling back
|
|
40
|
+
* to a fresh JS-Bridge handshake. Returns `null` on any non-success path so
|
|
41
|
+
* the caller falls through cleanly; throws `'TON Connect connection was
|
|
42
|
+
* cancelled'` if `connectGeneration` changes mid-flight (caller must surface
|
|
43
|
+
* this as a rejection).
|
|
44
|
+
*
|
|
45
|
+
* The wallet (Tonkeeper, etc.) is the source of truth — it decides via its
|
|
46
|
+
* injected `restoreConnection` API whether to silently re-issue the connect
|
|
47
|
+
* event or drop the session. The SDK clears its own storage on failure
|
|
48
|
+
* (see `InjectedProvider.restoreConnection` in @tonconnect/sdk).
|
|
49
|
+
*/
|
|
50
|
+
export async function tryRestoreInjectedSession(args, deps) {
|
|
51
|
+
const { requestedJsBridgeKey, sdk, generation } = args;
|
|
52
|
+
const stored = await readStoredInjectedConnection();
|
|
53
|
+
if (deps.getCurrentGeneration() !== generation) {
|
|
54
|
+
throw new Error('TON Connect connection was cancelled');
|
|
55
|
+
}
|
|
56
|
+
if (!stored)
|
|
57
|
+
return null;
|
|
58
|
+
// JS bridge keys are JS property names on `window` (e.g. `tonkeeper`) —
|
|
59
|
+
// case-sensitive by definition. A mismatch means a different wallet was
|
|
60
|
+
// last connected; wipe the stale session and fall through.
|
|
61
|
+
if (stored.jsBridgeKey !== requestedJsBridgeKey) {
|
|
62
|
+
await clearStoredBridgeConnection(TON_CONNECT_INJECTED_STORAGE_PREFIX);
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
return awaitRestoredAccount(sdk, deps, account => {
|
|
66
|
+
const friendlyAddress = deps.toUserFriendlyAddressFn
|
|
67
|
+
? toFriendlyAddress(account.address, deps.toUserFriendlyAddressFn)
|
|
68
|
+
: account.address;
|
|
69
|
+
return {
|
|
70
|
+
address: friendlyAddress,
|
|
71
|
+
...(account.publicKey ? { publicKey: account.publicKey } : {})
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=ton-connect-injected-restore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ton-conn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D,IAAI,IAAI,CAAC,oBAAoB,EAAE,KAAK,UAAU,EAAE,CAAC;QAC/C,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAA;IACzD,CAAC;IACD,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IAExB,wEAAwE;IACxE,wEAAwE;IACxE,2DAA2D;IAC3D,IAAI,MAAM,CAAC,WAAW,KAAK,oBAAoB,EAAE,CAAC;QAChD,MAAM,2BAA2B,CAAC,mCAAmC,CAAC,CAAA;QACtE,OAAO,IAAI,CAAA;IACb,CAAC;IAED,OAAO,oBAAoB,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE;QAC/C,MAAM,eAAe,GAAG,IAAI,CAAC,uBAAuB;YAClD,CAAC,CAAC,iBAAiB,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,uBAAuB,CAAC;YAClE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAA;QACnB,OAAO;YACL,OAAO,EAAE,eAAe;YACxB,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC/D,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { AvailableAddress, ConnectorResult, Network, TonConnectWalletProvider } from '@meshconnect/uwc-types';
|
|
2
|
+
import type { ITonConnect } from '@tonconnect/sdk';
|
|
3
|
+
/**
|
|
4
|
+
* Pure helpers + free orchestrator that back `TonConnectConnector`'s
|
|
5
|
+
* restore preflight (ONC-2717). Split out of the connector so the storage
|
|
6
|
+
* read, wallet-shape guard, and result construction are independently
|
|
7
|
+
* testable and the connector class stays focused on the public `Connector`
|
|
8
|
+
* surface and the wallet lifecycle state it owns.
|
|
9
|
+
*/
|
|
10
|
+
export declare const TON_CONNECT_STORAGE_PREFIX = "uwc-ton-remote";
|
|
11
|
+
export declare const TON_CONNECT_BRIDGE_CONNECTION_KEY = "ton-connect-storage_bridge-connection";
|
|
12
|
+
/**
|
|
13
|
+
* Wipe the SDK's stored bridge-connection blob for the given prefix.
|
|
14
|
+
* Used by the restore preflight on appName/jsBridgeKey mismatch — calling
|
|
15
|
+
* `sdk.disconnect()` for that purpose is incorrect, because the SDK throws
|
|
16
|
+
* `WalletNotConnectedError` when `connected` is false (see ton-connect.ts
|
|
17
|
+
* `disconnect` at ~L867 of the @tonconnect/sdk source). The connector
|
|
18
|
+
* always invokes the preflight against a *freshly-instantiated* SDK whose
|
|
19
|
+
* `_wallet` is still null, so the throw would be swallowed and the stale
|
|
20
|
+
* blob would persist. Removing the storage entry directly is the
|
|
21
|
+
* equivalent of what the SDK would do via `BridgeConnectionStorage.removeConnection`
|
|
22
|
+
* had `disconnect()` been allowed to run.
|
|
23
|
+
*/
|
|
24
|
+
export declare function clearStoredBridgeConnection(prefix: string): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Read the SDK's stored bridge-connection blob and surface the wallet's
|
|
27
|
+
* appName if a usable HTTP session is present. Returns null for empty,
|
|
28
|
+
* malformed, pending (pre-handshake), or non-http entries — caller falls
|
|
29
|
+
* through to the fresh-connect path.
|
|
30
|
+
*/
|
|
31
|
+
export declare function readStoredConnection(): Promise<{
|
|
32
|
+
appName: string;
|
|
33
|
+
} | null>;
|
|
34
|
+
/**
|
|
35
|
+
* Validate and extract the wallet account fields we care about out of the
|
|
36
|
+
* unknown payload `@tonconnect/sdk`'s onStatusChange delivers. Returns null
|
|
37
|
+
* when the wallet is disconnected or the shape doesn't match.
|
|
38
|
+
*/
|
|
39
|
+
export declare function extractRestoredAccount(wallet: unknown): {
|
|
40
|
+
address: string;
|
|
41
|
+
publicKey?: string;
|
|
42
|
+
} | null;
|
|
43
|
+
/**
|
|
44
|
+
* Filter `supportedNetworkIds` to TVM-namespace entries and pair each
|
|
45
|
+
* with the friendly address. Pure transform shared by the fresh-connect
|
|
46
|
+
* and restore paths.
|
|
47
|
+
*/
|
|
48
|
+
export declare function buildAvailableAddresses(supportedNetworkIds: string[], address: string): AvailableAddress[];
|
|
49
|
+
/**
|
|
50
|
+
* Build the `ConnectorResult` returned by `TonConnectConnector.connect()`.
|
|
51
|
+
* Used by both the fresh-connect and restore paths. Pure — caller is
|
|
52
|
+
* responsible for any connector-state mutations (`connectedAddress` etc.).
|
|
53
|
+
*
|
|
54
|
+
* `toUserFriendlyAddressFn` is the SDK's `toUserFriendlyAddress` captured
|
|
55
|
+
* by the host after the dynamic SDK import. Pass `null` to fall through to
|
|
56
|
+
* the raw hex address (matches legacy fresh-path behaviour).
|
|
57
|
+
*/
|
|
58
|
+
export declare function buildConnectorResult(args: {
|
|
59
|
+
account: {
|
|
60
|
+
address: string;
|
|
61
|
+
publicKey?: string;
|
|
62
|
+
};
|
|
63
|
+
network: Network;
|
|
64
|
+
provider: TonConnectWalletProvider;
|
|
65
|
+
toUserFriendlyAddressFn: ((hex: string, testOnly?: boolean) => string) | null;
|
|
66
|
+
}): ConnectorResult;
|
|
67
|
+
export interface TryRestoreSessionArgs {
|
|
68
|
+
network: Network;
|
|
69
|
+
provider: TonConnectWalletProvider;
|
|
70
|
+
requestedAppName: string;
|
|
71
|
+
sdk: ITonConnect;
|
|
72
|
+
generation: number;
|
|
73
|
+
}
|
|
74
|
+
export interface TryRestoreSessionDeps {
|
|
75
|
+
/** Read-side: current connectGeneration for cancellation detection. */
|
|
76
|
+
getCurrentGeneration: () => number;
|
|
77
|
+
/** Write-side: register/clear the abort hook on the host (TonConnectConnector). */
|
|
78
|
+
setAbortHook: (fn: (() => void) | null) => void;
|
|
79
|
+
/** Optional host telemetry callback fired exactly once on successful restore. */
|
|
80
|
+
onSessionRestored?: () => void;
|
|
81
|
+
/** SDK's `toUserFriendlyAddress`, captured by the host after dynamic import. */
|
|
82
|
+
toUserFriendlyAddressFn: ((hex: string, testOnly?: boolean) => string) | null;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Shared async restore orchestrator. Subscribes to `onStatusChange`,
|
|
86
|
+
* registers a host-controlled abort hook, calls `sdk.restoreConnection()`,
|
|
87
|
+
* and resolves with `buildResult(account)` when the wallet emits a
|
|
88
|
+
* usable account — or `null` if `restoreConnection` settles without one.
|
|
89
|
+
* Rejects with the cancellation error if the abort hook fires first.
|
|
90
|
+
*
|
|
91
|
+
* Used by both `tryRestoreSession` (HTTP bridge) and
|
|
92
|
+
* `tryRestoreInjectedSession` (injected JS Bridge); the only thing
|
|
93
|
+
* that varies between them is the resolve-value shape, which is what
|
|
94
|
+
* `buildResult` builds.
|
|
95
|
+
*/
|
|
96
|
+
export declare function awaitRestoredAccount<T>(sdk: ITonConnect, deps: Pick<TryRestoreSessionDeps, 'setAbortHook' | 'onSessionRestored'>, buildResult: (account: {
|
|
97
|
+
address: string;
|
|
98
|
+
publicKey?: string;
|
|
99
|
+
}) => T): Promise<T | null>;
|
|
100
|
+
/**
|
|
101
|
+
* Try to resume an existing TON Connect session before falling back to a
|
|
102
|
+
* fresh QR/deeplink handshake. Returns `null` on any non-success path so
|
|
103
|
+
* the caller falls through cleanly; throws `'TON Connect connection was
|
|
104
|
+
* cancelled'` if `connectGeneration` changes mid-flight (caller must
|
|
105
|
+
* surface this as a rejection).
|
|
106
|
+
*
|
|
107
|
+
* Free function with a deps interface so the connector class doesn't have
|
|
108
|
+
* to host the orchestration logic. Cancellation via the `setAbortHook`
|
|
109
|
+
* dependency mirrors the connector's `waitForWalletApproval` pattern.
|
|
110
|
+
*/
|
|
111
|
+
export declare function tryRestoreSession(args: TryRestoreSessionArgs, deps: TryRestoreSessionDeps): Promise<ConnectorResult | null>;
|
|
112
|
+
//# sourceMappingURL=ton-connect-session-restore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ton-connect-session-restore.d.ts","sourceRoot":"","sources":["../src/ton-connect-session-restore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAg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