@authon/react-native-wallet 0.0.0-stage → 0.1.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.
Files changed (159) hide show
  1. package/README.md +221 -2
  2. package/android/build.gradle +40 -0
  3. package/android/consumer-rules.pro +10 -0
  4. package/android/src/main/AndroidManifest.xml +4 -0
  5. package/android/src/main/java/dev/authon/reactnative/wallet/AuthonWalletModule.kt +181 -0
  6. package/android/src/vendor/GENERATED.md +4 -0
  7. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/AuthonWallet.kt +191 -0
  8. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Bytes.kt +74 -0
  9. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/CredentialManagerPasskeys.kt +192 -0
  10. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/DeviceStore.kt +170 -0
  11. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/DialogWalletApprover.kt +141 -0
  12. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Eip712.kt +176 -0
  13. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/EvmAccount.kt +45 -0
  14. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/EvmTransaction.kt +180 -0
  15. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/GfTables.kt +44 -0
  16. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/HdWallet.kt +130 -0
  17. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Http.kt +82 -0
  18. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/JsValues.kt +83 -0
  19. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/KeystoreDeviceStore.kt +232 -0
  20. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Prf.kt +111 -0
  21. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Proof.kt +134 -0
  22. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Shamir.kt +106 -0
  23. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/SignSummary.kt +335 -0
  24. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/WalletApi.kt +353 -0
  25. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/WalletError.kt +58 -0
  26. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/WalletOps.kt +449 -0
  27. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/WalletTypes.kt +71 -0
  28. package/build/authonContext.d.ts +19 -0
  29. package/build/authonContext.d.ts.map +1 -0
  30. package/build/authonContext.js +20 -0
  31. package/build/authonContext.js.map +1 -0
  32. package/build/client.d.ts +76 -0
  33. package/build/client.d.ts.map +1 -0
  34. package/build/client.js +349 -0
  35. package/build/client.js.map +1 -0
  36. package/build/errors.d.ts +18 -0
  37. package/build/errors.d.ts.map +1 -0
  38. package/build/errors.js +9 -0
  39. package/build/errors.js.map +1 -0
  40. package/build/index.d.ts +7 -0
  41. package/build/index.d.ts.map +1 -0
  42. package/build/index.js +4 -0
  43. package/build/index.js.map +1 -0
  44. package/build/native.d.ts +39 -0
  45. package/build/native.d.ts.map +1 -0
  46. package/build/native.js +12 -0
  47. package/build/native.js.map +1 -0
  48. package/build/types.d.ts +121 -0
  49. package/build/types.d.ts.map +1 -0
  50. package/build/types.js +3 -0
  51. package/build/types.js.map +1 -0
  52. package/build/useAuthonWallet.d.ts +25 -0
  53. package/build/useAuthonWallet.d.ts.map +1 -0
  54. package/build/useAuthonWallet.js +77 -0
  55. package/build/useAuthonWallet.js.map +1 -0
  56. package/expo-module.config.json +9 -0
  57. package/ios/AuthonReactNativeWallet.podspec +37 -0
  58. package/ios/AuthonWalletModule.swift +190 -0
  59. package/ios/vendor/AuthonWallet/AuthonWallet.swift +212 -0
  60. package/ios/vendor/AuthonWallet/Crypto/BIP39Wordlist.swift +262 -0
  61. package/ios/vendor/AuthonWallet/Crypto/HDKey.swift +108 -0
  62. package/ios/vendor/AuthonWallet/Crypto/Secp256k1.swift +104 -0
  63. package/ios/vendor/AuthonWallet/Crypto/Shamir.swift +123 -0
  64. package/ios/vendor/AuthonWallet/EVM/Address.swift +57 -0
  65. package/ios/vendor/AuthonWallet/EVM/EvmAccount.swift +48 -0
  66. package/ios/vendor/AuthonWallet/EVM/Transaction.swift +165 -0
  67. package/ios/vendor/AuthonWallet/EVM/TypedData.swift +193 -0
  68. package/ios/vendor/AuthonWallet/Support/BigInteger.swift +220 -0
  69. package/ios/vendor/AuthonWallet/Support/Bytes.swift +89 -0
  70. package/ios/vendor/AuthonWallet/Support/JSONValue.swift +341 -0
  71. package/ios/vendor/AuthonWallet/UI/WalletApprover.swift +250 -0
  72. package/ios/vendor/AuthonWallet/Wallet/Backup.swift +69 -0
  73. package/ios/vendor/AuthonWallet/Wallet/DeviceStore.swift +351 -0
  74. package/ios/vendor/AuthonWallet/Wallet/Passkeys.swift +190 -0
  75. package/ios/vendor/AuthonWallet/Wallet/Proof.swift +143 -0
  76. package/ios/vendor/AuthonWallet/Wallet/Shares.swift +116 -0
  77. package/ios/vendor/AuthonWallet/Wallet/Summary.swift +342 -0
  78. package/ios/vendor/AuthonWallet/Wallet/WalletAPI.swift +350 -0
  79. package/ios/vendor/AuthonWallet/Wallet/WalletOps.swift +555 -0
  80. package/ios/vendor/AuthonWallet/WalletError.swift +54 -0
  81. package/ios/vendor/CKeccak/LICENSE +22 -0
  82. package/ios/vendor/CKeccak/README.md +27 -0
  83. package/ios/vendor/CKeccak/byte_order.h +59 -0
  84. package/ios/vendor/CKeccak/include/ckeccak.h +9 -0
  85. package/ios/vendor/CKeccak/memzero.c +75 -0
  86. package/ios/vendor/CKeccak/memzero.h +8 -0
  87. package/ios/vendor/CKeccak/options.h +99 -0
  88. package/ios/vendor/CKeccak/sha3.c +413 -0
  89. package/ios/vendor/CKeccak/sha3.h +89 -0
  90. package/ios/vendor/CSecp256k1/COPYING +19 -0
  91. package/ios/vendor/CSecp256k1/README.md +35 -0
  92. package/ios/vendor/CSecp256k1/build/precomputed_ecmult.c +3 -0
  93. package/ios/vendor/CSecp256k1/build/precomputed_ecmult_gen.c +3 -0
  94. package/ios/vendor/CSecp256k1/build/secp256k1.c +3 -0
  95. package/ios/vendor/CSecp256k1/include/secp256k1.h +899 -0
  96. package/ios/vendor/CSecp256k1/include/secp256k1_preallocated.h +134 -0
  97. package/ios/vendor/CSecp256k1/include/secp256k1_recovery.h +113 -0
  98. package/ios/vendor/CSecp256k1/src/assumptions.h +87 -0
  99. package/ios/vendor/CSecp256k1/src/checkmem.h +102 -0
  100. package/ios/vendor/CSecp256k1/src/ecdsa.h +21 -0
  101. package/ios/vendor/CSecp256k1/src/ecdsa_impl.h +304 -0
  102. package/ios/vendor/CSecp256k1/src/eckey.h +25 -0
  103. package/ios/vendor/CSecp256k1/src/eckey_impl.h +92 -0
  104. package/ios/vendor/CSecp256k1/src/ecmult.h +61 -0
  105. package/ios/vendor/CSecp256k1/src/ecmult_const.h +38 -0
  106. package/ios/vendor/CSecp256k1/src/ecmult_const_impl.h +399 -0
  107. package/ios/vendor/CSecp256k1/src/ecmult_gen.h +143 -0
  108. package/ios/vendor/CSecp256k1/src/ecmult_gen_impl.h +341 -0
  109. package/ios/vendor/CSecp256k1/src/ecmult_impl.h +853 -0
  110. package/ios/vendor/CSecp256k1/src/field.h +350 -0
  111. package/ios/vendor/CSecp256k1/src/field_10x26.h +57 -0
  112. package/ios/vendor/CSecp256k1/src/field_10x26_impl.h +1232 -0
  113. package/ios/vendor/CSecp256k1/src/field_5x52.h +62 -0
  114. package/ios/vendor/CSecp256k1/src/field_5x52_impl.h +522 -0
  115. package/ios/vendor/CSecp256k1/src/field_5x52_int128_impl.h +274 -0
  116. package/ios/vendor/CSecp256k1/src/field_impl.h +457 -0
  117. package/ios/vendor/CSecp256k1/src/group.h +212 -0
  118. package/ios/vendor/CSecp256k1/src/group_impl.h +974 -0
  119. package/ios/vendor/CSecp256k1/src/hash.h +44 -0
  120. package/ios/vendor/CSecp256k1/src/hash_impl.h +299 -0
  121. package/ios/vendor/CSecp256k1/src/hsort.h +33 -0
  122. package/ios/vendor/CSecp256k1/src/hsort_impl.h +125 -0
  123. package/ios/vendor/CSecp256k1/src/int128.h +90 -0
  124. package/ios/vendor/CSecp256k1/src/int128_impl.h +18 -0
  125. package/ios/vendor/CSecp256k1/src/int128_native.h +19 -0
  126. package/ios/vendor/CSecp256k1/src/int128_native_impl.h +94 -0
  127. package/ios/vendor/CSecp256k1/src/int128_struct.h +14 -0
  128. package/ios/vendor/CSecp256k1/src/int128_struct_impl.h +205 -0
  129. package/ios/vendor/CSecp256k1/src/modinv32.h +43 -0
  130. package/ios/vendor/CSecp256k1/src/modinv32_impl.h +725 -0
  131. package/ios/vendor/CSecp256k1/src/modinv64.h +47 -0
  132. package/ios/vendor/CSecp256k1/src/modinv64_impl.h +780 -0
  133. package/ios/vendor/CSecp256k1/src/modules/recovery/main_impl.h +159 -0
  134. package/ios/vendor/CSecp256k1/src/precomputed_ecmult.c +16456 -0
  135. package/ios/vendor/CSecp256k1/src/precomputed_ecmult.h +38 -0
  136. package/ios/vendor/CSecp256k1/src/precomputed_ecmult_gen.c +1779 -0
  137. package/ios/vendor/CSecp256k1/src/precomputed_ecmult_gen.h +26 -0
  138. package/ios/vendor/CSecp256k1/src/scalar.h +105 -0
  139. package/ios/vendor/CSecp256k1/src/scalar_4x64.h +19 -0
  140. package/ios/vendor/CSecp256k1/src/scalar_4x64_impl.h +1000 -0
  141. package/ios/vendor/CSecp256k1/src/scalar_8x32.h +19 -0
  142. package/ios/vendor/CSecp256k1/src/scalar_8x32_impl.h +816 -0
  143. package/ios/vendor/CSecp256k1/src/scalar_impl.h +321 -0
  144. package/ios/vendor/CSecp256k1/src/scalar_low.h +24 -0
  145. package/ios/vendor/CSecp256k1/src/scalar_low_impl.h +206 -0
  146. package/ios/vendor/CSecp256k1/src/scratch.h +44 -0
  147. package/ios/vendor/CSecp256k1/src/scratch_impl.h +99 -0
  148. package/ios/vendor/CSecp256k1/src/secp256k1.c +831 -0
  149. package/ios/vendor/CSecp256k1/src/selftest.h +32 -0
  150. package/ios/vendor/CSecp256k1/src/util.h +451 -0
  151. package/ios/vendor/GENERATED.md +4 -0
  152. package/package.json +65 -3
  153. package/src/authonContext.ts +30 -0
  154. package/src/client.ts +375 -0
  155. package/src/errors.ts +52 -0
  156. package/src/index.ts +21 -0
  157. package/src/native.ts +50 -0
  158. package/src/types.ts +120 -0
  159. package/src/useAuthonWallet.ts +103 -0
@@ -0,0 +1,349 @@
1
+ import { Platform } from 'expo-modules-core';
2
+ import { AuthonWalletError } from './errors';
3
+ import { getNativeModule } from './native';
4
+ const MAX_ACCOUNT_INDEX = 0x7fffffff;
5
+ let counter = 0;
6
+ const isObject = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
7
+ const str = (v) => (typeof v === 'string' ? v : null);
8
+ /** Copies only the public fields, so nothing else the native side might add reaches the app. */
9
+ function toWallet(value) {
10
+ if (!isObject(value) || typeof value.address !== 'string')
11
+ throw new AuthonWalletError('UNKNOWN', 'Wallet returned no wallet');
12
+ const devices = Array.isArray(value.devices)
13
+ ? value.devices.filter(isObject).map((d) => ({
14
+ id: String(d.id),
15
+ label: str(d.label),
16
+ createdAt: str(d.createdAt),
17
+ lastUsedAt: str(d.lastUsedAt),
18
+ current: d.current === true,
19
+ }))
20
+ : [];
21
+ return {
22
+ address: value.address,
23
+ protected: value.protected === true,
24
+ needsRestore: value.needsRestore === true,
25
+ backupUpgradeRecommended: value.backupUpgradeRecommended === true,
26
+ devices,
27
+ };
28
+ }
29
+ function toAccounts(value) {
30
+ if (!Array.isArray(value))
31
+ throw new AuthonWalletError('UNKNOWN', 'Wallet returned no accounts');
32
+ return value.filter(isObject).map((a) => ({ index: Number(a.index), path: String(a.path), address: String(a.address) }));
33
+ }
34
+ function toHex(value) {
35
+ if (typeof value !== 'string' || !/^0x[0-9a-fA-F]*$/.test(value))
36
+ throw new AuthonWalletError('UNKNOWN', 'Wallet returned no signature');
37
+ return value;
38
+ }
39
+ function toAppConfig(value) {
40
+ if (!isObject(value))
41
+ throw new AuthonWalletError('UNKNOWN', 'Wallet returned no app config');
42
+ return {
43
+ projectId: str(value.projectId),
44
+ allowed: value.allowed === true,
45
+ approved: value.approved === true,
46
+ enabled: value.enabled === true,
47
+ chainIds: Array.isArray(value.chainIds) ? value.chainIds.map(Number) : [],
48
+ confirmSigning: value.confirmSigning !== false,
49
+ rpId: String(value.rpId ?? ''),
50
+ minFrameProtocol: typeof value.minFrameProtocol === 'number' ? value.minFrameProtocol : null,
51
+ };
52
+ }
53
+ /** bigint → 0x hex (transactions, like @authon/js). */
54
+ const txReplacer = (_key, v) => (typeof v === 'bigint' ? `0x${v.toString(16)}` : v);
55
+ /** bigint → decimal string (EIP-712 integer values). */
56
+ const typedReplacer = (_key, v) => (typeof v === 'bigint' ? v.toString(10) : v);
57
+ /**
58
+ * The Authon embedded wallet in a React Native app. Signing runs in the native Swift / Kotlin
59
+ * wallet; JS only sees addresses, signatures, status and devices.
60
+ */
61
+ export class AuthonWalletClient {
62
+ id = `authon-wallet-${++counter}`;
63
+ options;
64
+ listeners = new Set();
65
+ accountAddresses = new Map();
66
+ configured = null;
67
+ ensuring = null;
68
+ /** Bumped by dispose(); results of calls started before it are dropped (DISPOSED). */
69
+ generation = 0;
70
+ constructor(options) {
71
+ if (!options?.publishableKey)
72
+ throw new AuthonWalletError('INVALID_PARAMS', 'publishableKey is required');
73
+ if (typeof options.getToken !== 'function')
74
+ throw new AuthonWalletError('INVALID_PARAMS', 'getToken is required');
75
+ this.options = options;
76
+ }
77
+ /** App registration and wallet settings (does not need a session). */
78
+ async appConfig() {
79
+ const generation = this.generation;
80
+ const native = await this.native();
81
+ return toAppConfig(this.unwrap(await native.appConfig(this.id), generation));
82
+ }
83
+ /** The signed-in user's wallet, or null when there is none yet. */
84
+ async get() {
85
+ try {
86
+ return this.remember(toWallet(await this.call((n, id, token) => n.status(id, token))));
87
+ }
88
+ catch (error) {
89
+ if (error instanceof AuthonWalletError && error.code === 'NOT_FOUND')
90
+ return null;
91
+ throw error;
92
+ }
93
+ }
94
+ /** Same as `get()` (the frame method is `wallet.status`). */
95
+ status() {
96
+ return this.get();
97
+ }
98
+ /** Creates the wallet (two-phase on the server), or returns the existing one. */
99
+ async create() {
100
+ const wallet = this.remember(toWallet(await this.call((n, id, token) => n.create(id, token))));
101
+ this.notify(wallet);
102
+ return wallet;
103
+ }
104
+ /** Returns the wallet, creating it first when the user has none. Concurrent calls share one request. */
105
+ ensure() {
106
+ if (this.ensuring)
107
+ return this.ensuring;
108
+ const run = (async () => (await this.get()) ?? (await this.create()))();
109
+ this.ensuring = run;
110
+ const clear = () => {
111
+ if (this.ensuring === run)
112
+ this.ensuring = null;
113
+ };
114
+ run.then(clear, clear);
115
+ return run;
116
+ }
117
+ /** True when the wallet exists and has a passkey backup. */
118
+ async isProtected() {
119
+ return (await this.get())?.protected === true;
120
+ }
121
+ /** Addresses of accounts `start`..`start + count - 1` (public, no approval). */
122
+ async getAccounts(options = {}) {
123
+ const start = options.start ?? 0;
124
+ const count = options.count ?? 1;
125
+ if (!Number.isInteger(start) || start < 0 || start > MAX_ACCOUNT_INDEX || !Number.isInteger(count) || count < 1) {
126
+ throw new AuthonWalletError('INVALID_PARAMS', 'start must be an integer 0..2147483647 and count a positive integer');
127
+ }
128
+ const list = toAccounts(await this.call((n, id, token) => n.accounts(id, token, start, count)));
129
+ for (const account of list)
130
+ this.accountAddresses.set(account.index, account.address);
131
+ return list;
132
+ }
133
+ /**
134
+ * EIP-191 personal_sign. The native approval sheet / dialog shows the full text first when the
135
+ * project requires confirmation (default); rejecting gives USER_CANCELLED and nothing is signed.
136
+ */
137
+ async signMessage(message, options = {}) {
138
+ let kind;
139
+ let text;
140
+ if (typeof message === 'string') {
141
+ kind = 'text';
142
+ text = message;
143
+ }
144
+ else if (isObject(message) && typeof message.raw === 'string') {
145
+ kind = 'raw';
146
+ text = message.raw;
147
+ }
148
+ else {
149
+ throw new AuthonWalletError('INVALID_PARAMS', 'message must be a string or { raw: hex }');
150
+ }
151
+ const [account, address] = await this.account(options.account);
152
+ return toHex(await this.call((n, id, token) => n.signMessage(id, token, kind, text, account, address)));
153
+ }
154
+ /** EIP-712 v4 typed data. */
155
+ async signTypedData(typedData, options = {}) {
156
+ if (!isObject(typedData))
157
+ throw new AuthonWalletError('INVALID_PARAMS', 'typedData must be an object');
158
+ const json = JSON.stringify(typedData, typedReplacer);
159
+ const [account, address] = await this.account(options.account);
160
+ return toHex(await this.call((n, id, token) => n.signTypedData(id, token, json, account, address)));
161
+ }
162
+ /** Signs a legacy, EIP-2930 or EIP-1559 transaction and returns the serialized signed transaction. */
163
+ async signTransaction(tx, options = {}) {
164
+ if (!isObject(tx))
165
+ throw new AuthonWalletError('INVALID_PARAMS', 'transaction must be an object');
166
+ const json = JSON.stringify(tx, txReplacer);
167
+ const [account, address] = await this.account(options.account);
168
+ return toHex(await this.call((n, id, token) => n.signTransaction(id, token, json, account, address)));
169
+ }
170
+ /** Creates the passkey backup (iOS 18+ / Android with PRF support). Needs an approved app registration. */
171
+ async protect() {
172
+ await this.call((n, id, token) => n.protect(id, token));
173
+ await this.refresh();
174
+ }
175
+ /** Replaces a legacy backup with a verifiable one, on a device that holds the wallet. */
176
+ async upgradeBackup() {
177
+ await this.call((n, id, token) => n.upgradeBackup(id, token));
178
+ await this.refresh();
179
+ }
180
+ /**
181
+ * Restores the wallet on this install with the backup passkey. By default this install is added
182
+ * as another device; `resetOtherDevices: true` re-splits the key and revokes every other device.
183
+ */
184
+ async restore(options = {}) {
185
+ const reset = options.resetOtherDevices === true;
186
+ await this.call((n, id, token) => n.restore(id, token, reset));
187
+ await this.refresh();
188
+ }
189
+ /** Revokes a device (signed with this install's device key). */
190
+ async revokeDevice(deviceId) {
191
+ if (typeof deviceId !== 'string' || !deviceId)
192
+ throw new AuthonWalletError('INVALID_PARAMS', 'deviceId required');
193
+ await this.call((n, id, token) => n.revokeDevice(id, token, deviceId));
194
+ await this.refresh();
195
+ }
196
+ onChange(listener) {
197
+ this.listeners.add(listener);
198
+ return () => {
199
+ this.listeners.delete(listener);
200
+ };
201
+ }
202
+ /** A minimal EIP-1193 provider (same methods as @authon/js). */
203
+ provider(chainId) {
204
+ const hexChainId = `0x${chainId.toString(16)}`;
205
+ return {
206
+ request: async ({ method, params }) => {
207
+ const list = Array.isArray(params) ? params : [];
208
+ switch (method) {
209
+ case 'eth_chainId':
210
+ return hexChainId;
211
+ case 'eth_accounts': {
212
+ const wallet = await this.get();
213
+ return wallet ? [wallet.address] : [];
214
+ }
215
+ case 'eth_requestAccounts':
216
+ return [(await this.ensure()).address];
217
+ case 'personal_sign': {
218
+ const data = list[0];
219
+ if (typeof data !== 'string')
220
+ throw new AuthonWalletError('INVALID_PARAMS', 'personal_sign requires a message');
221
+ return this.signMessage({ raw: data });
222
+ }
223
+ case 'eth_signTypedData_v4': {
224
+ const raw = list[1];
225
+ const typed = typeof raw === 'string' ? JSON.parse(raw) : raw;
226
+ if (!isObject(typed))
227
+ throw new AuthonWalletError('INVALID_PARAMS', 'eth_signTypedData_v4 requires typed data');
228
+ return this.signTypedData(typed);
229
+ }
230
+ case 'eth_signTransaction': {
231
+ const tx = list[0];
232
+ if (!isObject(tx))
233
+ throw new AuthonWalletError('INVALID_PARAMS', 'eth_signTransaction requires a transaction');
234
+ return this.signTransaction({ chainId: hexChainId, ...tx });
235
+ }
236
+ default:
237
+ throw Object.assign(new AuthonWalletError('UNSUPPORTED_METHOD', `Method ${method} is not supported`), { code: 4200 });
238
+ }
239
+ },
240
+ };
241
+ }
242
+ /**
243
+ * Call on sign-out: releases the native instance, rejects calls in flight with DISPOSED and
244
+ * forgets cached account addresses. The device share stays on the device. Like @authon/js, the
245
+ * client can be used again afterwards (it reconnects on the next call).
246
+ */
247
+ dispose() {
248
+ this.generation++;
249
+ const configured = this.configured;
250
+ this.configured = null;
251
+ this.ensuring = null;
252
+ this.accountAddresses.clear();
253
+ configured?.then((n) => n.release(this.id)).catch(() => { });
254
+ this.notify(null);
255
+ }
256
+ // Internals
257
+ async native() {
258
+ if (!this.configured) {
259
+ const run = (async () => {
260
+ const native = getNativeModule();
261
+ if (!native) {
262
+ throw new AuthonWalletError('NOT_CONFIGURED', '@authon/react-native-wallet native module not found. Use a development build (not Expo Go) and rebuild the app.');
263
+ }
264
+ const appId = this.options.appId;
265
+ const platformAppId = typeof appId === 'string' ? appId : Platform.OS === 'ios' ? appId?.ios : appId?.android;
266
+ this.unwrap(await native.configure(this.id, {
267
+ publishableKey: this.options.publishableKey,
268
+ apiUrl: this.options.apiUrl ?? null,
269
+ appId: platformAppId ?? null,
270
+ requireDeviceAuthentication: this.options.requireDeviceAuthentication === true,
271
+ testing: {
272
+ allowSoftwareKeys: this.options.testing?.allowSoftwareKeys === true,
273
+ autoApprove: this.options.testing?.autoApprove === true,
274
+ },
275
+ }));
276
+ return native;
277
+ })();
278
+ this.configured = run;
279
+ run.catch(() => {
280
+ if (this.configured === run)
281
+ this.configured = null;
282
+ });
283
+ }
284
+ return this.configured;
285
+ }
286
+ async token() {
287
+ const token = await this.options.getToken();
288
+ if (typeof token !== 'string' || !token)
289
+ throw new AuthonWalletError('NOT_SIGNED_IN', 'Sign in before using the wallet');
290
+ return token;
291
+ }
292
+ async call(fn) {
293
+ const generation = this.generation;
294
+ const native = await this.native();
295
+ const token = await this.token();
296
+ return this.unwrap(await fn(native, this.id, token), generation);
297
+ }
298
+ unwrap(result, generation = this.generation) {
299
+ if (generation !== this.generation)
300
+ throw new AuthonWalletError('DISPOSED', 'Wallet was disposed');
301
+ if (!isObject(result))
302
+ throw new AuthonWalletError('UNKNOWN', 'Wallet returned no result');
303
+ if (result.ok === true)
304
+ return result.value;
305
+ const code = typeof result.code === 'string' && result.code ? result.code : 'UNKNOWN';
306
+ throw new AuthonWalletError(code, typeof result.message === 'string' && result.message ? result.message : code);
307
+ }
308
+ /** For accounts other than 0 the native wallet needs the expected address and refuses on mismatch. */
309
+ async account(index) {
310
+ if (index === undefined || index === 0)
311
+ return [0, null];
312
+ if (!Number.isInteger(index) || index < 0 || index > MAX_ACCOUNT_INDEX) {
313
+ throw new AuthonWalletError('INVALID_PARAMS', 'account must be an integer 0..2147483647');
314
+ }
315
+ let address = this.accountAddresses.get(index);
316
+ if (!address) {
317
+ const [account] = await this.getAccounts({ start: index, count: 1 });
318
+ if (!account || account.index !== index)
319
+ throw new AuthonWalletError('UNKNOWN', 'Wallet returned another account');
320
+ address = account.address;
321
+ }
322
+ return [index, address];
323
+ }
324
+ /** A different wallet (another user) invalidates the cached account addresses. */
325
+ remember(wallet) {
326
+ const known = this.accountAddresses.get(0);
327
+ if (known && known.toLowerCase() !== wallet.address.toLowerCase())
328
+ this.accountAddresses.clear();
329
+ this.accountAddresses.set(0, wallet.address);
330
+ return wallet;
331
+ }
332
+ async refresh() {
333
+ this.notify(await this.get());
334
+ }
335
+ notify(wallet) {
336
+ for (const listener of this.listeners) {
337
+ try {
338
+ listener(wallet);
339
+ }
340
+ catch {
341
+ // A listener error must not break the wallet call.
342
+ }
343
+ }
344
+ }
345
+ }
346
+ export function createAuthonWallet(options) {
347
+ return new AuthonWalletClient(options);
348
+ }
349
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAoD,MAAM,UAAU,CAAC;AAgB7F,MAAM,iBAAiB,GAAG,UAAU,CAAC;AACrC,IAAI,OAAO,GAAG,CAAC,CAAC;AAEhB,MAAM,QAAQ,GAAG,CAAC,CAAU,EAAgC,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACxH,MAAM,GAAG,GAAG,CAAC,CAAU,EAAiB,EAAE,CAAC,CAAC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MAAM,CAAC,MAA6B;QAC1C,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACtC,IAAI,CAAC;gBACH,QAAQ,CAAC,MAAM,CAAC,CAAC;YACnB,CAAC;YAAC,MAAM,CAAC;gBACP,mDAAmD;YACrD,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAED,MAAM,UAAU,kBAAkB,CAAC,OAA4B;IAC7D,OAAO,IAAI,kBAAkB,CAAC,OAAO,CAAC,CAAC;AACzC,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Error codes of the web wallet (`@authon/js` WalletErrorCode, frame `errors.ts`). The native
3
+ * Swift and Kotlin wallets report the same strings; they reach JS unchanged.
4
+ */
5
+ export type WalletErrorCode = 'NOT_FOUND' | 'NEEDS_RESTORE' | 'NOT_PROTECTED' | 'PRF_UNSUPPORTED' | 'ORIGIN_NOT_ALLOWED' | 'USER_CANCELLED' | 'NEEDS_POPUP' | 'INVALID_REQUEST' | 'UNSUPPORTED_TYPE' | 'UNAUTHORIZED' | 'FORBIDDEN' | 'ALREADY_EXISTS' | 'RATE_LIMITED' | 'ADDRESS_MISMATCH' | 'STORAGE_UNAVAILABLE' | 'API_ERROR' | 'INTERNAL' | 'LAST_DEVICE' | 'SESSION_REQUIRED' | 'WALLET_PENDING' | 'CONFIRM_WINDOW_BLOCKED' | 'CONFIRM_WINDOW_CLOSED' | 'MESSAGE_TOO_LARGE' | 'FRAME_OUTDATED' | 'BACKUP_KEY_REQUIRED' | 'ALREADY_UPGRADED' | 'ACCOUNT_UNAVAILABLE'
6
+ /** Raised in JS: getToken() returned no token. */
7
+ | 'NOT_SIGNED_IN'
8
+ /** Raised in JS: bad arguments caught before the native call. */
9
+ | 'INVALID_PARAMS' | 'UNSUPPORTED_METHOD'
10
+ /** Raised in JS: the client was disposed. */
11
+ | 'DISPOSED'
12
+ /** Raised in JS: the native module is missing (Expo Go, or the app was not rebuilt). */
13
+ | 'NOT_CONFIGURED' | 'UNKNOWN' | (string & {});
14
+ export declare class AuthonWalletError extends Error {
15
+ readonly code: WalletErrorCode;
16
+ constructor(code: WalletErrorCode, message?: string);
17
+ }
18
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,eAAe,GACvB,WAAW,GACX,eAAe,GACf,eAAe,GACf,iBAAiB,GACjB,oBAAoB,GACpB,gBAAgB,GAChB,aAAa,GACb,iBAAiB,GACjB,kBAAkB,GAClB,cAAc,GACd,WAAW,GACX,gBAAgB,GAChB,cAAc,GACd,kBAAkB,GAClB,qBAAqB,GACrB,WAAW,GACX,UAAU,GACV,aAAa,GACb,kBAAkB,GAClB,gBAAgB,GAChB,wBAAwB,GACxB,uBAAuB,GACvB,mBAAmB,GACnB,gBAAgB,GAChB,qBAAqB,GACrB,kBAAkB,GAClB,qBAAqB;AACvB,kDAAkD;GAChD,eAAe;AACjB,iEAAiE;GAC/D,gBAAgB,GAChB,oBAAoB;AACtB,6CAA6C;GAC3C,UAAU;AACZ,wFAAwF;GACtF,gBAAgB,GAChB,SAAS,GACT,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAElB,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;gBACnB,IAAI,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,MAAM;CAKpD"}
@@ -0,0 +1,9 @@
1
+ export class AuthonWalletError extends Error {
2
+ code;
3
+ constructor(code, message) {
4
+ super(message ?? code);
5
+ this.name = 'AuthonWalletError';
6
+ this.code = code;
7
+ }
8
+ }
9
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AA4CA,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACjC,IAAI,CAAkB;IAC/B,YAAY,IAAqB,EAAE,OAAgB;QACjD,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF"}
@@ -0,0 +1,7 @@
1
+ export { AuthonWalletClient, createAuthonWallet } from './client';
2
+ export { AuthonWalletError } from './errors';
3
+ export type { WalletErrorCode } from './errors';
4
+ export { useAuthonWallet } from './useAuthonWallet';
5
+ export type { UseAuthonWalletOptions, UseAuthonWalletResult } from './useAuthonWallet';
6
+ export type { AuthonWalletOptions, EIP1193Provider, EIP1193RequestArguments, EmbeddedWallet, EmbeddedWalletDevice, Hex, TokenGetter, TypedDataPayload, WalletAccount, WalletAppConfig, WalletChangeListener, WalletMessage, WalletSignOptions, WalletTransactionRequest, } from './types';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AACvF,YAAY,EACV,mBAAmB,EACnB,eAAe,EACf,uBAAuB,EACvB,cAAc,EACd,oBAAoB,EACpB,GAAG,EACH,WAAW,EACX,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,SAAS,CAAC"}
package/build/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { AuthonWalletClient, createAuthonWallet } from './client';
2
+ export { AuthonWalletError } from './errors';
3
+ export { useAuthonWallet } from './useAuthonWallet';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,39 @@
1
+ /** Every native function resolves an envelope instead of rejecting. */
2
+ export type NativeResult<T> = {
3
+ ok: true;
4
+ value: T;
5
+ } | {
6
+ ok: false;
7
+ code: string;
8
+ message?: string;
9
+ };
10
+ export interface NativeConfig {
11
+ publishableKey: string;
12
+ apiUrl: string | null;
13
+ appId: string | null;
14
+ requireDeviceAuthentication: boolean;
15
+ testing: {
16
+ allowSoftwareKeys: boolean;
17
+ autoApprove: boolean;
18
+ };
19
+ }
20
+ /** The Swift / Kotlin module `AuthonWallet`. Tokens go in per call; nothing secret comes out. */
21
+ export interface AuthonWalletNativeModule {
22
+ configure(id: string, config: NativeConfig): Promise<NativeResult<null>>;
23
+ release(id: string): Promise<NativeResult<null>>;
24
+ appConfig(id: string): Promise<NativeResult<unknown>>;
25
+ status(id: string, token: string): Promise<NativeResult<unknown>>;
26
+ create(id: string, token: string): Promise<NativeResult<unknown>>;
27
+ accounts(id: string, token: string, start: number, count: number): Promise<NativeResult<unknown>>;
28
+ signMessage(id: string, token: string, kind: 'text' | 'raw', message: string, account: number, address: string | null): Promise<NativeResult<unknown>>;
29
+ signTypedData(id: string, token: string, typedDataJson: string, account: number, address: string | null): Promise<NativeResult<unknown>>;
30
+ signTransaction(id: string, token: string, transactionJson: string, account: number, address: string | null): Promise<NativeResult<unknown>>;
31
+ protect(id: string, token: string): Promise<NativeResult<unknown>>;
32
+ upgradeBackup(id: string, token: string): Promise<NativeResult<unknown>>;
33
+ restore(id: string, token: string, reset: boolean): Promise<NativeResult<unknown>>;
34
+ revokeDevice(id: string, token: string, deviceId: string): Promise<NativeResult<unknown>>;
35
+ }
36
+ export declare function getNativeModule(): AuthonWalletNativeModule | null;
37
+ /** Tests only: replaces the native module (pass undefined to restore). */
38
+ export declare function setNativeModuleForTesting(module: AuthonWalletNativeModule | null | undefined): void;
39
+ //# sourceMappingURL=native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAEA,uEAAuE;AACvE,MAAM,MAAM,YAAY,CAAC,CAAC,IACtB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GACtB;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAElD,MAAM,WAAW,YAAY;IAC3B,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,2BAA2B,EAAE,OAAO,CAAC;IACrC,OAAO,EAAE;QAAE,iBAAiB,EAAE,OAAO,CAAC;QAAC,WAAW,EAAE,OAAO,CAAA;KAAE,CAAC;CAC/D;AAED,iGAAiG;AACjG,MAAM,WAAW,wBAAwB;IACvC,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;IACzE,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;IACjD,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;IACtD,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE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AAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;IACnF,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;CAC3F;AAID,wBAAgB,eAAe,IAAI,wBAAwB,GAAG,IAAI,CAGjE;AAED,0EAA0E;AAC1E,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,wBAAwB,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CAEnG"}
@@ -0,0 +1,12 @@
1
+ import { requireOptionalNativeModule } from 'expo-modules-core';
2
+ let override;
3
+ export function getNativeModule() {
4
+ if (override !== undefined)
5
+ return override;
6
+ return requireOptionalNativeModule('AuthonWallet');
7
+ }
8
+ /** Tests only: replaces the native module (pass undefined to restore). */
9
+ export function setNativeModuleForTesting(module) {
10
+ override = module;
11
+ }
12
+ //# sourceMappingURL=native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native.js","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,mBAAmB,CAAC;AAuChE,IAAI,QAAqD,CAAC;AAE1D,MAAM,UAAU,eAAe;IAC7B,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC;IAC5C,OAAO,2BAA2B,CAA2B,cAAc,CAAC,CAAC;AAC/E,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,yBAAyB,CAAC,MAAmD;IAC3F,QAAQ,GAAG,MAAM,CAAC;AACpB,CAAC"}
@@ -0,0 +1,121 @@
1
+ /** Names and shapes follow `@authon/js` (WalletClient) so web and app code read the same. */
2
+ export type Hex = `0x${string}`;
3
+ export interface EmbeddedWalletDevice {
4
+ id: string;
5
+ label: string | null;
6
+ createdAt: string | null;
7
+ lastUsedAt: string | null;
8
+ /** This app install. */
9
+ current: boolean;
10
+ }
11
+ export interface EmbeddedWallet {
12
+ /** Account 0 (m/44'/60'/0'/0/0), the same address the web wallet shows for this user. */
13
+ address: string;
14
+ /**
15
+ * True once the wallet has a passkey backup (`protect()`). An unprotected wallet exists only
16
+ * as this install's device share plus the server share: deleting the app or losing the device
17
+ * makes it unrecoverable. Do not let users receive funds until `protected` is true.
18
+ */
19
+ protected: boolean;
20
+ /** True when the server has a wallet but this install holds no device share (call `restore()`). */
21
+ needsRestore: boolean;
22
+ /** A legacy backup without a passkey public key; call `upgradeBackup()` on a device that holds the wallet. */
23
+ backupUpgradeRecommended: boolean;
24
+ devices: EmbeddedWalletDevice[];
25
+ }
26
+ /** One HD account, derived at `m/44'/60'/0'/0/{index}`. Account 0 is `EmbeddedWallet.address`. */
27
+ export interface WalletAccount {
28
+ index: number;
29
+ path: string;
30
+ address: string;
31
+ }
32
+ /** Signs with another account of the same wallet. Omitted or 0 = the wallet address. */
33
+ export interface WalletSignOptions {
34
+ account?: number;
35
+ }
36
+ /** A personal_sign payload: UTF-8 text, or raw bytes as 0x hex. */
37
+ export type WalletMessage = string | {
38
+ raw: string;
39
+ };
40
+ export interface TypedDataPayload {
41
+ domain: Record<string, unknown>;
42
+ types: Record<string, Array<{
43
+ name: string;
44
+ type: string;
45
+ }>>;
46
+ primaryType: string;
47
+ message: Record<string, unknown>;
48
+ }
49
+ export interface WalletTransactionRequest {
50
+ to?: string;
51
+ from?: string;
52
+ value?: string | number | bigint;
53
+ data?: string;
54
+ nonce?: string | number;
55
+ gas?: string | number | bigint;
56
+ gasLimit?: string | number | bigint;
57
+ gasPrice?: string | number | bigint;
58
+ maxFeePerGas?: string | number | bigint;
59
+ maxPriorityFeePerGas?: string | number | bigint;
60
+ chainId?: string | number;
61
+ type?: string | number;
62
+ accessList?: Array<{
63
+ address: string;
64
+ storageKeys: string[];
65
+ }>;
66
+ }
67
+ export type WalletChangeListener = (wallet: EmbeddedWallet | null) => void;
68
+ /** `GET /v1/wallet/app-config` for this app (public, no session needed). */
69
+ export interface WalletAppConfig {
70
+ projectId: string | null;
71
+ /** The app is registered for the project (bundle ID / package name). */
72
+ allowed: boolean;
73
+ /** An Authon administrator approved the registration; passkey backup and restore need it. */
74
+ approved: boolean;
75
+ enabled: boolean;
76
+ chainIds: number[];
77
+ /** Project setting: show the native approval UI before every signature. */
78
+ confirmSigning: boolean;
79
+ /** Passkey relying party (`wallet.authon.dev`). */
80
+ rpId: string;
81
+ minFrameProtocol: number | null;
82
+ }
83
+ export interface EIP1193RequestArguments {
84
+ method: string;
85
+ params?: unknown[] | Record<string, unknown>;
86
+ }
87
+ export interface EIP1193Provider {
88
+ request(args: EIP1193RequestArguments): Promise<unknown>;
89
+ }
90
+ export type TokenGetter = () => Promise<string | null | undefined> | string | null | undefined;
91
+ export interface AuthonWalletOptions {
92
+ publishableKey: string;
93
+ /** Defaults to https://api.authon.dev. */
94
+ apiUrl?: string;
95
+ /**
96
+ * Returns the current Authon session (access) token, refreshed when needed. Called before
97
+ * every wallet call; the token is handed to the native wallet for that call only.
98
+ */
99
+ getToken: TokenGetter;
100
+ /**
101
+ * The app as registered in the Authon console: `TEAMID.bundleId` on iOS, the package name on
102
+ * Android. Detected when omitted (iOS: from the keychain access group; Android: package name).
103
+ */
104
+ appId?: string | {
105
+ ios?: string;
106
+ android?: string;
107
+ };
108
+ /** Also require Face ID / Touch ID / device credential (iOS) or BiometricPrompt (Android) before each signature. */
109
+ requireDeviceAuthentication?: boolean;
110
+ /**
111
+ * TEST ONLY. Refused by the native module outside debug builds.
112
+ * - `allowSoftwareKeys`: software device keys when there is no Secure Enclave / StrongBox / TEE
113
+ * (simulator, emulator).
114
+ * - `autoApprove`: approve every signature without UI, for automated smoke tests.
115
+ */
116
+ testing?: {
117
+ allowSoftwareKeys?: boolean;
118
+ autoApprove?: boolean;
119
+ };
120
+ }
121
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+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,GAAG,IAAI,CAAC;CACjC;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC9C;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,IAAI,EAAE,uBAAuB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1D;AAED,MAAM,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;AAE/F,MAAM,WAAW,mBAAmB;IAClC,cAAc,EAAE,MAAM,CAAC;IACvB,0CAA0C;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,QAAQ,EAAE,WAAW,CAAC;IACtB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACpD,oHAAoH;IACpH,2BAA2B,CAAC,EAAE,OAAO,CAAC;IACtC;;;;;OAKG;IACH,OAAO,CAAC,EAAE;QAAE,iBAAiB,CAAC,EAAE,OAAO,CAAC;QAAC,WAAW,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;CAClE"}
package/build/types.js ADDED
@@ -0,0 +1,3 @@
1
+ /** Names and shapes follow `@authon/js` (WalletClient) so web and app code read the same. */
2
+ export {};
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,6FAA6F"}