@thru/wallet 0.2.25 → 0.2.28
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/README.md +1 -0
- package/dist/{BrowserSDK-CpRFiJsW.d.ts → BrowserSDK-CRQTOT8S.d.ts} +178 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +376 -12
- package/dist/index.js.map +1 -1
- package/dist/native/react/transparent.d.ts +104 -0
- package/dist/native/react/transparent.js +2210 -0
- package/dist/native/react/transparent.js.map +1 -0
- package/dist/native/react.d.ts +5 -90
- package/dist/native/react.js +765 -32
- package/dist/native/react.js.map +1 -1
- package/dist/native.d.ts +105 -1
- package/dist/native.js +521 -31
- package/dist/native.js.map +1 -1
- package/dist/react-ui.js +5 -0
- package/dist/react-ui.js.map +1 -1
- package/dist/react.d.ts +2 -2
- package/dist/react.js +376 -12
- package/dist/react.js.map +1 -1
- package/package.json +8 -2
- package/src/BrowserSDK.ts +32 -1
- package/src/encoding.ts +39 -0
- package/src/index.ts +5 -1
- package/src/interfaces/IThruChain.ts +50 -1
- package/src/interfaces/types.ts +52 -0
- package/src/native/NativeSDK.test.ts +200 -1
- package/src/native/NativeSDK.ts +124 -10
- package/src/native/index.ts +12 -0
- package/src/native/provider/NativeProvider.ts +106 -5
- package/src/native/provider/WebViewBridge.test.ts +22 -1
- package/src/native/provider/WebViewBridge.ts +17 -7
- package/src/native/provider/chains/ThruChain.ts +215 -5
- package/src/native/react/ThruContext.ts +3 -1
- package/src/native/react/ThruProvider.tsx +25 -0
- package/src/native/react/ThruTransparentWalletBridge.tsx +281 -0
- package/src/native/react/hooks/useWallet.ts +12 -1
- package/src/native/react/index.ts +11 -0
- package/src/native/react/transparent.ts +35 -0
- package/src/protocol/postMessage.ts +127 -2
- package/src/provider/EmbeddedProvider.ts +7 -1
- package/src/provider/IframeManager.test.ts +18 -0
- package/src/provider/IframeManager.ts +8 -1
- package/src/provider/chains/ThruChain.ts +210 -4
- package/src/provider/types/messages.ts +16 -0
- package/src/react/index.ts +6 -0
- package/src/signing-sessions.test.ts +182 -0
- package/src/signing-sessions.ts +204 -0
package/dist/native.d.ts
CHANGED
|
@@ -56,6 +56,34 @@ interface ThruTransactionReviewPayload {
|
|
|
56
56
|
simulation?: ThruTransactionReviewSimulation;
|
|
57
57
|
abiReflection?: ThruTransactionReviewAbiReflection;
|
|
58
58
|
}
|
|
59
|
+
type ThruSigningSessionTimestamp = Date | number | bigint | string;
|
|
60
|
+
interface ThruSigningSessionCreateOptions {
|
|
61
|
+
walletAddress?: string;
|
|
62
|
+
durationSeconds?: number;
|
|
63
|
+
expiresAt?: ThruSigningSessionTimestamp;
|
|
64
|
+
review?: ThruTransactionReviewPayload;
|
|
65
|
+
}
|
|
66
|
+
interface ThruSigningSessionInstructionCreateOptions extends Omit<ThruSigningSessionCreateOptions, "review"> {
|
|
67
|
+
walletAccountIdx: number;
|
|
68
|
+
}
|
|
69
|
+
interface ThruSigningSessionDescriptor {
|
|
70
|
+
id: string;
|
|
71
|
+
walletAddress: string;
|
|
72
|
+
publicKey: string;
|
|
73
|
+
authIdx: number;
|
|
74
|
+
expiresAt: number;
|
|
75
|
+
createdAt: number;
|
|
76
|
+
}
|
|
77
|
+
interface ThruSigningSession extends ThruSigningSessionDescriptor {
|
|
78
|
+
signTransaction(transaction: ThruTransactionIntent): Promise<string>;
|
|
79
|
+
revoke(): Promise<void>;
|
|
80
|
+
toJSON(): ThruSigningSessionDescriptor;
|
|
81
|
+
}
|
|
82
|
+
interface ThruSigningSessionInstruction {
|
|
83
|
+
session: ThruSigningSession;
|
|
84
|
+
programAddress: string;
|
|
85
|
+
instructionData: Uint8Array;
|
|
86
|
+
}
|
|
59
87
|
interface ThruTransactionIntent {
|
|
60
88
|
walletAddress?: string;
|
|
61
89
|
programAddress: string;
|
|
@@ -63,6 +91,19 @@ interface ThruTransactionIntent {
|
|
|
63
91
|
readWriteAddresses?: string[];
|
|
64
92
|
readOnlyAddresses?: string[];
|
|
65
93
|
review?: ThruTransactionReviewPayload;
|
|
94
|
+
/** @internal Used by ThruSigningSession handles. */
|
|
95
|
+
signingSessionId?: string;
|
|
96
|
+
}
|
|
97
|
+
interface ThruPasskeyChallengeIntent {
|
|
98
|
+
/** base64url-encoded passkey-manager challenge bytes. */
|
|
99
|
+
challenge: string;
|
|
100
|
+
walletAddress?: string;
|
|
101
|
+
}
|
|
102
|
+
interface ThruPasskeyChallengeSignature {
|
|
103
|
+
signatureR: string;
|
|
104
|
+
signatureS: string;
|
|
105
|
+
authenticatorData: string;
|
|
106
|
+
clientDataJSON: string;
|
|
66
107
|
}
|
|
67
108
|
interface SignMessageParams {
|
|
68
109
|
message: string | Uint8Array;
|
|
@@ -105,18 +146,51 @@ interface IThruChain {
|
|
|
105
146
|
* account ordering, headers, nonces, and final wire layout.
|
|
106
147
|
*/
|
|
107
148
|
signTransaction(transaction: ThruTransactionIntent): Promise<string>;
|
|
149
|
+
/**
|
|
150
|
+
* Sign a backend-prepared passkey-manager challenge with the wallet-owned
|
|
151
|
+
* selected passkey and return submit-ready signature fields.
|
|
152
|
+
*/
|
|
153
|
+
signPasskeyChallenge(challenge: ThruPasskeyChallengeIntent): Promise<ThruPasskeyChallengeSignature>;
|
|
154
|
+
/**
|
|
155
|
+
* Create a temporary wallet-owned signing session. The SDK stores the
|
|
156
|
+
* returned descriptor in app-local storage; the wallet stores the private key.
|
|
157
|
+
*/
|
|
158
|
+
createSigningSession(options: ThruSigningSessionCreateOptions): Promise<ThruSigningSession>;
|
|
159
|
+
/**
|
|
160
|
+
* Prepare a temporary signing-session authority instruction without asking
|
|
161
|
+
* for passkey approval. The returned instruction must be included in a
|
|
162
|
+
* later passkey-approved transaction before the session can sign.
|
|
163
|
+
*/
|
|
164
|
+
createSigningSessionInstruction(options: ThruSigningSessionInstructionCreateOptions): Promise<ThruSigningSessionInstruction>;
|
|
165
|
+
/**
|
|
166
|
+
* Confirm that a prepared signing-session instruction landed on-chain and
|
|
167
|
+
* publish the resulting session descriptor into SDK storage.
|
|
168
|
+
*/
|
|
169
|
+
confirmSigningSession(id: string): Promise<ThruSigningSession>;
|
|
170
|
+
/** Return a locally known signing session by id. */
|
|
171
|
+
getSigningSession(id: string): Promise<ThruSigningSession | null>;
|
|
172
|
+
/** Return locally known signing sessions for this SDK app scope only. */
|
|
173
|
+
getSigningSessions(): Promise<ThruSigningSession[]>;
|
|
174
|
+
/** Delete a locally known session and ask the wallet to delete its key. */
|
|
175
|
+
revokeSigningSession(id: string): Promise<void>;
|
|
108
176
|
}
|
|
109
177
|
|
|
110
178
|
declare const POST_MESSAGE_REQUEST_TYPES: {
|
|
111
179
|
readonly CONNECT: "connect";
|
|
180
|
+
readonly CREATE_ACCOUNT: "createAccount";
|
|
112
181
|
readonly DISCONNECT: "disconnect";
|
|
113
182
|
readonly SIGN_MESSAGE: "signMessage";
|
|
114
183
|
readonly SIGN_TRANSACTION: "signTransaction";
|
|
184
|
+
readonly SIGN_PASSKEY_CHALLENGE: "signPasskeyChallenge";
|
|
115
185
|
readonly GET_ACCOUNTS: "getAccounts";
|
|
116
186
|
readonly GET_CONNECTION_STATE: "getConnectionState";
|
|
117
187
|
readonly GET_SIGNING_CONTEXT: "getSigningContext";
|
|
118
188
|
readonly SELECT_ACCOUNT: "selectAccount";
|
|
119
189
|
readonly MANAGE_ACCOUNTS: "manageAccounts";
|
|
190
|
+
readonly CREATE_SIGNING_SESSION: "createSigningSession";
|
|
191
|
+
readonly CREATE_SIGNING_SESSION_INSTRUCTION: "createSigningSessionInstruction";
|
|
192
|
+
readonly CONFIRM_SIGNING_SESSION: "confirmSigningSession";
|
|
193
|
+
readonly REVOKE_SIGNING_SESSION: "revokeSigningSession";
|
|
120
194
|
};
|
|
121
195
|
declare const EMBEDDED_PROVIDER_EVENTS: {
|
|
122
196
|
readonly CONNECT_START: "connect_start";
|
|
@@ -128,6 +202,15 @@ declare const EMBEDDED_PROVIDER_EVENTS: {
|
|
|
128
202
|
readonly UI_SHOW: "ui_show";
|
|
129
203
|
readonly ACCOUNT_CHANGED: "account_changed";
|
|
130
204
|
};
|
|
205
|
+
interface CreateAccountResult {
|
|
206
|
+
account: WalletAccount;
|
|
207
|
+
accounts: WalletAccount[];
|
|
208
|
+
selectedAccount: WalletAccount;
|
|
209
|
+
signature: string | null;
|
|
210
|
+
vmError: string | null;
|
|
211
|
+
userErrorCode: string | null;
|
|
212
|
+
executionResult: string | null;
|
|
213
|
+
}
|
|
131
214
|
interface GetConnectionStateResult {
|
|
132
215
|
isAuthorized: boolean;
|
|
133
216
|
isConnected: boolean;
|
|
@@ -175,6 +258,7 @@ interface WebViewMessageEventLike {
|
|
|
175
258
|
}
|
|
176
259
|
|
|
177
260
|
type IosWebViewMode = "direct" | "shell-iframe";
|
|
261
|
+
type NativeWalletExperience = "standard" | "transparent";
|
|
178
262
|
type WalletAvailability = {
|
|
179
263
|
status: "checking";
|
|
180
264
|
isAuthorized: false;
|
|
@@ -211,9 +295,14 @@ type WalletAvailability = {
|
|
|
211
295
|
};
|
|
212
296
|
interface NativeSDKConfig {
|
|
213
297
|
walletUrl?: string;
|
|
298
|
+
/** Wallet presentation loaded in the native WebView. Transparent mode
|
|
299
|
+
signs in without opening the native wallet sheet. */
|
|
300
|
+
walletExperience?: NativeWalletExperience;
|
|
214
301
|
/** Stamped on every postMessage so wallet's ConnectedAppsStorage can
|
|
215
302
|
scope per-host. Default: 'thru-mobile://app'. */
|
|
216
303
|
origin?: string;
|
|
304
|
+
/** Default app metadata used for connection and transparent hydration. */
|
|
305
|
+
metadata?: ConnectMetadataInput;
|
|
217
306
|
rpcUrl?: string;
|
|
218
307
|
addressTypes?: AddressType[];
|
|
219
308
|
/** iOS-only host mode. Shell iframe is the default; direct is kept
|
|
@@ -226,6 +315,8 @@ interface NativeSDKConfig {
|
|
|
226
315
|
storageKey?: string;
|
|
227
316
|
/** Override the key used to remember the app-local selected account. */
|
|
228
317
|
selectedAccountStorageKey?: string;
|
|
318
|
+
/** Override the key used for app-local signing session descriptors. */
|
|
319
|
+
signingSessionStorageKey?: string;
|
|
229
320
|
}
|
|
230
321
|
interface SignInOptions {
|
|
231
322
|
app_id: string;
|
|
@@ -239,6 +330,10 @@ interface ConnectOptions {
|
|
|
239
330
|
preferredAccountAddress?: string;
|
|
240
331
|
intent?: ConnectRequestPayload["intent"];
|
|
241
332
|
}
|
|
333
|
+
interface CreateAccountOptions {
|
|
334
|
+
accountName?: string;
|
|
335
|
+
metadata?: ConnectMetadataInput;
|
|
336
|
+
}
|
|
242
337
|
interface RestoreConnectionOptions {
|
|
243
338
|
hydrate?: boolean;
|
|
244
339
|
}
|
|
@@ -273,6 +368,8 @@ declare class NativeSDK {
|
|
|
273
368
|
private readonly storageKey;
|
|
274
369
|
private readonly selectedAccountStorageKey;
|
|
275
370
|
private readonly iosWebViewMode;
|
|
371
|
+
private readonly walletExperience;
|
|
372
|
+
private readonly defaultMetadata?;
|
|
276
373
|
constructor(config?: NativeSDKConfig);
|
|
277
374
|
/** Hand the WebView ref to the underlying provider/bridge. */
|
|
278
375
|
attachWebView(ref: WebViewRefLike): void;
|
|
@@ -294,6 +391,7 @@ declare class NativeSDK {
|
|
|
294
391
|
initialize(): Promise<void>;
|
|
295
392
|
connect(options?: ConnectOptions): Promise<ConnectResult>;
|
|
296
393
|
signIn(options: SignInOptions): Promise<ConnectResult>;
|
|
394
|
+
createAccount(options?: CreateAccountOptions): Promise<CreateAccountResult>;
|
|
297
395
|
disconnect(): Promise<void>;
|
|
298
396
|
isConnected(): boolean;
|
|
299
397
|
getWalletAvailability(): WalletAvailability;
|
|
@@ -326,4 +424,10 @@ declare class NativeSDK {
|
|
|
326
424
|
private readSelectedAccountAddress;
|
|
327
425
|
}
|
|
328
426
|
|
|
329
|
-
|
|
427
|
+
interface SigningSessionStorage {
|
|
428
|
+
getItem: (key: string) => string | null | Promise<string | null>;
|
|
429
|
+
setItem: (key: string, value: string) => void | Promise<void>;
|
|
430
|
+
removeItem: (key: string) => void | Promise<void>;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
export { AddressType, type AppMetadata, type ConnectMetadataInput, type ConnectOptions, type ConnectResult, type CreateAccountOptions, type CreateAccountResult, EMBEDDED_PROVIDER_EVENTS, ErrorCode, type EventCallback, type GetConnectionStateResult, type IThruChain, type IosWebViewMode, type ManageAccountsResult, NativeSDK, type NativeSDKConfig, type NativeSDKStorage, type NativeSDKUiHandlers, type NativeWalletExperience, POST_MESSAGE_REQUEST_TYPES, type RestoreConnectionOptions, type SDKEvent, type SignInOptions, type SignMessageParams, type SignMessageResult, type SigningSessionStorage, type ThruPasskeyChallengeIntent, type ThruPasskeyChallengeSignature, type ThruSigningContext, type ThruSigningSession, type ThruSigningSessionCreateOptions, type ThruSigningSessionDescriptor, type ThruSigningSessionInstruction, type ThruSigningSessionInstructionCreateOptions, type ThruSigningSessionTimestamp, ThruTransactionEncoding, type ThruTransactionIntent, type WalletAccount, type WalletAvailability };
|