@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.
- package/README.md +221 -2
- package/android/build.gradle +40 -0
- package/android/consumer-rules.pro +10 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/dev/authon/reactnative/wallet/AuthonWalletModule.kt +181 -0
- package/android/src/vendor/GENERATED.md +4 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/AuthonWallet.kt +191 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Bytes.kt +74 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/CredentialManagerPasskeys.kt +192 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/DeviceStore.kt +170 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/DialogWalletApprover.kt +141 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Eip712.kt +176 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/EvmAccount.kt +45 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/EvmTransaction.kt +180 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/GfTables.kt +44 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/HdWallet.kt +130 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Http.kt +82 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/JsValues.kt +83 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/KeystoreDeviceStore.kt +232 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Prf.kt +111 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Proof.kt +134 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Shamir.kt +106 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/SignSummary.kt +335 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/WalletApi.kt +353 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/WalletError.kt +58 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/WalletOps.kt +449 -0
- package/android/src/vendor/kotlin/dev/authon/sdk/wallet/WalletTypes.kt +71 -0
- package/build/authonContext.d.ts +19 -0
- package/build/authonContext.d.ts.map +1 -0
- package/build/authonContext.js +20 -0
- package/build/authonContext.js.map +1 -0
- package/build/client.d.ts +76 -0
- package/build/client.d.ts.map +1 -0
- package/build/client.js +349 -0
- package/build/client.js.map +1 -0
- package/build/errors.d.ts +18 -0
- package/build/errors.d.ts.map +1 -0
- package/build/errors.js +9 -0
- package/build/errors.js.map +1 -0
- package/build/index.d.ts +7 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +4 -0
- package/build/index.js.map +1 -0
- package/build/native.d.ts +39 -0
- package/build/native.d.ts.map +1 -0
- package/build/native.js +12 -0
- package/build/native.js.map +1 -0
- package/build/types.d.ts +121 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +3 -0
- package/build/types.js.map +1 -0
- package/build/useAuthonWallet.d.ts +25 -0
- package/build/useAuthonWallet.d.ts.map +1 -0
- package/build/useAuthonWallet.js +77 -0
- package/build/useAuthonWallet.js.map +1 -0
- package/expo-module.config.json +9 -0
- package/ios/AuthonReactNativeWallet.podspec +37 -0
- package/ios/AuthonWalletModule.swift +190 -0
- package/ios/vendor/AuthonWallet/AuthonWallet.swift +212 -0
- package/ios/vendor/AuthonWallet/Crypto/BIP39Wordlist.swift +262 -0
- package/ios/vendor/AuthonWallet/Crypto/HDKey.swift +108 -0
- package/ios/vendor/AuthonWallet/Crypto/Secp256k1.swift +104 -0
- package/ios/vendor/AuthonWallet/Crypto/Shamir.swift +123 -0
- package/ios/vendor/AuthonWallet/EVM/Address.swift +57 -0
- package/ios/vendor/AuthonWallet/EVM/EvmAccount.swift +48 -0
- package/ios/vendor/AuthonWallet/EVM/Transaction.swift +165 -0
- package/ios/vendor/AuthonWallet/EVM/TypedData.swift +193 -0
- package/ios/vendor/AuthonWallet/Support/BigInteger.swift +220 -0
- package/ios/vendor/AuthonWallet/Support/Bytes.swift +89 -0
- package/ios/vendor/AuthonWallet/Support/JSONValue.swift +341 -0
- package/ios/vendor/AuthonWallet/UI/WalletApprover.swift +250 -0
- package/ios/vendor/AuthonWallet/Wallet/Backup.swift +69 -0
- package/ios/vendor/AuthonWallet/Wallet/DeviceStore.swift +351 -0
- package/ios/vendor/AuthonWallet/Wallet/Passkeys.swift +190 -0
- package/ios/vendor/AuthonWallet/Wallet/Proof.swift +143 -0
- package/ios/vendor/AuthonWallet/Wallet/Shares.swift +116 -0
- package/ios/vendor/AuthonWallet/Wallet/Summary.swift +342 -0
- package/ios/vendor/AuthonWallet/Wallet/WalletAPI.swift +350 -0
- package/ios/vendor/AuthonWallet/Wallet/WalletOps.swift +555 -0
- package/ios/vendor/AuthonWallet/WalletError.swift +54 -0
- package/ios/vendor/CKeccak/LICENSE +22 -0
- package/ios/vendor/CKeccak/README.md +27 -0
- package/ios/vendor/CKeccak/byte_order.h +59 -0
- package/ios/vendor/CKeccak/include/ckeccak.h +9 -0
- package/ios/vendor/CKeccak/memzero.c +75 -0
- package/ios/vendor/CKeccak/memzero.h +8 -0
- package/ios/vendor/CKeccak/options.h +99 -0
- package/ios/vendor/CKeccak/sha3.c +413 -0
- package/ios/vendor/CKeccak/sha3.h +89 -0
- package/ios/vendor/CSecp256k1/COPYING +19 -0
- package/ios/vendor/CSecp256k1/README.md +35 -0
- package/ios/vendor/CSecp256k1/build/precomputed_ecmult.c +3 -0
- package/ios/vendor/CSecp256k1/build/precomputed_ecmult_gen.c +3 -0
- package/ios/vendor/CSecp256k1/build/secp256k1.c +3 -0
- package/ios/vendor/CSecp256k1/include/secp256k1.h +899 -0
- package/ios/vendor/CSecp256k1/include/secp256k1_preallocated.h +134 -0
- package/ios/vendor/CSecp256k1/include/secp256k1_recovery.h +113 -0
- package/ios/vendor/CSecp256k1/src/assumptions.h +87 -0
- package/ios/vendor/CSecp256k1/src/checkmem.h +102 -0
- package/ios/vendor/CSecp256k1/src/ecdsa.h +21 -0
- package/ios/vendor/CSecp256k1/src/ecdsa_impl.h +304 -0
- package/ios/vendor/CSecp256k1/src/eckey.h +25 -0
- package/ios/vendor/CSecp256k1/src/eckey_impl.h +92 -0
- package/ios/vendor/CSecp256k1/src/ecmult.h +61 -0
- package/ios/vendor/CSecp256k1/src/ecmult_const.h +38 -0
- package/ios/vendor/CSecp256k1/src/ecmult_const_impl.h +399 -0
- package/ios/vendor/CSecp256k1/src/ecmult_gen.h +143 -0
- package/ios/vendor/CSecp256k1/src/ecmult_gen_impl.h +341 -0
- package/ios/vendor/CSecp256k1/src/ecmult_impl.h +853 -0
- package/ios/vendor/CSecp256k1/src/field.h +350 -0
- package/ios/vendor/CSecp256k1/src/field_10x26.h +57 -0
- package/ios/vendor/CSecp256k1/src/field_10x26_impl.h +1232 -0
- package/ios/vendor/CSecp256k1/src/field_5x52.h +62 -0
- package/ios/vendor/CSecp256k1/src/field_5x52_impl.h +522 -0
- package/ios/vendor/CSecp256k1/src/field_5x52_int128_impl.h +274 -0
- package/ios/vendor/CSecp256k1/src/field_impl.h +457 -0
- package/ios/vendor/CSecp256k1/src/group.h +212 -0
- package/ios/vendor/CSecp256k1/src/group_impl.h +974 -0
- package/ios/vendor/CSecp256k1/src/hash.h +44 -0
- package/ios/vendor/CSecp256k1/src/hash_impl.h +299 -0
- package/ios/vendor/CSecp256k1/src/hsort.h +33 -0
- package/ios/vendor/CSecp256k1/src/hsort_impl.h +125 -0
- package/ios/vendor/CSecp256k1/src/int128.h +90 -0
- package/ios/vendor/CSecp256k1/src/int128_impl.h +18 -0
- package/ios/vendor/CSecp256k1/src/int128_native.h +19 -0
- package/ios/vendor/CSecp256k1/src/int128_native_impl.h +94 -0
- package/ios/vendor/CSecp256k1/src/int128_struct.h +14 -0
- package/ios/vendor/CSecp256k1/src/int128_struct_impl.h +205 -0
- package/ios/vendor/CSecp256k1/src/modinv32.h +43 -0
- package/ios/vendor/CSecp256k1/src/modinv32_impl.h +725 -0
- package/ios/vendor/CSecp256k1/src/modinv64.h +47 -0
- package/ios/vendor/CSecp256k1/src/modinv64_impl.h +780 -0
- package/ios/vendor/CSecp256k1/src/modules/recovery/main_impl.h +159 -0
- package/ios/vendor/CSecp256k1/src/precomputed_ecmult.c +16456 -0
- package/ios/vendor/CSecp256k1/src/precomputed_ecmult.h +38 -0
- package/ios/vendor/CSecp256k1/src/precomputed_ecmult_gen.c +1779 -0
- package/ios/vendor/CSecp256k1/src/precomputed_ecmult_gen.h +26 -0
- package/ios/vendor/CSecp256k1/src/scalar.h +105 -0
- package/ios/vendor/CSecp256k1/src/scalar_4x64.h +19 -0
- package/ios/vendor/CSecp256k1/src/scalar_4x64_impl.h +1000 -0
- package/ios/vendor/CSecp256k1/src/scalar_8x32.h +19 -0
- package/ios/vendor/CSecp256k1/src/scalar_8x32_impl.h +816 -0
- package/ios/vendor/CSecp256k1/src/scalar_impl.h +321 -0
- package/ios/vendor/CSecp256k1/src/scalar_low.h +24 -0
- package/ios/vendor/CSecp256k1/src/scalar_low_impl.h +206 -0
- package/ios/vendor/CSecp256k1/src/scratch.h +44 -0
- package/ios/vendor/CSecp256k1/src/scratch_impl.h +99 -0
- package/ios/vendor/CSecp256k1/src/secp256k1.c +831 -0
- package/ios/vendor/CSecp256k1/src/selftest.h +32 -0
- package/ios/vendor/CSecp256k1/src/util.h +451 -0
- package/ios/vendor/GENERATED.md +4 -0
- package/package.json +65 -3
- package/src/authonContext.ts +30 -0
- package/src/client.ts +375 -0
- package/src/errors.ts +52 -0
- package/src/index.ts +21 -0
- package/src/native.ts +50 -0
- package/src/types.ts +120 -0
- package/src/useAuthonWallet.ts +103 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { getAuthonContext } from './authonContext';
|
|
3
|
+
import { AuthonWalletClient } from './client';
|
|
4
|
+
import { AuthonWalletError } from './errors';
|
|
5
|
+
import type { AuthonWalletOptions, EmbeddedWallet, TokenGetter } from './types';
|
|
6
|
+
|
|
7
|
+
export interface UseAuthonWalletOptions extends Omit<AuthonWalletOptions, 'getToken'> {
|
|
8
|
+
/** Defaults to the session of the surrounding `<AuthonProvider>` from @authon/react-native. */
|
|
9
|
+
getToken?: TokenGetter;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface UseAuthonWalletResult {
|
|
13
|
+
/** The client; call ensure(), signMessage(), protect() etc. on it. */
|
|
14
|
+
wallet: AuthonWalletClient;
|
|
15
|
+
/** The signed-in user's wallet, null when signed out or before it is created. */
|
|
16
|
+
current: EmbeddedWallet | null;
|
|
17
|
+
/** False until the first status check finished (or while signed out and the auth SDK is loading). */
|
|
18
|
+
isLoaded: boolean;
|
|
19
|
+
error: AuthonWalletError | null;
|
|
20
|
+
/** Reloads `current`. */
|
|
21
|
+
refresh: () => Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Wallet of the signed-in user. Inside `<AuthonProvider>` (@authon/react-native) the session token
|
|
26
|
+
* comes from the provider and the wallet follows sign-in and sign-out; elsewhere pass `getToken`.
|
|
27
|
+
* The client is recreated only when publishableKey, apiUrl or appId change.
|
|
28
|
+
*/
|
|
29
|
+
export function useAuthonWallet(options: UseAuthonWalletOptions): UseAuthonWalletResult {
|
|
30
|
+
const session = useContext(getAuthonContext());
|
|
31
|
+
const latest = useRef({ options, session });
|
|
32
|
+
latest.current = { options, session };
|
|
33
|
+
|
|
34
|
+
if (!options.getToken && !session) {
|
|
35
|
+
throw new AuthonWalletError(
|
|
36
|
+
'NOT_CONFIGURED',
|
|
37
|
+
'useAuthonWallet needs getToken, or must be used inside <AuthonProvider> from @authon/react-native',
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const appIdKey = typeof options.appId === 'string' ? options.appId : JSON.stringify(options.appId ?? null);
|
|
42
|
+
const testingKey = JSON.stringify(options.testing ?? null);
|
|
43
|
+
const wallet = useMemo(
|
|
44
|
+
() =>
|
|
45
|
+
new AuthonWalletClient({
|
|
46
|
+
...latest.current.options,
|
|
47
|
+
getToken: async () => {
|
|
48
|
+
const { options: o, session: s } = latest.current;
|
|
49
|
+
if (o.getToken) return o.getToken();
|
|
50
|
+
if (!s?.isSignedIn) return null;
|
|
51
|
+
const token = s.getToken?.();
|
|
52
|
+
if (token) return token;
|
|
53
|
+
return (await s.client?.refreshToken?.())?.accessToken ?? null;
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
56
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
57
|
+
[options.publishableKey, options.apiUrl, appIdKey, options.requireDeviceAuthentication, testingKey],
|
|
58
|
+
);
|
|
59
|
+
// dispose() only resets the client, so this is safe under StrictMode's double effects.
|
|
60
|
+
useEffect(() => () => wallet.dispose(), [wallet]);
|
|
61
|
+
|
|
62
|
+
const [current, setCurrent] = useState<EmbeddedWallet | null>(null);
|
|
63
|
+
const [isLoaded, setLoaded] = useState(false);
|
|
64
|
+
const [error, setError] = useState<AuthonWalletError | null>(null);
|
|
65
|
+
|
|
66
|
+
useEffect(() => wallet.onChange(setCurrent), [wallet]);
|
|
67
|
+
|
|
68
|
+
const signedIn = options.getToken ? true : session?.isSignedIn === true;
|
|
69
|
+
const sessionUser = options.getToken ? null : session?.userId ?? null;
|
|
70
|
+
const authLoaded = options.getToken ? true : session?.isLoaded !== false;
|
|
71
|
+
|
|
72
|
+
const lastUser = useRef<string | null | undefined>(undefined);
|
|
73
|
+
|
|
74
|
+
const refresh = useCallback(async () => {
|
|
75
|
+
try {
|
|
76
|
+
setCurrent(await wallet.get());
|
|
77
|
+
setError(null);
|
|
78
|
+
} catch (e) {
|
|
79
|
+
setError(e instanceof AuthonWalletError ? e : new AuthonWalletError('UNKNOWN', String(e)));
|
|
80
|
+
} finally {
|
|
81
|
+
setLoaded(true);
|
|
82
|
+
}
|
|
83
|
+
}, [wallet]);
|
|
84
|
+
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
if (!authLoaded) return;
|
|
87
|
+
if (!signedIn) {
|
|
88
|
+
wallet.dispose();
|
|
89
|
+
lastUser.current = undefined;
|
|
90
|
+
setCurrent(null);
|
|
91
|
+
setError(null);
|
|
92
|
+
setLoaded(true);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
// Another user signed in: drop the previous user's cached accounts and in-flight calls.
|
|
96
|
+
if (lastUser.current !== undefined && lastUser.current !== sessionUser) wallet.dispose();
|
|
97
|
+
lastUser.current = sessionUser;
|
|
98
|
+
setLoaded(false);
|
|
99
|
+
void refresh();
|
|
100
|
+
}, [authLoaded, signedIn, sessionUser, refresh, wallet]);
|
|
101
|
+
|
|
102
|
+
return { wallet, current, isLoaded, error, refresh };
|
|
103
|
+
}
|