@thru/wallet 0.2.22

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.
Files changed (69) hide show
  1. package/README.md +67 -0
  2. package/android/build.gradle +37 -0
  3. package/android/src/main/AndroidManifest.xml +1 -0
  4. package/android/src/main/java/org/thru/walletnative/ThruWebViewBridgeModule.kt +77 -0
  5. package/app.plugin.cjs +101 -0
  6. package/dist/BrowserSDK-CpRFiJsW.d.ts +409 -0
  7. package/dist/index.d.ts +23 -0
  8. package/dist/index.js +941 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/native/react.d.ts +109 -0
  11. package/dist/native/react.js +2381 -0
  12. package/dist/native/react.js.map +1 -0
  13. package/dist/native.d.ts +329 -0
  14. package/dist/native.js +1126 -0
  15. package/dist/native.js.map +1 -0
  16. package/dist/react-ui.d.ts +5 -0
  17. package/dist/react-ui.js +266 -0
  18. package/dist/react-ui.js.map +1 -0
  19. package/dist/react.d.ts +66 -0
  20. package/dist/react.js +1151 -0
  21. package/dist/react.js.map +1 -0
  22. package/expo-module.config.json +6 -0
  23. package/package.json +114 -0
  24. package/src/BrowserSDK.ts +315 -0
  25. package/src/index.ts +27 -0
  26. package/src/interfaces/IThruChain.ts +37 -0
  27. package/src/interfaces/accounts.ts +61 -0
  28. package/src/interfaces/index.ts +9 -0
  29. package/src/interfaces/types.ts +95 -0
  30. package/src/native/NativeSDK.test.ts +819 -0
  31. package/src/native/NativeSDK.ts +773 -0
  32. package/src/native/index.ts +39 -0
  33. package/src/native/provider/NativeProvider.ts +363 -0
  34. package/src/native/provider/WebViewBridge.test.ts +339 -0
  35. package/src/native/provider/WebViewBridge.ts +339 -0
  36. package/src/native/provider/chains/ThruChain.ts +85 -0
  37. package/src/native/provider/shell.html +88 -0
  38. package/src/native/provider/shell.test.ts +56 -0
  39. package/src/native/provider/shell.ts +111 -0
  40. package/src/native/provider/shims-html.d.ts +4 -0
  41. package/src/native/react/ThruContext.ts +37 -0
  42. package/src/native/react/ThruProvider.tsx +168 -0
  43. package/src/native/react/ThruWalletSheet.tsx +1162 -0
  44. package/src/native/react/android-webauthn.ts +37 -0
  45. package/src/native/react/hooks/useAccounts.ts +35 -0
  46. package/src/native/react/hooks/useThru.ts +11 -0
  47. package/src/native/react/hooks/useWallet.ts +71 -0
  48. package/src/native/react/hooks/useWalletAvailability.ts +31 -0
  49. package/src/native/react/hooks/waitForWallet.ts +21 -0
  50. package/src/native/react/index.ts +29 -0
  51. package/src/protocol/index.ts +2 -0
  52. package/src/protocol/postMessage.ts +283 -0
  53. package/src/protocol/walletState.ts +12 -0
  54. package/src/provider/EmbeddedProvider.ts +330 -0
  55. package/src/provider/IframeManager.ts +438 -0
  56. package/src/provider/chains/ThruChain.ts +86 -0
  57. package/src/provider/index.ts +17 -0
  58. package/src/provider/types/messages.ts +37 -0
  59. package/src/react/ThruContext.ts +31 -0
  60. package/src/react/ThruProvider.tsx +169 -0
  61. package/src/react/hooks/useAccounts.ts +38 -0
  62. package/src/react/hooks/useThru.ts +11 -0
  63. package/src/react/hooks/useWallet.ts +81 -0
  64. package/src/react/index.ts +30 -0
  65. package/src/react-ui/ThruAccountSwitcher.tsx +187 -0
  66. package/src/react-ui/custom.d.ts +8 -0
  67. package/src/react-ui/index.ts +1 -0
  68. package/src/static/logo.png +0 -0
  69. package/src/static/logomark_red.svg +11 -0
package/src/index.ts ADDED
@@ -0,0 +1,27 @@
1
+ // Main exports
2
+ export {
3
+ BrowserSDK,
4
+ type BrowserSDKConfig, type ConnectOptions, type EventCallback, type SDKEvent
5
+ } from './BrowserSDK';
6
+
7
+ export type {
8
+ ConnectedApp, ConnectResult, IThruChain, SignMessageParams,
9
+ SignMessageResult, ThruSigningContext, ThruTransactionIntent, WalletAccount
10
+ } from './interfaces';
11
+ export {
12
+ AddressType,
13
+ normalizeActiveWalletAccounts,
14
+ normalizeWalletAccountResult,
15
+ resolveSelectedWalletAccount,
16
+ resolveWalletAccountByAddress,
17
+ ThruTransactionEncoding,
18
+ } from './interfaces';
19
+ export type {
20
+ ActiveWalletAccounts,
21
+ WalletAccountResult,
22
+ } from './interfaces';
23
+
24
+ export {
25
+ ErrorCode,
26
+ } from './protocol';
27
+ export * from './protocol';
@@ -0,0 +1,37 @@
1
+ import type { ThruSigningContext, ThruTransactionIntent } from "./types";
2
+
3
+ /**
4
+ * Minimal Thru chain interface exposed to SDK consumers.
5
+ * The concrete implementation will evolve as the Thru transaction
6
+ * flow is fleshed out, but maintaining a dedicated contract now
7
+ * keeps the Surface area aligned with other chain adapters.
8
+ */
9
+ export interface IThruChain {
10
+ /** Indicates whether the wallet has approved a Thru connection. */
11
+ readonly connected: boolean;
12
+
13
+ /**
14
+ * Initiate a Thru connection flow. Resolves with the connected address once
15
+ * the user has approved the request.
16
+ */
17
+ connect(): Promise<{ publicKey: string }>;
18
+
19
+ /** Disconnect the currently connected Thru account. */
20
+ disconnect(): Promise<void>;
21
+
22
+ /**
23
+ * Return the current embedded signing contract for Thru transactions.
24
+ *
25
+ * The selected account is the managed wallet account shown to the user.
26
+ * The fee payer / signer can differ when the wallet routes transactions
27
+ * through an embedded manager profile.
28
+ */
29
+ getSigningContext(): Promise<ThruSigningContext>;
30
+
31
+ /**
32
+ * Sign a wallet-managed transaction intent and return canonical raw
33
+ * transaction bytes encoded as base64. The wallet owns fee payer choice,
34
+ * account ordering, headers, nonces, and final wire layout.
35
+ */
36
+ signTransaction(transaction: ThruTransactionIntent): Promise<string>;
37
+ }
@@ -0,0 +1,61 @@
1
+ import type { WalletAccount } from "./types";
2
+
3
+ export interface ActiveWalletAccounts {
4
+ accounts: WalletAccount[];
5
+ selectedAccount: WalletAccount | null;
6
+ }
7
+
8
+ export type WalletAccountResult<T> = Omit<T, "accounts" | "selectedAccount"> & {
9
+ accounts: WalletAccount[];
10
+ selectedAccount: WalletAccount | null;
11
+ };
12
+
13
+ export function resolveSelectedWalletAccount(
14
+ accounts: WalletAccount[],
15
+ selectedAccount?: WalletAccount | null,
16
+ ): WalletAccount | null {
17
+ if (selectedAccount) {
18
+ return (
19
+ accounts.find((account) => account.address === selectedAccount.address) ??
20
+ selectedAccount
21
+ );
22
+ }
23
+
24
+ return accounts[0] ?? null;
25
+ }
26
+
27
+ export function resolveWalletAccountByAddress(
28
+ accounts: WalletAccount[],
29
+ address?: string | null,
30
+ ): WalletAccount | null {
31
+ if (!address) return null;
32
+ return accounts.find((account) => account.address === address) ?? null;
33
+ }
34
+
35
+ export function normalizeActiveWalletAccounts(
36
+ accounts: WalletAccount[],
37
+ selectedAccount?: WalletAccount | null,
38
+ ): ActiveWalletAccounts {
39
+ const activeAccount = resolveSelectedWalletAccount(accounts, selectedAccount);
40
+ return {
41
+ accounts: activeAccount ? [activeAccount] : [],
42
+ selectedAccount: activeAccount,
43
+ };
44
+ }
45
+
46
+ export function normalizeWalletAccountResult<
47
+ T extends { accounts: WalletAccount[]; selectedAccount?: WalletAccount | null },
48
+ >(
49
+ result: T,
50
+ selectedAccount?: WalletAccount | null,
51
+ ): WalletAccountResult<T> {
52
+ const active = normalizeActiveWalletAccounts(
53
+ result.accounts,
54
+ selectedAccount ?? result.selectedAccount ?? null,
55
+ );
56
+ return {
57
+ ...result,
58
+ accounts: active.accounts,
59
+ selectedAccount: active.selectedAccount,
60
+ };
61
+ }
@@ -0,0 +1,9 @@
1
+ export type { IThruChain } from './IThruChain';
2
+ export {
3
+ normalizeActiveWalletAccounts,
4
+ normalizeWalletAccountResult,
5
+ resolveSelectedWalletAccount,
6
+ resolveWalletAccountByAddress,
7
+ } from './accounts';
8
+ export type { ActiveWalletAccounts, WalletAccountResult } from './accounts';
9
+ export * from './types';
@@ -0,0 +1,95 @@
1
+ export const AddressType = {
2
+ THRU: "thru",
3
+ } as const;
4
+
5
+ export type AddressType = (typeof AddressType)[keyof typeof AddressType];
6
+
7
+ export interface WalletAccount {
8
+ accountType: AddressType;
9
+ address: string;
10
+ label: string;
11
+ }
12
+
13
+ export interface AppMetadata {
14
+ appId: string;
15
+ appName: string;
16
+ appUrl: string;
17
+ imageUrl?: string;
18
+ }
19
+
20
+ export interface ConnectResult {
21
+ walletId?: string;
22
+ accounts: WalletAccount[];
23
+ selectedAccount?: WalletAccount | null;
24
+ status?: "pending" | "completed";
25
+ metadata?: AppMetadata;
26
+ }
27
+
28
+ export const ThruTransactionEncoding = {
29
+ SIGNING_PAYLOAD_BASE64: "signing_payload_base64",
30
+ RAW_TRANSACTION_BASE64: "raw_transaction_base64",
31
+ } as const;
32
+
33
+ export type ThruTransactionEncoding =
34
+ (typeof ThruTransactionEncoding)[keyof typeof ThruTransactionEncoding];
35
+
36
+ export interface ThruSigningContext {
37
+ mode: "managed_fee_payer";
38
+ selectedAccountPublicKey: string | null;
39
+ feePayerPublicKey: string;
40
+ signerPublicKey: string;
41
+ acceptedInputEncodings: ThruTransactionEncoding[];
42
+ outputEncoding: typeof ThruTransactionEncoding.RAW_TRANSACTION_BASE64;
43
+ }
44
+
45
+ export interface ThruTransactionReviewSimulation {
46
+ before?: string;
47
+ after?: string;
48
+ }
49
+
50
+ export interface ThruTransactionReviewAbiReflection {
51
+ label?: string;
52
+ kind?: string | null;
53
+ typeName?: string;
54
+ value?: unknown;
55
+ rawHex?: string;
56
+ source?: string;
57
+ error?: string;
58
+ }
59
+
60
+ export interface ThruTransactionReviewPayload {
61
+ appName?: string;
62
+ programAddress?: string;
63
+ abiName?: string;
64
+ instruction?: string;
65
+ simulation?: ThruTransactionReviewSimulation;
66
+ abiReflection?: ThruTransactionReviewAbiReflection;
67
+ }
68
+
69
+ export interface ThruTransactionIntent {
70
+ walletAddress?: string;
71
+ programAddress: string;
72
+ instructionData: string;
73
+ readWriteAddresses?: string[];
74
+ readOnlyAddresses?: string[];
75
+ review?: ThruTransactionReviewPayload;
76
+ }
77
+
78
+ export interface ConnectedApp {
79
+ accountId: number;
80
+ appId: string;
81
+ origin: string;
82
+ metadata: AppMetadata;
83
+ connectedAt: number;
84
+ updatedAt: number;
85
+ }
86
+
87
+ export interface SignMessageParams {
88
+ message: string | Uint8Array;
89
+ networkId: string;
90
+ }
91
+
92
+ export interface SignMessageResult {
93
+ signature: Uint8Array;
94
+ publicKey: string;
95
+ }