@bsv/expo-wallet-toolbox 0.4.0 → 0.7.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/CHANGELOG.md +547 -0
- package/README.md +19 -1
- package/assets/sounds/vault-deposit.wav +0 -0
- package/assets/sounds/vault-withdraw.wav +0 -0
- package/core/amountFormatHelpers.ts +238 -34
- package/core/backup/RemoteSyncReader.ts +2 -5
- package/core/backup/codec.ts +2 -2
- package/core/backup/push.ts +1 -1
- package/core/config.tsx +16 -1
- package/core/contacts/contactActivity.ts +153 -0
- package/core/contacts/contactCache.ts +41 -0
- package/core/contacts/contactsStore.ts +183 -0
- package/core/context/VaultContext.tsx +8 -11
- package/core/context/WalletConnectionContext.tsx +137 -52
- package/core/context/WalletContext.tsx +464 -30
- package/core/demo/demoAssets.ts +60 -0
- package/core/demo/demoLedger.ts +240 -0
- package/core/demo/demoMandalaRuntime.ts +96 -0
- package/core/demo/demoMode.ts +38 -0
- package/core/demo/demoWallet.ts +25 -0
- package/core/demo/index.ts +26 -0
- package/core/demo/useDemo.ts +59 -0
- package/core/headers/OfflineFirstChaintracks.ts +52 -14
- package/core/headers/headerStore.ts +7 -10
- package/core/hooks/useConfirmationSound.ts +14 -8
- package/core/i18n/translations.tsx +4562 -986
- package/core/identity/contactLink.ts +36 -0
- package/core/identity/handleRegistry/client.ts +285 -0
- package/core/identity/handleRegistry/profileCert.ts +254 -0
- package/core/identity/handleRegistry/registration.ts +559 -0
- package/core/identity/handleRegistry/resolver.ts +247 -0
- package/core/identity/handleRegistry/rules.ts +104 -0
- package/core/index.ts +116 -15
- package/core/localpay/build.ts +674 -37
- package/core/localpay/codec.ts +68 -5
- package/core/localpay/pending.ts +240 -22
- package/core/localpay/pendingAborts.ts +5 -1
- package/core/localpay/settlementAck.ts +149 -0
- package/core/localpay/types.ts +14 -1
- package/core/localpay/verify.ts +118 -69
- package/core/mandala/abortGuard.ts +134 -0
- package/core/mandala/basketMigration.ts +166 -0
- package/core/mandala/bundle.ts +244 -0
- package/core/mandala/createRuntime.ts +2437 -0
- package/core/mandala/drain.ts +670 -0
- package/core/mandala/permissionModule.ts +642 -0
- package/core/mandala/resendTransfer.ts +175 -0
- package/core/mandala/runtime.ts +357 -0
- package/core/mandala/settlementStore.ts +412 -0
- package/core/mandala/types.ts +290 -0
- package/core/monitor/MonitorSupervisor.ts +121 -0
- package/core/monitor/TaskBackupPush.ts +1 -1
- package/core/monitor/TaskCreditInbox.ts +1 -1
- package/core/monitor/TaskDrainOutbox.ts +1 -1
- package/core/monitor/TaskSendOffline.ts +1 -1
- package/core/net/online.ts +49 -0
- package/core/numberFormat.ts +19 -0
- package/core/offline/cancelParked.ts +94 -1
- package/core/offline/payerHold.ts +152 -12
- package/core/offline/plan.ts +1 -1
- package/core/offline/tokenFrames.ts +197 -0
- package/core/parsePeerPayURI.ts +70 -17
- package/core/pay/rails/address.ts +51 -3
- package/core/pay/rails/handle.ts +88 -9
- package/core/pay/rails/index.ts +16 -6
- package/core/pay/rails/nearby.ts +114 -4
- package/core/pay/recordProof.ts +2 -6
- package/core/services/arcadeBroadcastProvider.ts +1 -4
- package/core/services/capWalletArgs.ts +8 -9
- package/core/services/exchangeRate.ts +1 -1
- package/core/services/externalOrigin.ts +42 -0
- package/core/services/vault/VaultKeyService.ts +912 -251
- package/core/services/vault/ceremony.ts +435 -367
- package/core/services/vault/ceremonyHost.ts +27 -21
- package/core/services/vault/devMock.ts +30 -7
- package/core/services/vault/driver.ts +95 -41
- package/core/services/vault/guard.ts +514 -56
- package/core/services/vault/hardwareLease.ts +22 -0
- package/core/services/vault/mockYubiKey.ts +258 -90
- package/core/services/vault/pivReset.ts +145 -0
- package/core/services/vault/r1comb.ts +976 -0
- package/core/services/vault/session.ts +93 -26
- package/core/services/vault/transfers.ts +2617 -747
- package/core/services/vault/types.ts +100 -43
- package/core/services/vault/vaultStore.ts +991 -74
- package/core/services/walletConnectionValidation.ts +293 -0
- package/core/services/walletServiceConfig.ts +31 -20
- package/core/storage/StorageExpoSQLite.ts +420 -87
- package/core/storage/dbImage.ts +48 -0
- package/core/storage/methods/findSql.ts +3 -54
- package/core/storage/methods/listActionsSql.ts +8 -5
- package/core/storage/methods/listOutputsSql.ts +9 -5
- package/core/storage/methods/offlineActions.ts +15 -0
- package/core/storage/methods/processOfflineActions.ts +265 -9
- package/core/storage/methods/reviewStatusSql.ts +7 -2
- package/core/storage/methods/walletBalanceSql.ts +16 -4
- package/core/storage/schema/createTables.ts +152 -0
- package/core/storage/sqlUpdateValue.ts +24 -0
- package/core/toolboxConfig.ts +182 -1
- package/core/toolboxTypes.ts +40 -0
- package/core/userAvatar.ts +79 -0
- package/core/walletMonitor.ts +8 -3
- package/core/walletRepair/runWalletCheck.ts +19 -2
- package/package.json +31 -30
- package/ui/activityFilter.ts +115 -0
- package/ui/components/QRScanner.tsx +1 -1
- package/ui/components/pay/AdmissionNotice.tsx +99 -0
- package/ui/components/pay/AssetPicker.tsx +184 -0
- package/ui/components/pay/AvailableBalance.tsx +33 -2
- package/ui/components/pay/HandleReceive.tsx +213 -50
- package/ui/components/pay/NearbyFlow.tsx +616 -69
- package/ui/components/pay/PayForm.tsx +73 -8
- package/ui/components/pay/PaymentSuccessOverlay.tsx +89 -8
- package/ui/components/pay/RecipientField.tsx +132 -73
- package/ui/components/pay/RequestHub.tsx +68 -8
- package/ui/components/pay/ResultBanner.tsx +41 -4
- package/ui/components/pay/StepBar.tsx +32 -0
- package/ui/components/pay/UniversalSend.tsx +1118 -86
- package/ui/components/pay/tokenSendCopy.ts +116 -0
- package/ui/components/pay/useRecipientInput.ts +36 -7
- package/ui/components/ui/PencilEditField.tsx +109 -0
- package/ui/components/ui/PermissionSheet.tsx +65 -4
- package/ui/components/ui/Sheet.tsx +9 -2
- package/ui/components/ui/SlideOverFromRight.tsx +86 -0
- package/ui/components/vault/EnrollWizard.tsx +1432 -488
- package/ui/components/vault/KeyChooser.tsx +96 -0
- package/ui/components/vault/VaultCeremonySheet.tsx +107 -43
- package/ui/components/vault/vaultErrorCopy.ts +145 -0
- package/ui/components/wallet/ActivityRow.tsx +283 -97
- package/ui/components/wallet/AmountInput.tsx +92 -28
- package/ui/components/wallet/AssetAmount.tsx +95 -0
- package/ui/components/wallet/AssetSwitcherDropdown.tsx +261 -0
- package/ui/components/wallet/ContactActivityList.tsx +149 -0
- package/ui/components/wallet/ContactSigil.tsx +49 -0
- package/ui/components/wallet/EditPictureSheet.tsx +99 -0
- package/ui/components/wallet/FitAmount.tsx +148 -0
- package/ui/components/wallet/IconPickerSheet.tsx +168 -0
- package/ui/components/wallet/IdentifierRow.tsx +69 -0
- package/ui/components/wallet/ImportFromBackupPrompt.tsx +35 -13
- package/ui/components/wallet/ProfileButton.tsx +62 -0
- package/ui/components/wallet/UserAvatar.tsx +85 -0
- package/ui/components/wallet/avatarIcons.ts +122 -0
- package/ui/components/wallet/tokenEviction.ts +65 -0
- package/ui/hooks/useContactsStore.ts +10 -0
- package/ui/hooks/useExportWalletData.ts +39 -0
- package/ui/hooks/useMandala.ts +320 -0
- package/ui/hooks/useOnline.ts +65 -20
- package/ui/hooks/useVaultBalance.ts +105 -7
- package/ui/hooks/useVaultCoverage.ts +52 -0
- package/ui/importDatabases.ts +7 -3
- package/ui/index.ts +75 -7
- package/ui/screens/ConnectionsScreen.tsx +46 -29
- package/ui/screens/ContactScreen.tsx +289 -0
- package/ui/screens/ContactsScreen.tsx +373 -0
- package/ui/screens/IdentifierScreen.tsx +234 -0
- package/ui/screens/NewContactScreen.tsx +362 -0
- package/ui/screens/PairScreen.tsx +12 -12
- package/ui/screens/PayScreen.tsx +145 -12
- package/ui/screens/ProfileScreen.tsx +783 -0
- package/ui/screens/SettingsScreen.tsx +18 -9
- package/ui/screens/TransactionDetailScreen.tsx +419 -0
- package/ui/screens/TrustScreen.tsx +1 -1
- package/ui/screens/VaultScreen.tsx +925 -171
- package/ui/screens/VaultTransferScreen.tsx +376 -123
- package/ui/screens/WalletCheckScreen.tsx +10 -1
- package/ui/screens/WalletConfigScreen.tsx +80 -16
- package/ui/screens/WalletHomeScreen.tsx +915 -139
- package/ui/screens/homeBadges.ts +9 -1
- package/ui/screens/tokenRowTitle.ts +68 -0
- package/ui/tokenFormat.ts +108 -0
- package/ui/tokenSeen.ts +75 -0
- package/ui/tokenStatus.ts +100 -0
- package/ui/txStatus.ts +43 -5
- package/assets/sounds/vault-close.wav +0 -0
- package/assets/sounds/vault-open.wav +0 -0
- package/core/services/vault/k1.ts +0 -75
- package/core/services/vault/sealing.ts +0 -84
- package/core/services/vault/vaultDerivation.ts +0 -152
- package/core/services/vault/vaultPassphrase.ts +0 -287
- package/ui/components/vault/PassphraseField.tsx +0 -306
- package/ui/components/vault/PhraseBackupSheet.tsx +0 -227
- package/ui/screens/VaultRecoverScreen.tsx +0 -226
|
@@ -5,42 +5,48 @@
|
|
|
5
5
|
* and the React vault context drive the SAME ceremony. Kept out of any React
|
|
6
6
|
* module so importing it never pulls in the component graph.
|
|
7
7
|
*/
|
|
8
|
-
import { CeremonyController,
|
|
8
|
+
import { CeremonyController, VaultProgress, VaultSigner } from './ceremony'
|
|
9
9
|
import { getVaultDriver } from './driver'
|
|
10
10
|
import { vaultStore } from './vaultStore'
|
|
11
11
|
|
|
12
|
-
/** How long an armed
|
|
13
|
-
*
|
|
14
|
-
* how long that key may live in memory. */
|
|
12
|
+
/** How long an armed signer stays usable before it relocks — refreshed by
|
|
13
|
+
* progress notes and sign() calls, capped at 3× (see ceremony.ts). */
|
|
15
14
|
export const VAULT_RETENTION_MS = 120_000
|
|
16
15
|
|
|
16
|
+
/** Digests one NFC tap covers before the ceremony closes the session and
|
|
17
|
+
* asks for a fresh tap (spec §4.2 step 6). PROVISIONAL: pinned by the §0
|
|
18
|
+
* device run (a 32-input withdrawal on iOS) against the card's 15 s touch
|
|
19
|
+
* cache and CoreNFC's 60 s session. Persistent readers (Android USB) ignore it. */
|
|
20
|
+
export const VAULT_INPUTS_PER_TAP = 16
|
|
21
|
+
|
|
17
22
|
export const ceremony = new CeremonyController({
|
|
18
23
|
getDriver: getVaultDriver,
|
|
19
24
|
store: {
|
|
20
|
-
// Only what the ceremony needs to run
|
|
21
|
-
// which
|
|
22
|
-
//
|
|
25
|
+
// Only what the ceremony needs to run a tap: which serials may answer and
|
|
26
|
+
// which slot / public key each carries. Nicknames and timestamps stay in
|
|
27
|
+
// the store — the sheet reads them from vaultStore directly.
|
|
23
28
|
getMeta: async () => {
|
|
24
29
|
const m = await vaultStore.getMeta()
|
|
25
|
-
return m ? {
|
|
26
|
-
}
|
|
27
|
-
getSeal: () => vaultStore.getSeal()
|
|
30
|
+
return m ? { keys: m.keys.map(k => ({ serial: k.serial, slot: k.slot, pubkey: k.pubkey })) } : null
|
|
31
|
+
}
|
|
28
32
|
},
|
|
29
|
-
retentionMs: VAULT_RETENTION_MS
|
|
33
|
+
retentionMs: VAULT_RETENTION_MS,
|
|
34
|
+
inputsPerTap: VAULT_INPUTS_PER_TAP
|
|
30
35
|
})
|
|
31
36
|
|
|
32
|
-
/** Tap the YubiKey to
|
|
33
|
-
* release() in a finally — that is what
|
|
34
|
-
*
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
/** Tap the CHOSEN YubiKey to obtain a signer for one operation. Callers MUST
|
|
38
|
+
* release() in a finally — that is what dismisses the NFC sheet and drops the
|
|
39
|
+
* PIN. `reason` is what the sheet shows, and (Task 6, decision 1) the iOS NFC
|
|
40
|
+
* alert text. */
|
|
41
|
+
export function requestVaultSigner(reason: string, chosenSerial: string): Promise<VaultSigner> {
|
|
42
|
+
return ceremony.requestSigner(reason, chosenSerial)
|
|
37
43
|
}
|
|
38
44
|
|
|
39
|
-
/** Report post-arm progress (preparing / broadcasting) so
|
|
40
|
-
* can show activity through the seconds-long stretches
|
|
41
|
-
* the network is busy, and so the retention window
|
|
42
|
-
* instead of expiring underneath it. A no-op when
|
|
43
|
-
*
|
|
45
|
+
/** Report post-arm progress (preparing with signed/total, broadcasting) so
|
|
46
|
+
* the ceremony sheet can show activity through the seconds-long stretches
|
|
47
|
+
* where the JS thread or the network is busy, and so the retention window
|
|
48
|
+
* tracks a live operation instead of expiring underneath it. A no-op when
|
|
49
|
+
* nothing is armed — which is what keeps the hardware-free deposit sheet-free. */
|
|
44
50
|
export function noteVaultProgress(p: VaultProgress): void {
|
|
45
51
|
ceremony.noteProgress(p)
|
|
46
52
|
}
|
|
@@ -2,21 +2,44 @@
|
|
|
2
2
|
* DEV-only convenience: run the whole vault stack against the software mock
|
|
3
3
|
* YubiKey without hardware. Toggled from wallet-config (DEV builds only).
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* ONE module-held MockYubiKey: its per-serial records (generated keys, PINs)
|
|
6
|
+
* survive toggling the driver off and on within the session, so a vault
|
|
7
|
+
* enrolled with MOCK-DEV-1 and MOCK-DEV-2 can be exercised by switching the
|
|
8
|
+
* "present" key with setMockPresentKey — the DEV wallet-config row's selector.
|
|
8
9
|
* Kept in its own module so driver.ts never imports the mock.
|
|
9
10
|
*/
|
|
10
11
|
import { setMockDriver } from './driver'
|
|
11
12
|
import { MockYubiKey } from './mockYubiKey'
|
|
12
13
|
|
|
14
|
+
export type MockPresentKey = 'MOCK-DEV-1' | 'MOCK-DEV-2' | 'MOCK-DEV-3'
|
|
15
|
+
|
|
16
|
+
let instance: MockYubiKey | null = null
|
|
17
|
+
let present: MockPresentKey = 'MOCK-DEV-1'
|
|
18
|
+
|
|
13
19
|
export function setMockDriverEnabled(on: boolean): void {
|
|
20
|
+
// Keep the software signer unreachable even if a release caller invokes the
|
|
21
|
+
// exported convenience function directly instead of going through the
|
|
22
|
+
// WalletConfigScreen's render gate.
|
|
23
|
+
if (!__DEV__) {
|
|
24
|
+
setMockDriver(null)
|
|
25
|
+
return
|
|
26
|
+
}
|
|
14
27
|
if (on) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
setMockDriver(mock)
|
|
28
|
+
if (!instance) instance = new MockYubiKey()
|
|
29
|
+
instance.insertKey(present)
|
|
30
|
+
setMockDriver(instance)
|
|
19
31
|
} else {
|
|
20
32
|
setMockDriver(null)
|
|
21
33
|
}
|
|
22
34
|
}
|
|
35
|
+
|
|
36
|
+
/** Which of the three dev keys is "held to the phone". Applies immediately
|
|
37
|
+
* when the mock is installed; otherwise remembered for the next enable. */
|
|
38
|
+
export function setMockPresentKey(serial: MockPresentKey): void {
|
|
39
|
+
present = serial
|
|
40
|
+
instance?.insertKey(serial)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function getMockPresentKey(): MockPresentKey {
|
|
44
|
+
return present
|
|
45
|
+
}
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
* "no YubiKey capability on this device", and every caller treats it as such —
|
|
12
12
|
* the vault UI hides, exactly like localpay's getLocalPayTransport() null path.
|
|
13
13
|
*/
|
|
14
|
-
import { Platform } from 'react-native'
|
|
15
14
|
import { vaultErrorFromNative } from './types'
|
|
16
15
|
|
|
17
16
|
export interface KeyEvent {
|
|
@@ -26,44 +25,93 @@ export interface KeyEvent {
|
|
|
26
25
|
|
|
27
26
|
export interface VaultDriver {
|
|
28
27
|
isSupported(): boolean
|
|
29
|
-
/** True when
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
28
|
+
/** True when discovery and the selected device are owned by one ceremony.
|
|
29
|
+
* Real native drivers are always session-based: iOS presents its NFC sheet;
|
|
30
|
+
* Android discovers either USB or NFC for the ceremony and tears both down
|
|
31
|
+
* before releasing the process-wide hardware lease. Test mocks may model a
|
|
32
|
+
* persistent reader. */
|
|
33
33
|
sessionBased: boolean
|
|
34
|
-
|
|
34
|
+
/** Open discovery. `message` is the localised NFC alert text shown on the
|
|
35
|
+
* iOS scan sheet for this session (spec §4.2 step 6); Android and persistent
|
|
36
|
+
* test readers ignore it. */
|
|
37
|
+
start(message?: string): void
|
|
35
38
|
stop(): void
|
|
36
39
|
onKeyEvent(cb: (e: KeyEvent) => void): () => void
|
|
37
40
|
getKeyInfo(): Promise<{ serial: string; firmwareVersion: string; pinRetries: number }>
|
|
38
|
-
verifyPin(pin: string): Promise<{ ok: boolean; retriesLeft: number }>
|
|
39
|
-
changePin(oldPin: string, newPin: string): Promise<{ ok: boolean; retriesLeft: number }>
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
|
|
41
|
+
verifyPin(expectedSerial: string, pin: string): Promise<{ ok: boolean; retriesLeft: number }>
|
|
42
|
+
changePin(expectedSerial: string, oldPin: string, newPin: string): Promise<{ ok: boolean; retriesLeft: number }>
|
|
43
|
+
/** Rotate the PIV unblock code. Neither value may be logged or persisted. */
|
|
44
|
+
changePuk(expectedSerial: string, oldPuk: string, newPuk: string): Promise<{ ok: boolean; retriesLeft: number }>
|
|
45
|
+
/** Authenticate the default management key and reject occupied user slots
|
|
46
|
+
* before global PIV credentials are changed. Explicit replacement may exempt
|
|
47
|
+
* only Vault slot 0x82; every other user slot remains protected. Native also verifies
|
|
48
|
+
* the factory F9 certificate through the pinned production Yubico chain,
|
|
49
|
+
* offline. Never mutates. */
|
|
50
|
+
preflightDedicatedPiv(
|
|
51
|
+
expectedSerial: string,
|
|
52
|
+
allowOccupiedVaultSlot?: boolean
|
|
53
|
+
): Promise<{
|
|
54
|
+
ok: true
|
|
55
|
+
inspection: 'metadata' | 'attestation'
|
|
56
|
+
manufacturerAttestation: 'verified'
|
|
57
|
+
}>
|
|
58
|
+
/** Generate a fresh P-256 key in the fixed Vault slot 0x82, with touch
|
|
59
|
+
* policy CACHED and PIN policy ONCE (spec D6). Native returns only after a
|
|
60
|
+
* same-session manufacturer attestation binds the exact key and policies. */
|
|
61
|
+
generateVaultKey(expectedSerial: string): Promise<{
|
|
62
|
+
publicKey: string
|
|
63
|
+
manufacturerAttestation: 'verified'
|
|
64
|
+
}>
|
|
65
|
+
/**
|
|
66
|
+
* Replace the factory management key with native CSPRNG material and discard
|
|
67
|
+
* it. Called immediately after vault-key generation, in the same session.
|
|
68
|
+
*/
|
|
69
|
+
protectManagementKey(expectedSerial: string): Promise<{ ok: true }>
|
|
70
|
+
/** Reset the entire PIV application to factory state, destroying every key
|
|
71
|
+
* and certificate in it — Vault slot 0x82 included. Both native SDKs block
|
|
72
|
+
* the PIN and PUK before the RESET APDU, so the retry counters are spent
|
|
73
|
+
* whatever the outcome. Never call this for a serial that is already an
|
|
74
|
+
* enrolled vault key; see pivReset.ts. */
|
|
75
|
+
resetPivApplication(expectedSerial: string): Promise<{ ok: true }>
|
|
76
|
+
/** The Vault slot's public key, or null when none can be READ.
|
|
77
|
+
*
|
|
78
|
+
* Null is not proof of an empty slot. iOS cannot read a retired slot's
|
|
79
|
+
* certificate at all and returns null for every 0x82, occupied or not — so
|
|
80
|
+
* "is the slot empty?" must go to `isVaultSlotOccupied`, and callers here
|
|
81
|
+
* only ever use a non-null result to compare against a key they already
|
|
82
|
+
* hold. */
|
|
83
|
+
readVaultPublicKey(expectedSerial: string): Promise<{ publicKey: string } | null>
|
|
84
|
+
/** Whether the Vault slot holds a key, answered by the card on both
|
|
85
|
+
* platforms (iOS attests the slot, Android reads its metadata).
|
|
86
|
+
*
|
|
87
|
+
* FAILS CLOSED: only the card's explicit reference-not-found reports false.
|
|
88
|
+
* An imported key, a missing attestation slot or any other status reports
|
|
89
|
+
* true, because none of them prove the slot empty. */
|
|
90
|
+
isVaultSlotOccupied(expectedSerial: string): Promise<{ occupied: boolean }>
|
|
47
91
|
/** Sign a pre-computed 32-byte digest (64 hex chars) with the slot's P-256
|
|
48
92
|
* key. Returns a DER signature as hex. TOUCH-gated, PIN-gated. */
|
|
49
|
-
signEcdsa(
|
|
93
|
+
signEcdsa(expectedSerial: string, pin: string, digest: string): Promise<{ signature: string }>
|
|
50
94
|
}
|
|
51
95
|
|
|
52
96
|
/** Shape of the native Nitro module (JSON-string API). Kept local so a missing
|
|
53
97
|
* package never breaks the type-check. */
|
|
54
98
|
interface NativeYubiKeyPiv {
|
|
55
99
|
isSupported(): boolean
|
|
56
|
-
startDiscovery(): void
|
|
100
|
+
startDiscovery(message: string): void
|
|
57
101
|
stopDiscovery(): void
|
|
58
102
|
setKeyListener(listener: (eventType: string, serial: string, transport: string) => void): void
|
|
59
103
|
clearKeyListener(): void
|
|
60
104
|
getKeyInfo(): Promise<string>
|
|
61
|
-
verifyPin(pin: string): Promise<string>
|
|
62
|
-
changePin(oldPin: string, newPin: string): Promise<string>
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
105
|
+
verifyPin(expectedSerial: string, pin: string): Promise<string>
|
|
106
|
+
changePin(expectedSerial: string, oldPin: string, newPin: string): Promise<string>
|
|
107
|
+
changePuk(expectedSerial: string, oldPuk: string, newPuk: string): Promise<string>
|
|
108
|
+
preflightDedicatedPiv(expectedSerial: string, allowOccupiedVaultSlot: boolean): Promise<string>
|
|
109
|
+
generateVaultKey(expectedSerial: string): Promise<string>
|
|
110
|
+
protectManagementKey(expectedSerial: string): Promise<string>
|
|
111
|
+
resetPivApplication(expectedSerial: string): Promise<string>
|
|
112
|
+
readVaultPublicKey(expectedSerial: string): Promise<string>
|
|
113
|
+
isVaultSlotOccupied(expectedSerial: string): Promise<string>
|
|
114
|
+
signEcdsa(expectedSerial: string, pin: string, digest: string): Promise<string>
|
|
67
115
|
}
|
|
68
116
|
|
|
69
117
|
let injectedMock: VaultDriver | null = null
|
|
@@ -119,9 +167,11 @@ function adaptNative(native: NativeYubiKeyPiv): VaultDriver {
|
|
|
119
167
|
const listeners = new Set<(e: KeyEvent) => void>()
|
|
120
168
|
return {
|
|
121
169
|
isSupported: () => native.isSupported(),
|
|
122
|
-
//
|
|
123
|
-
|
|
124
|
-
|
|
170
|
+
// Both native implementations scope discovery to one hardware ceremony.
|
|
171
|
+
// Android listens for USB and NFC together, then synchronously tears both
|
|
172
|
+
// down on stop so an NFC device object can never survive into a later run.
|
|
173
|
+
sessionBased: true,
|
|
174
|
+
start: (message?: string) => {
|
|
125
175
|
// (Re)install the native listener each start; it forwards into the
|
|
126
176
|
// persistent JS `listeners` set so app subscribers survive stop/start
|
|
127
177
|
// cycles (a session-based transport starts and stops per ceremony).
|
|
@@ -130,7 +180,7 @@ function adaptNative(native: NativeYubiKeyPiv): VaultDriver {
|
|
|
130
180
|
listeners.forEach(cb => cb(e))
|
|
131
181
|
})
|
|
132
182
|
try {
|
|
133
|
-
native.startDiscovery()
|
|
183
|
+
native.startDiscovery(message ?? '')
|
|
134
184
|
} catch (e) {
|
|
135
185
|
// iOS throws VAULT_ERR:driver-unavailable when NFC reading is
|
|
136
186
|
// unavailable (NFC off, or a wedged nfcd needing a device restart)
|
|
@@ -149,22 +199,26 @@ function adaptNative(native: NativeYubiKeyPiv): VaultDriver {
|
|
|
149
199
|
return () => listeners.delete(cb)
|
|
150
200
|
},
|
|
151
201
|
getKeyInfo: () => parse(native.getKeyInfo()),
|
|
152
|
-
verifyPin: pin => parse(native.verifyPin(pin)),
|
|
153
|
-
changePin: (o, n) => parse(native.changePin(o, n)),
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
//
|
|
158
|
-
//
|
|
159
|
-
//
|
|
160
|
-
//
|
|
161
|
-
generateVaultKey:
|
|
162
|
-
|
|
163
|
-
|
|
202
|
+
verifyPin: (serial, pin) => parse(native.verifyPin(serial, pin)),
|
|
203
|
+
changePin: (serial, o, n) => parse(native.changePin(serial, o, n)),
|
|
204
|
+
changePuk: (serial, o, n) => parse(native.changePuk(serial, o, n)),
|
|
205
|
+
preflightDedicatedPiv: (serial, allowOccupiedVaultSlot = false) =>
|
|
206
|
+
parse(native.preflightDedicatedPiv(serial, allowOccupiedVaultSlot)),
|
|
207
|
+
// 'cached' (spec D6): the card signs every vault input on-chain, up to
|
|
208
|
+
// VAULT_INPUTS_PER_TAP digests per tap, so one touch must cover a batch —
|
|
209
|
+
// the card keeps a touch valid for 15 s. 'always' would need a touch per
|
|
210
|
+
// input. 'once' lets the PIN verified at session start cover the batch.
|
|
211
|
+
generateVaultKey: serial => parse(native.generateVaultKey(serial)),
|
|
212
|
+
protectManagementKey: serial => parse(native.protectManagementKey(serial)),
|
|
213
|
+
resetPivApplication: serial => parse(native.resetPivApplication(serial)),
|
|
214
|
+
readVaultPublicKey: async serial => {
|
|
215
|
+
const r = await parse<{ publicKey: string | null }>(native.readVaultPublicKey(serial))
|
|
164
216
|
return r.publicKey ? { publicKey: r.publicKey } : null
|
|
165
217
|
},
|
|
166
|
-
|
|
167
|
-
|
|
218
|
+
// No `?? true` fallback: a native module too old to implement this would
|
|
219
|
+
// report every slot empty, which is the answer that authorizes an erase.
|
|
220
|
+
isVaultSlotOccupied: serial => parse<{ occupied: boolean }>(native.isVaultSlotOccupied(serial)),
|
|
221
|
+
signEcdsa: (serial, pin, digest) => parse(native.signEcdsa(serial, pin, digest))
|
|
168
222
|
}
|
|
169
223
|
}
|
|
170
224
|
|