toss-expo-sdk 0.1.1 → 1.0.1

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 (93) hide show
  1. package/README.md +490 -81
  2. package/lib/module/ble.js +59 -4
  3. package/lib/module/ble.js.map +1 -1
  4. package/lib/module/client/BLETransactionHandler.js +277 -0
  5. package/lib/module/client/BLETransactionHandler.js.map +1 -0
  6. package/lib/module/client/NonceAccountManager.js +364 -0
  7. package/lib/module/client/NonceAccountManager.js.map +1 -0
  8. package/lib/module/client/TossClient.js +27 -44
  9. package/lib/module/client/TossClient.js.map +1 -1
  10. package/lib/module/contexts/WalletContext.js +4 -4
  11. package/lib/module/contexts/WalletContext.js.map +1 -1
  12. package/lib/module/discovery.js +35 -8
  13. package/lib/module/discovery.js.map +1 -1
  14. package/lib/module/examples/offlinePaymentFlow.js +27 -2
  15. package/lib/module/examples/offlinePaymentFlow.js.map +1 -1
  16. package/lib/module/hooks/useOfflineBLETransactions.js +314 -0
  17. package/lib/module/hooks/useOfflineBLETransactions.js.map +1 -0
  18. package/lib/module/index.js +13 -8
  19. package/lib/module/index.js.map +1 -1
  20. package/lib/module/intent.js +198 -0
  21. package/lib/module/intent.js.map +1 -1
  22. package/lib/module/nfc.js +1 -1
  23. package/lib/module/noise.js +176 -1
  24. package/lib/module/noise.js.map +1 -1
  25. package/lib/module/reconciliation.js +155 -0
  26. package/lib/module/reconciliation.js.map +1 -1
  27. package/lib/module/services/authService.js +164 -1
  28. package/lib/module/services/authService.js.map +1 -1
  29. package/lib/module/storage/secureStorage.js +102 -0
  30. package/lib/module/storage/secureStorage.js.map +1 -1
  31. package/lib/module/storage.js +4 -4
  32. package/lib/module/sync.js +25 -1
  33. package/lib/module/sync.js.map +1 -1
  34. package/lib/module/types/nonceAccount.js +2 -0
  35. package/lib/module/types/nonceAccount.js.map +1 -0
  36. package/lib/module/types/tossUser.js +16 -1
  37. package/lib/module/types/tossUser.js.map +1 -1
  38. package/lib/typescript/src/__tests__/solana-program-simple.test.d.ts +8 -0
  39. package/lib/typescript/src/__tests__/solana-program-simple.test.d.ts.map +1 -0
  40. package/lib/typescript/src/ble.d.ts +31 -2
  41. package/lib/typescript/src/ble.d.ts.map +1 -1
  42. package/lib/typescript/src/client/BLETransactionHandler.d.ts +98 -0
  43. package/lib/typescript/src/client/BLETransactionHandler.d.ts.map +1 -0
  44. package/lib/typescript/src/client/NonceAccountManager.d.ts +82 -0
  45. package/lib/typescript/src/client/NonceAccountManager.d.ts.map +1 -0
  46. package/lib/typescript/src/client/TossClient.d.ts +10 -12
  47. package/lib/typescript/src/client/TossClient.d.ts.map +1 -1
  48. package/lib/typescript/src/discovery.d.ts +8 -2
  49. package/lib/typescript/src/discovery.d.ts.map +1 -1
  50. package/lib/typescript/src/examples/offlinePaymentFlow.d.ts +9 -1
  51. package/lib/typescript/src/examples/offlinePaymentFlow.d.ts.map +1 -1
  52. package/lib/typescript/src/hooks/useOfflineBLETransactions.d.ts +91 -0
  53. package/lib/typescript/src/hooks/useOfflineBLETransactions.d.ts.map +1 -0
  54. package/lib/typescript/src/index.d.ts +11 -4
  55. package/lib/typescript/src/index.d.ts.map +1 -1
  56. package/lib/typescript/src/intent.d.ts +26 -0
  57. package/lib/typescript/src/intent.d.ts.map +1 -1
  58. package/lib/typescript/src/noise.d.ts +62 -0
  59. package/lib/typescript/src/noise.d.ts.map +1 -1
  60. package/lib/typescript/src/reconciliation.d.ts +6 -0
  61. package/lib/typescript/src/reconciliation.d.ts.map +1 -1
  62. package/lib/typescript/src/services/authService.d.ts +26 -1
  63. package/lib/typescript/src/services/authService.d.ts.map +1 -1
  64. package/lib/typescript/src/storage/secureStorage.d.ts +16 -0
  65. package/lib/typescript/src/storage/secureStorage.d.ts.map +1 -1
  66. package/lib/typescript/src/sync.d.ts +6 -1
  67. package/lib/typescript/src/sync.d.ts.map +1 -1
  68. package/lib/typescript/src/types/nonceAccount.d.ts +59 -0
  69. package/lib/typescript/src/types/nonceAccount.d.ts.map +1 -0
  70. package/lib/typescript/src/types/tossUser.d.ts +16 -0
  71. package/lib/typescript/src/types/tossUser.d.ts.map +1 -1
  72. package/package.json +12 -1
  73. package/src/__tests__/reconciliation.test.tsx +7 -1
  74. package/src/__tests__/solana-program-simple.test.ts +256 -0
  75. package/src/ble.ts +105 -4
  76. package/src/client/BLETransactionHandler.ts +364 -0
  77. package/src/client/NonceAccountManager.ts +444 -0
  78. package/src/client/TossClient.ts +36 -49
  79. package/src/contexts/WalletContext.tsx +4 -4
  80. package/src/discovery.ts +46 -8
  81. package/src/examples/offlinePaymentFlow.ts +48 -2
  82. package/src/hooks/useOfflineBLETransactions.ts +438 -0
  83. package/src/index.tsx +49 -7
  84. package/src/intent.ts +254 -0
  85. package/src/nfc.ts +4 -4
  86. package/src/noise.ts +239 -1
  87. package/src/reconciliation.ts +184 -0
  88. package/src/services/authService.ts +188 -1
  89. package/src/storage/secureStorage.ts +142 -4
  90. package/src/storage.ts +4 -4
  91. package/src/sync.ts +40 -0
  92. package/src/types/nonceAccount.ts +75 -0
  93. package/src/types/tossUser.ts +35 -2
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Represents a durable nonce account for offline transaction support
3
+ * Enables secure offline transaction creation with replay protection
4
+ */
5
+ export interface NonceAccountInfo {
6
+ // Account Identity
7
+ address: string; // Public key of the nonce account
8
+ owner: string; // Public key of owner/authority
9
+ authorizedSigner: string; // Public key authorized to use this nonce
10
+
11
+ // Nonce State
12
+ currentNonce: number; // Current nonce value
13
+ lastUsedNonce: number; // Last consumed nonce
14
+ blockhash: string; // Associated blockhash
15
+
16
+ // Security
17
+ isBiometricProtected: boolean; // Requires biometric to use
18
+ createdAt: number; // Unix timestamp
19
+ lastModified: number; // Unix timestamp
20
+
21
+ // Storage
22
+ isStoredSecurely: boolean; // In secure enclave
23
+ encryptedData?: string; // Optional encrypted backup
24
+ minRentLamports?: number; // Minimum rent exemption amount
25
+ status?: 'active' | 'expired' | 'revoked'; // Account lifecycle status
26
+ }
27
+
28
+ /**
29
+ * Options for creating a durable nonce account
30
+ */
31
+ export interface CreateNonceAccountOptions {
32
+ // Biometric & Security
33
+ requireBiometric?: boolean; // Default: true (mandatory)
34
+ securityLevel?: 'standard' | 'high' | 'maximum'; // Default: 'standard'
35
+
36
+ // Nonce Config
37
+ minNonceCount?: number; // Minimum nonces to maintain (default: 1)
38
+ maxNonceCount?: number; // Maximum nonces to cache (default: 100)
39
+
40
+ // Storage
41
+ persistToSecureStorage?: boolean; // Default: true
42
+ allowCloudBackup?: boolean; // Default: false
43
+
44
+ // Lifecycle
45
+ autoRenew?: boolean; // Auto-renew when close to expiry (default: true)
46
+ expiryDays?: number; // Account expiry in days (default: 365)
47
+ }
48
+
49
+ /**
50
+ * Nonce account cache entry for efficient offline usage
51
+ */
52
+ export interface NonceAccountCacheEntry {
53
+ accountInfo: NonceAccountInfo;
54
+ nonces: number[];
55
+ expiresAt: number;
56
+ }
57
+
58
+ /**
59
+ * Represents a transaction prepared for offline use with nonce account
60
+ */
61
+ export interface OfflineTransaction {
62
+ id: string;
63
+ nonceAccount: string;
64
+ nonce: number;
65
+ transaction: string; // Base64 or serialized transaction
66
+ signature?: string;
67
+ status: 'prepared' | 'signed' | 'submitted' | 'confirmed' | 'failed';
68
+ createdAt: number;
69
+ expiresAt: number;
70
+ metadata?: {
71
+ description?: string;
72
+ tags?: string[];
73
+ [key: string]: any;
74
+ };
75
+ }
@@ -2,6 +2,7 @@ import { PublicKey } from '@solana/web3.js';
2
2
 
3
3
  /**
4
4
  * Represents a TOSS wallet user in the ecosystem
5
+ * Enhanced with secure nonce account support for offline transactions
5
6
  */
6
7
  export type TossUser = {
7
8
  // Core Identity
@@ -9,13 +10,22 @@ export type TossUser = {
9
10
  username: string; // @handle format (e.g., '@alice')
10
11
  displayName?: string; // Optional display name
11
12
 
12
- // TOSS Wallet
13
+ // TOSS Wallet (Primary wallet)
13
14
  wallet: {
14
15
  publicKey: PublicKey; // Main wallet address
15
16
  isVerified: boolean; // KYC/verification status
16
17
  createdAt: string; // ISO timestamp
17
18
  };
18
19
 
20
+ // Nonce Account (For offline transactions with replay protection)
21
+ nonceAccount?: {
22
+ address: PublicKey; // Public key of the nonce account
23
+ authorizedSigner: PublicKey; // Public key authorized to use this nonce
24
+ isBiometricProtected: boolean; // Requires biometric authentication
25
+ expiresAt?: number; // Unix timestamp of expiry
26
+ status: 'active' | 'expired' | 'revoked'; // Account status
27
+ };
28
+
19
29
  // Device & Session
20
30
  device: {
21
31
  id: string; // Unique device ID
@@ -24,16 +34,26 @@ export type TossUser = {
24
34
  client: 'mobile' | 'web' | 'desktop';
25
35
  };
26
36
 
37
+ // Security & Biometrics
38
+ security: {
39
+ biometricEnabled: boolean; // Biometric authentication enabled
40
+ biometricSalt?: string; // Salt for biometric derivation
41
+ nonceAccountRequiresBiometric: boolean; // Nonce operations require biometric
42
+ lastBiometricVerification?: number; // Unix timestamp
43
+ };
44
+
27
45
  // Status
28
46
  status: 'active' | 'inactive' | 'restricted';
29
47
  lastSeen: string; // ISO timestamp
30
48
 
31
- // TOSS-specific
49
+ // TOSS-specific Features
32
50
  tossFeatures: {
33
51
  canSend: boolean;
34
52
  canReceive: boolean;
35
53
  isPrivateTxEnabled: boolean;
36
54
  maxTransactionAmount: number; // In lamports
55
+ offlineTransactionsEnabled?: boolean; // Can create offline transactions
56
+ nonceAccountEnabled?: boolean; // Has durable nonce account
37
57
  };
38
58
 
39
59
  // Timestamps
@@ -62,12 +82,23 @@ export const exampleTossUser: TossUser = {
62
82
  isVerified: true,
63
83
  createdAt: '2023-01-01T00:00:00Z',
64
84
  },
85
+ nonceAccount: {
86
+ address: new PublicKey('22222222222222222222222222222222'),
87
+ authorizedSigner: new PublicKey('33333333333333333333333333333333'),
88
+ isBiometricProtected: true,
89
+ status: 'active',
90
+ },
65
91
  device: {
66
92
  id: 'dev_xyz789',
67
93
  name: 'Alice iPhone',
68
94
  lastActive: new Date().toISOString(),
69
95
  client: 'mobile',
70
96
  },
97
+ security: {
98
+ biometricEnabled: true,
99
+ nonceAccountRequiresBiometric: true,
100
+ lastBiometricVerification: Math.floor(Date.now() / 1000),
101
+ },
71
102
  status: 'active',
72
103
  lastSeen: new Date().toISOString(),
73
104
  tossFeatures: {
@@ -75,6 +106,8 @@ export const exampleTossUser: TossUser = {
75
106
  canReceive: true,
76
107
  isPrivateTxEnabled: true,
77
108
  maxTransactionAmount: 1000000000, // 1 SOL in lamports
109
+ offlineTransactionsEnabled: true,
110
+ nonceAccountEnabled: true,
78
111
  },
79
112
  createdAt: '2023-01-01T00:00:00Z',
80
113
  updatedAt: new Date().toISOString(),