toss-expo-sdk 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 (116) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +292 -0
  3. package/lib/module/ble.js +103 -0
  4. package/lib/module/ble.js.map +1 -0
  5. package/lib/module/client/TossClient.js +324 -0
  6. package/lib/module/client/TossClient.js.map +1 -0
  7. package/lib/module/client/index.js +4 -0
  8. package/lib/module/client/index.js.map +1 -0
  9. package/lib/module/contexts/WalletContext.js +99 -0
  10. package/lib/module/contexts/WalletContext.js.map +1 -0
  11. package/lib/module/discovery.js +434 -0
  12. package/lib/module/discovery.js.map +1 -0
  13. package/lib/module/errors.js +47 -0
  14. package/lib/module/errors.js.map +1 -0
  15. package/lib/module/examples/offlinePaymentFlow.js +234 -0
  16. package/lib/module/examples/offlinePaymentFlow.js.map +1 -0
  17. package/lib/module/index.js +32 -0
  18. package/lib/module/index.js.map +1 -0
  19. package/lib/module/intent.js +223 -0
  20. package/lib/module/intent.js.map +1 -0
  21. package/lib/module/intentManager.js +145 -0
  22. package/lib/module/intentManager.js.map +1 -0
  23. package/lib/module/internal/arciumHelper.js +50 -0
  24. package/lib/module/internal/arciumHelper.js.map +1 -0
  25. package/lib/module/nfc.js +54 -0
  26. package/lib/module/nfc.js.map +1 -0
  27. package/lib/module/noise.js +14 -0
  28. package/lib/module/noise.js.map +1 -0
  29. package/lib/module/package.json +1 -0
  30. package/lib/module/qr.js +57 -0
  31. package/lib/module/qr.js.map +1 -0
  32. package/lib/module/reconciliation.js +329 -0
  33. package/lib/module/reconciliation.js.map +1 -0
  34. package/lib/module/services/authService.js +205 -0
  35. package/lib/module/services/authService.js.map +1 -0
  36. package/lib/module/storage/secureStorage.js +89 -0
  37. package/lib/module/storage/secureStorage.js.map +1 -0
  38. package/lib/module/storage.js +16 -0
  39. package/lib/module/storage.js.map +1 -0
  40. package/lib/module/sync.js +64 -0
  41. package/lib/module/sync.js.map +1 -0
  42. package/lib/module/types/tossUser.js +41 -0
  43. package/lib/module/types/tossUser.js.map +1 -0
  44. package/lib/module/utils/nonceUtils.js +38 -0
  45. package/lib/module/utils/nonceUtils.js.map +1 -0
  46. package/lib/typescript/package.json +1 -0
  47. package/lib/typescript/src/__tests__/index.test.d.ts +1 -0
  48. package/lib/typescript/src/__tests__/index.test.d.ts.map +1 -0
  49. package/lib/typescript/src/__tests__/reconciliation.test.d.ts +6 -0
  50. package/lib/typescript/src/__tests__/reconciliation.test.d.ts.map +1 -0
  51. package/lib/typescript/src/ble.d.ts +10 -0
  52. package/lib/typescript/src/ble.d.ts.map +1 -0
  53. package/lib/typescript/src/client/TossClient.d.ts +110 -0
  54. package/lib/typescript/src/client/TossClient.d.ts.map +1 -0
  55. package/lib/typescript/src/client/index.d.ts +3 -0
  56. package/lib/typescript/src/client/index.d.ts.map +1 -0
  57. package/lib/typescript/src/contexts/WalletContext.d.ts +20 -0
  58. package/lib/typescript/src/contexts/WalletContext.d.ts.map +1 -0
  59. package/lib/typescript/src/discovery.d.ts +188 -0
  60. package/lib/typescript/src/discovery.d.ts.map +1 -0
  61. package/lib/typescript/src/errors.d.ts +27 -0
  62. package/lib/typescript/src/errors.d.ts.map +1 -0
  63. package/lib/typescript/src/examples/offlinePaymentFlow.d.ts +48 -0
  64. package/lib/typescript/src/examples/offlinePaymentFlow.d.ts.map +1 -0
  65. package/lib/typescript/src/index.d.ts +13 -0
  66. package/lib/typescript/src/index.d.ts.map +1 -0
  67. package/lib/typescript/src/intent.d.ts +84 -0
  68. package/lib/typescript/src/intent.d.ts.map +1 -0
  69. package/lib/typescript/src/intentManager.d.ts +46 -0
  70. package/lib/typescript/src/intentManager.d.ts.map +1 -0
  71. package/lib/typescript/src/internal/arciumHelper.d.ts +19 -0
  72. package/lib/typescript/src/internal/arciumHelper.d.ts.map +1 -0
  73. package/lib/typescript/src/nfc.d.ts +7 -0
  74. package/lib/typescript/src/nfc.d.ts.map +1 -0
  75. package/lib/typescript/src/noise.d.ts +5 -0
  76. package/lib/typescript/src/noise.d.ts.map +1 -0
  77. package/lib/typescript/src/qr.d.ts +6 -0
  78. package/lib/typescript/src/qr.d.ts.map +1 -0
  79. package/lib/typescript/src/reconciliation.d.ts +65 -0
  80. package/lib/typescript/src/reconciliation.d.ts.map +1 -0
  81. package/lib/typescript/src/services/authService.d.ts +55 -0
  82. package/lib/typescript/src/services/authService.d.ts.map +1 -0
  83. package/lib/typescript/src/storage/secureStorage.d.ts +7 -0
  84. package/lib/typescript/src/storage/secureStorage.d.ts.map +1 -0
  85. package/lib/typescript/src/storage.d.ts +4 -0
  86. package/lib/typescript/src/storage.d.ts.map +1 -0
  87. package/lib/typescript/src/sync.d.ts +40 -0
  88. package/lib/typescript/src/sync.d.ts.map +1 -0
  89. package/lib/typescript/src/types/tossUser.d.ts +39 -0
  90. package/lib/typescript/src/types/tossUser.d.ts.map +1 -0
  91. package/lib/typescript/src/utils/nonceUtils.d.ts +8 -0
  92. package/lib/typescript/src/utils/nonceUtils.d.ts.map +1 -0
  93. package/package.json +176 -0
  94. package/src/__tests__/index.test.tsx +1 -0
  95. package/src/__tests__/reconciliation.test.tsx +361 -0
  96. package/src/ble.ts +138 -0
  97. package/src/client/TossClient.ts +435 -0
  98. package/src/client/index.ts +2 -0
  99. package/src/contexts/WalletContext.tsx +127 -0
  100. package/src/discovery.ts +542 -0
  101. package/src/errors.ts +51 -0
  102. package/src/examples/offlinePaymentFlow.ts +331 -0
  103. package/src/index.tsx +61 -0
  104. package/src/intent.ts +328 -0
  105. package/src/intentManager.ts +164 -0
  106. package/src/internal/arciumHelper.ts +58 -0
  107. package/src/nfc.ts +57 -0
  108. package/src/noise.ts +9 -0
  109. package/src/qr.tsx +65 -0
  110. package/src/reconciliation.ts +421 -0
  111. package/src/services/authService.ts +238 -0
  112. package/src/storage/secureStorage.ts +100 -0
  113. package/src/storage.ts +17 -0
  114. package/src/sync.ts +101 -0
  115. package/src/types/tossUser.ts +81 -0
  116. package/src/utils/nonceUtils.ts +56 -0
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Transaction","bs58","verifyIntentSignature","intent","serialized","tx","from","Buffer","decode","verifySignatures","error","console","isIntentExpired","Date","now","expiry","updateIntentStatus","status","updatedAt","Math","floor","validateIntent","currentBlockhash","valid","blockhash","processIntentsForSync","intents","connection","getRecentBlockhash","Promise","all","map","validation","Error","message","filterExpiredIntents","expired","push"],"sourceRoot":"../../src","sources":["intentManager.ts"],"mappings":";;AAAA,SAASA,WAAW,QAAQ,iBAAiB;AAC7C,OAAOC,IAAI,MAAM,MAAM;AAGvB;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CAACC,MAAoB,EAAW;EACnE,IAAI;IACF;IACA,IAAI,CAACA,MAAM,CAACC,UAAU,EAAE;MACtB,OAAO,KAAK;IACd;;IAEA;IACA,MAAMC,EAAE,GAAGL,WAAW,CAACM,IAAI,CAACC,MAAM,CAACD,IAAI,CAACL,IAAI,CAACO,MAAM,CAACL,MAAM,CAACC,UAAU,CAAC,CAAC,CAAC;;IAExE;IACA,OAAOC,EAAE,CAACI,gBAAgB,CAAC,CAAC;EAC9B,CAAC,CAAC,OAAOC,KAAK,EAAE;IACdC,OAAO,CAACD,KAAK,CAAC,mCAAmC,EAAEA,KAAK,CAAC;IACzD,OAAO,KAAK;EACd;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,eAAeA,CAACT,MAAoB,EAAW;EAC7D,OAAOU,IAAI,CAACC,GAAG,CAAC,CAAC,GAAG,IAAI,GAAGX,MAAM,CAACY,MAAM;AAC1C;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CAChCb,MAAoB,EACpBc,MAAoB,EACpBP,KAAc,EACA;EACd,OAAO;IACL,GAAGP,MAAM;IACTc,MAAM;IACNC,SAAS,EAAEC,IAAI,CAACC,KAAK,CAACP,IAAI,CAACC,GAAG,CAAC,CAAC,GAAG,IAAI,C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MAAM,EAAE,SAAS,CAAC;IAC9C,CAAC,CAAC,OAAOO,KAAK,EAAE;MACd,OAAOM,kBAAkB,CACvBb,MAAM,EACN,QAAQ,EACRO,KAAK,YAAYuB,KAAK,GAAGvB,KAAK,CAACwB,OAAO,GAAG,eAC3C,CAAC;IACH;EACF,CAAC,CACH,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,oBAAoBA,CAClCT,OAAuB,EACW;EAClC,MAAMH,KAAqB,GAAG,EAAE;EAChC,MAAMa,OAAuB,GAAG,EAAE;EAElC,KAAK,MAAMjC,MAAM,IAAIuB,OAAO,EAAE;IAC5B,IAAId,eAAe,CAACT,MAAM,CAAC,EAAE;MAC3BiC,OAAO,CAACC,IAAI,CAACrB,kBAAkB,CAACb,MAAM,EAAE,SAAS,CAAC,CAAC;IACrD,CAAC,MAAM;MACLoB,KAAK,CAACc,IAAI,CAAClC,MAAM,CAAC;IACpB;EACF;EAEA,OAAO,CAACoB,KAAK,EAAEa,OAAO,CAAC;AACzB","ignoreList":[]}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ // import {
4
+ // getArciumEnv,
5
+ // x25519,
6
+ // getMXEPublicKey,
7
+ // RescueCipher,
8
+ // } from "@arcium-hq/client";
9
+ import * as Arcium from '@arcium-hq/client';
10
+
11
+ /**
12
+ * Output from Arcium encryption (internal only)
13
+ */
14
+
15
+ /**
16
+ * Internal helper to encrypt a set of numeric values with Arcium.
17
+ * Does not leak anything about Arcium to the SDK consumer.
18
+ *
19
+ * @param mxeProgramId PublicKey of the MXE
20
+ * @param plaintextValues numeric values for encryption
21
+ * @param provider Solana provider (e.g., AnchorProvider)
22
+ */
23
+ export async function encryptForArciumInternal(mxeProgramId, plaintextValues, provider) {
24
+ // Required by the Arcium client before encryption
25
+ Arcium.getArciumEnv();
26
+
27
+ // 1) Generate a random x25519 keypair
28
+ const privateKey = Arcium.x25519.utils.randomSecretKey();
29
+ const publicKey = Arcium.x25519.getPublicKey(privateKey);
30
+
31
+ // 2) Fetch the MXE's public encryption key using the provided provider
32
+ const mxePubKey = await Arcium.getMXEPublicKey(provider, mxeProgramId);
33
+ if (!mxePubKey) {
34
+ throw new Error('MXE public key not found for Arcium encryption');
35
+ }
36
+
37
+ // 3) Derive DH shared secret
38
+ const sharedSecret = Arcium.x25519.getSharedSecret(privateKey, mxePubKey);
39
+
40
+ // 4) Build the cipher and encrypt the data
41
+ const cipher = new Arcium.RescueCipher(sharedSecret);
42
+ const nonce = crypto.getRandomValues(new Uint8Array(16));
43
+ const ciphertext = cipher.encrypt(plaintextValues, nonce);
44
+ return {
45
+ ciphertext,
46
+ publicKey,
47
+ nonce
48
+ };
49
+ }
50
+ //# sourceMappingURL=arciumHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Arcium","encryptForArciumInternal","mxeProgramId","plaintextValues","provider","getArciumEnv","privateKey","x25519","utils","randomSecretKey","publicKey","getPublicKey","mxePubKey","getMXEPublicKey","Error","sharedSecret","getSharedSecret","cipher","RescueCipher","nonce","crypto","getRandomValues","Uint8Array","ciphertext","encrypt"],"sourceRoot":"../../../src","sources":["internal/arciumHelper.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,KAAKA,MAAM,MAAM,mBAAmB;;AAG3C;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,wBAAwBA,CAC5CC,YAAuB,EACvBC,eAAyB,EACzBC,QAAa,EACmB;EAChC;EACAJ,MAAM,CAACK,YAAY,CAAC,CAAC;;EAErB;EACA,MAAMC,UAAU,GAAGN,MAAM,CAACO,MAAM,CAACC,KAAK,CAACC,eAAe,CAAC,CAAC;EACxD,MAAMC,SAAS,GAAGV,MAAM,CAACO,MAAM,CAACI,YAAY,CAACL,UAAU,CAAC;;EAExD;EACA,MAAMM,SAAS,GAAG,MAAMZ,MAAM,CAACa,eAAe,CAACT,QAAQ,EAAEF,YAAY,CAAC;EAEtE,IAAI,CAACU,SAAS,EAAE;IACd,MAAM,IAAIE,KAAK,CAAC,gDAAgD,CAAC;EACnE;;EAEA;EACA,MAAMC,YAAY,GAAGf,MAAM,CAACO,MAAM,CAACS,eAAe,CAACV,UAAU,EAAEM,SAAS,CAAC;;EAEzE;EACA,MAAMK,MAAM,GAAG,IAAIjB,MAAM,CAACkB,YAAY,CAACH,YAAY,CAAC;EACpD,MAAMI,KAAK,GAAGC,MAAM,CAACC,eAAe,CAAC,IAAIC,UAAU,CAAC,EAAE,CAAC,CAAC;EACxD,MAAMC,UAAU,GAAGN,MAAM,CAACO,OAAO,CAACrB,eAAe,EAAEgB,KAAK,CAAC;EAEzD,OAAO;IACLI,UAAU;IACVb,SAAS;IACTS;EACF,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ // src/nfc.ts
4
+ import NfcManager, { NfcTech, Ndef } from "react-native-nfc-manager";
5
+ // Start the manager
6
+ export function initNFC() {
7
+ return NfcManager.start();
8
+ }
9
+
10
+ // Read NFC tag containing a TossUser
11
+ export async function readNFCUser() {
12
+ try {
13
+ await NfcManager.requestTechnology(NfcTech.Ndef);
14
+ const tag = await NfcManager.getTag();
15
+ await NfcManager.cancelTechnologyRequest();
16
+ if (!tag?.ndefMessage?.[0]?.payload) {
17
+ throw new Error('No NDEF message found');
18
+ }
19
+ const message = Ndef.uri.decodePayload(tag.ndefMessage[0].payload);
20
+ return JSON.parse(message);
21
+ } catch (ex) {
22
+ await NfcManager.cancelTechnologyRequest();
23
+ throw new Error(`Failed to read user from NFC: ${String(ex)}`);
24
+ }
25
+ }
26
+ export async function writeUserToNFC(user) {
27
+ try {
28
+ await NfcManager.requestTechnology(NfcTech.Ndef);
29
+ const jsonUser = JSON.stringify(user);
30
+ const bytes = Ndef.encodeMessage([Ndef.uriRecord(jsonUser)]);
31
+ await NfcManager.ndefHandler.writeNdefMessage(bytes);
32
+ await NfcManager.cancelTechnologyRequest();
33
+ return true;
34
+ } catch (ex) {
35
+ await NfcManager.cancelTechnologyRequest();
36
+ throw new Error(`Failed to write user to NFC: ${String(ex)}`);
37
+ }
38
+ }
39
+
40
+ // Write SolanaIntent to NFC tag
41
+ export async function writeIntentToNFC(intent) {
42
+ try {
43
+ await NfcManager.requestTechnology(NfcTech.Ndef);
44
+ const jsonIntent = JSON.stringify(intent);
45
+ const bytes = Ndef.encodeMessage([Ndef.uriRecord(jsonIntent)]);
46
+ await NfcManager.ndefHandler.writeNdefMessage(bytes);
47
+ await NfcManager.cancelTechnologyRequest();
48
+ return true;
49
+ } catch (ex) {
50
+ await NfcManager.cancelTechnologyRequest();
51
+ throw new Error(`Failed to write intent to NFC: ${String(ex)}`);
52
+ }
53
+ }
54
+ //# sourceMappingURL=nfc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NfcManager","NfcTech","Ndef","initNFC","start","readNFCUser","requestTechnology","tag","getTag","cancelTechnologyRequest","ndefMessage","payload","Error","message","uri","decodePayload","JSON","parse","ex","String","writeUserToNFC","user","jsonUser","stringify","bytes","encodeMessage","uriRecord","ndefHandler","writeNdefMessage","writeIntentToNFC","intent","jsonIntent"],"sourceRoot":"../../src","sources":["nfc.ts"],"mappings":";;AAAA;AACA,OAAOA,UAAU,IAAIC,OAAO,EAAEC,IAAI,QAAQ,0BAA0B;AAIpE;AACA,OAAO,SAASC,OAAOA,CAAA,EAAG;EACxB,OAAOH,UAAU,CAACI,KAAK,CAAC,CAAC;AAC3B;;AAEA;AACA,OAAO,eAAeC,WAAWA,CAAA,EAAsB;EACrD,IAAI;IACF,MAAML,UAAU,CAACM,iBAAiB,CAACL,OAAO,CAACC,IAAI,CAAC;IAChD,MAAMK,GAAG,GAAG,MAAMP,UAAU,CAACQ,MAAM,CAAC,CAAC;IACrC,MAAMR,UAAU,CAACS,uBAAuB,CAAC,CAAC;IAE1C,IAAI,CAACF,GAAG,EAAEG,WAAW,GAAG,CAAC,CAAC,EAAEC,OAAO,EAAE;MACnC,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,aAAa,CAAC,CAACvB,IAAI,CAACwB,SAAS,CAACK,UAAU,CAAC,CAAC,CAAC;IAC9D,MAAM/B,UAAU,CAAC2B,WAAW,CAACC,gBAAgB,CAACJ,KAAK,CAAC;IACpD,MAAMxB,UAAU,CAACS,uBAAuB,CAAC,CAAC;IAC1C,OAAO,IAAI;EACb,CAAC,CAAC,OAAOS,EAAW,EAAE;IACpB,MAAMlB,UAAU,CAACS,uBAAuB,CAAC,CAAC;IAC1C,MAAM,IAAIG,KAAK,CAAC,kCAAkCO,MAAM,CAACD,EAAE,CAAC,EAAE,CAAC;EACjE;AACF","ignoreList":[]}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ import { noise } from "@chainsafe/libp2p-noise";
4
+
5
+ /**
6
+ * Initialize Noise secure session with a static key.
7
+ */
8
+ export function initNoiseSession(staticKey) {
9
+ const ns = noise({
10
+ staticNoiseKey: staticKey
11
+ });
12
+ return ns;
13
+ }
14
+ //# sourceMappingURL=noise.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["noise","initNoiseSession","staticKey","ns","staticNoiseKey"],"sourceRoot":"../../src","sources":["noise.ts"],"mappings":";;AAAA,SAASA,KAAK,QAAQ,yBAAyB;;AAE/C;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAACC,SAAqB,EAAE;EACtD,MAAMC,EAAE,GAAGH,KAAK,CAAC;IAAEI,cAAc,EAAEF;EAAU,CAAC,CAAC;EAC/C,OAAOC,EAAE;AACX","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ import { View, StyleSheet, Text } from 'react-native';
4
+ import { Camera, useCameraDevice, useCameraPermission, useCodeScanner } from 'react-native-vision-camera';
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ export function QRScanner({
7
+ onScan
8
+ }) {
9
+ const device = useCameraDevice('back');
10
+ const permission = useCameraPermission();
11
+ const codeScanner = useCodeScanner({
12
+ codeTypes: ['qr'],
13
+ // ✅ correct CodeType
14
+ onCodeScanned: codes => {
15
+ const code = codes[0];
16
+ if (!code?.value) return; // ✅ undefined-safe
17
+
18
+ onScan(code.value);
19
+ }
20
+ });
21
+ if (!permission.hasPermission) {
22
+ return /*#__PURE__*/_jsx(View, {
23
+ style: styles.center,
24
+ children: /*#__PURE__*/_jsx(Text, {
25
+ children: "Camera permission not granted"
26
+ })
27
+ });
28
+ }
29
+ if (!device) {
30
+ return /*#__PURE__*/_jsx(View, {
31
+ style: styles.center,
32
+ children: /*#__PURE__*/_jsx(Text, {
33
+ children: "Camera not available"
34
+ })
35
+ });
36
+ }
37
+ return /*#__PURE__*/_jsx(View, {
38
+ style: styles.container,
39
+ children: /*#__PURE__*/_jsx(Camera, {
40
+ style: StyleSheet.absoluteFill,
41
+ device: device,
42
+ isActive: true,
43
+ codeScanner: codeScanner
44
+ })
45
+ });
46
+ }
47
+ const styles = StyleSheet.create({
48
+ container: {
49
+ flex: 1
50
+ },
51
+ center: {
52
+ flex: 1,
53
+ alignItems: 'center',
54
+ justifyContent: 'center'
55
+ }
56
+ });
57
+ //# sourceMappingURL=qr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["View","StyleSheet","Text","Camera","useCameraDevice","useCameraPermission","useCodeScanner","jsx","_jsx","QRScanner","onScan","device","permission","codeScanner","codeTypes","onCodeScanned","codes","code","value","hasPermission","style","styles","center","children","container","absoluteFill","isActive","create","flex","alignItems","justifyContent"],"sourceRoot":"../../src","sources":["qr.tsx"],"mappings":";;AAAA,SAASA,IAAI,EAAEC,UAAU,EAAEC,IAAI,QAAQ,cAAc;AACrD,SACEC,MAAM,EACNC,eAAe,EACfC,mBAAmB,EACnBC,cAAc,QAET,4BAA4B;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAMpC,OAAO,SAASC,SAASA,CAAC;EAAEC;AAAuB,CAAC,EAAE;EACpD,MAAMC,MAAM,GAAGP,eAAe,CAAC,MAAM,CAAC;EACtC,MAA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
+ "use strict";
2
+
3
+ /**
4
+ * Reconciliation and Settlement Module for TOSS
5
+ *
6
+ * Implements Section 9-10 of the TOSS Technical Paper:
7
+ * - Synchronisation and reconciliation with onchain state
8
+ * - Deterministic failure handling
9
+ * - Conflict resolution
10
+ */
11
+
12
+ import { PublicKey, Transaction, SystemProgram } from '@solana/web3.js';
13
+ import { isIntentExpired } from "./intent.js";
14
+ import { secureStoreIntent, getAllSecureIntents } from "./storage/secureStorage.js";
15
+ import { TossError, NetworkError } from "./errors.js";
16
+
17
+ /**
18
+ * Result of intent settlement attempt
19
+ */
20
+
21
+ /**
22
+ * State of a device's reconciliation with onchain
23
+ */
24
+
25
+ /**
26
+ * Validates an intent can be settled with current onchain state
27
+ */
28
+ export async function validateIntentOnchain(intent, connection) {
29
+ try {
30
+ // Check if intent has expired
31
+ if (isIntentExpired(intent)) {
32
+ return {
33
+ valid: false,
34
+ error: 'Intent has expired'
35
+ };
36
+ }
37
+
38
+ // Fetch sender account info
39
+ const senderPublicKey = new PublicKey(intent.from);
40
+ const senderAccountInfo = await connection.getAccountInfo(senderPublicKey);
41
+ if (!senderAccountInfo) {
42
+ return {
43
+ valid: false,
44
+ error: 'Sender account does not exist'
45
+ };
46
+ }
47
+
48
+ // Validate sender has sufficient balance
49
+ if (senderAccountInfo.lamports < intent.amount) {
50
+ return {
51
+ valid: false,
52
+ error: `Insufficient balance: have ${senderAccountInfo.lamports}, need ${intent.amount}`
53
+ };
54
+ }
55
+
56
+ // Validate recipient exists (if not a system account)
57
+ const recipientPublicKey = new PublicKey(intent.to);
58
+ const recipientAccountInfo = await connection.getAccountInfo(recipientPublicKey);
59
+ if (!recipientAccountInfo && intent.amount > 0) {
60
+ // Recipient account doesn't exist - this is okay, will be created by transfer
61
+ // But we should verify it's a valid public key format (already done above)
62
+ }
63
+
64
+ // Fetch recent transactions to check for double-spend
65
+ const signatures = await connection.getSignaturesForAddress(senderPublicKey, {
66
+ limit: 100
67
+ });
68
+
69
+ // Check if this nonce has been used recently
70
+ for (const sig of signatures) {
71
+ const tx = await connection.getParsedTransaction(sig.signature);
72
+ if (tx?.transaction.message) {
73
+ // Check if nonce matches and transaction was successful
74
+ const instructions = tx.transaction.message.instructions;
75
+ for (const instruction of instructions) {
76
+ // Look for SystemProgram transfers with same nonce
77
+ if ('parsed' in instruction && instruction.parsed?.type === 'transfer') {
78
+ const parsedIx = instruction.parsed;
79
+ if (parsedIx.info?.source === intent.from && parsedIx.info?.destination === intent.to) {
80
+ // Check if this is a duplicate
81
+ if (tx.slot && tx.blockTime) {
82
+ const timeDiff = Math.floor(Date.now() / 1000) - tx.blockTime;
83
+ // If transaction was confirmed within the nonce window, it's a potential conflict
84
+ if (timeDiff < 5 * 60) {
85
+ return {
86
+ valid: false,
87
+ error: `Potential double-spend detected: similar transaction already confirmed`
88
+ };
89
+ }
90
+ }
91
+ }
92
+ }
93
+ }
94
+ }
95
+ }
96
+ return {
97
+ valid: true
98
+ };
99
+ } catch (error) {
100
+ return {
101
+ valid: false,
102
+ error: `Onchain validation failed: ${error instanceof Error ? error.message : String(error)}`
103
+ };
104
+ }
105
+ }
106
+
107
+ /**
108
+ * Builds a Solana transaction from an intent
109
+ */
110
+ export async function buildTransactionFromIntent(intent, connection, feePayer) {
111
+ try {
112
+ const senderPublicKey = new PublicKey(intent.from);
113
+ const recipientPublicKey = new PublicKey(intent.to);
114
+ const feePayerPubkey = feePayer || senderPublicKey;
115
+
116
+ // Get latest blockhash
117
+ const {
118
+ blockhash,
119
+ lastValidBlockHeight
120
+ } = await connection.getLatestBlockhash('confirmed');
121
+
122
+ // Create transfer instruction
123
+ const transferInstruction = SystemProgram.transfer({
124
+ fromPubkey: senderPublicKey,
125
+ toPubkey: recipientPublicKey,
126
+ lamports: intent.amount
127
+ });
128
+
129
+ // Create transaction
130
+ const transaction = new Transaction();
131
+ transaction.add(transferInstruction);
132
+
133
+ // If using nonce account, add nonce advance instruction
134
+ if (intent.nonceAccount && intent.nonceAuth) {
135
+ const nonceAccountPubkey = new PublicKey(intent.nonceAccount);
136
+ const nonceAuthPubkey = new PublicKey(intent.nonceAuth);
137
+ const nonceAdvanceInstruction = SystemProgram.nonceAdvance({
138
+ noncePubkey: nonceAccountPubkey,
139
+ authorizedPubkey: nonceAuthPubkey
140
+ });
141
+ transaction.add(nonceAdvanceInstruction);
142
+ }
143
+ transaction.feePayer = feePayerPubkey;
144
+ transaction.recentBlockhash = blockhash;
145
+ transaction.lastValidBlockHeight = lastValidBlockHeight;
146
+ return transaction;
147
+ } catch (error) {
148
+ throw new TossError(`Failed to build transaction from intent: ${error instanceof Error ? error.message : String(error)}`, 'TRANSACTION_BUILD_FAILED');
149
+ }
150
+ }
151
+
152
+ /**
153
+ * Submits a transaction to the network with confirmation
154
+ */
155
+ export async function submitTransactionToChain(transaction, connection, maxRetries = 3) {
156
+ let lastError = null;
157
+ for (let attempt = 1; attempt <= maxRetries; attempt++) {
158
+ try {
159
+ // Serialize and send transaction
160
+ const rawTransaction = transaction.serialize();
161
+ const signature = await connection.sendRawTransaction(rawTransaction, {
162
+ skipPreflight: false,
163
+ preflightCommitment: 'confirmed'
164
+ });
165
+
166
+ // Wait for confirmation
167
+ const confirmation = await connection.confirmTransaction(signature, 'confirmed');
168
+ if (confirmation.value.err) {
169
+ throw new Error(`Transaction failed: ${JSON.stringify(confirmation.value.err)}`);
170
+ }
171
+ return signature;
172
+ } catch (error) {
173
+ lastError = error;
174
+
175
+ // Don't retry if it's a signature error (transaction already processed)
176
+ if (lastError.message?.includes('Signature verification failed')) {
177
+ throw lastError;
178
+ }
179
+
180
+ // Exponential backoff
181
+ if (attempt < maxRetries) {
182
+ const delay = 1000 * Math.pow(2, attempt - 1);
183
+ await new Promise(resolve => setTimeout(resolve, delay));
184
+ }
185
+ }
186
+ }
187
+ throw new NetworkError(`Failed to submit transaction after ${maxRetries} attempts: ${lastError?.message}`, {
188
+ context: 'submitTransactionToChain',
189
+ cause: lastError
190
+ });
191
+ }
192
+
193
+ /**
194
+ * Attempts to settle a single intent and returns the result
195
+ */
196
+ export async function settleIntent(intent, connection, feePayer) {
197
+ const timestamp = Math.floor(Date.now() / 1000);
198
+ try {
199
+ // Validate intent against onchain state
200
+ const validation = await validateIntentOnchain(intent, connection);
201
+ if (!validation.valid) {
202
+ return {
203
+ intentId: intent.id,
204
+ status: 'rejected',
205
+ error: validation.error,
206
+ timestamp
207
+ };
208
+ }
209
+
210
+ // Build transaction from intent
211
+ const transaction = await buildTransactionFromIntent(intent, connection, feePayer);
212
+
213
+ // Submit transaction to chain
214
+ const signature = await submitTransactionToChain(transaction, connection);
215
+ return {
216
+ intentId: intent.id,
217
+ status: 'success',
218
+ signature,
219
+ timestamp
220
+ };
221
+ } catch (error) {
222
+ return {
223
+ intentId: intent.id,
224
+ status: 'failed',
225
+ error: error instanceof Error ? error.message : String(error),
226
+ timestamp
227
+ };
228
+ }
229
+ }
230
+
231
+ /**
232
+ * Core reconciliation: process all pending intents for settlement
233
+ */
234
+ export async function reconcilePendingIntents(connection, feePayer) {
235
+ try {
236
+ // Fetch all pending intents from storage
237
+ const allIntents = await getAllSecureIntents();
238
+ const pendingIntents = allIntents.filter(i => i.status === 'pending');
239
+ if (pendingIntents.length === 0) {
240
+ return [];
241
+ }
242
+
243
+ // Sort by creation time to maintain ordering
244
+ pendingIntents.sort((a, b) => a.createdAt - b.createdAt);
245
+
246
+ // Settle each intent and collect results
247
+ const settlementResults = [];
248
+ for (const intent of pendingIntents) {
249
+ const result = await settleIntent(intent, connection, feePayer);
250
+ settlementResults.push(result);
251
+
252
+ // Update intent status based on settlement result
253
+ let newStatus;
254
+ let error;
255
+ switch (result.status) {
256
+ case 'success':
257
+ newStatus = 'settled';
258
+ break;
259
+ case 'rejected':
260
+ newStatus = 'failed';
261
+ error = result.error;
262
+ break;
263
+ case 'failed':
264
+ newStatus = 'failed';
265
+ error = result.error;
266
+ break;
267
+ }
268
+
269
+ // Update the intent in storage
270
+ const updatedIntent = {
271
+ ...intent,
272
+ status: newStatus,
273
+ updatedAt: Math.floor(Date.now() / 1000),
274
+ error,
275
+ signatures: result.signature ? [result.signature] : undefined
276
+ };
277
+ await secureStoreIntent(updatedIntent);
278
+ }
279
+ return settlementResults;
280
+ } catch (error) {
281
+ throw new NetworkError(`Reconciliation failed: ${error instanceof Error ? error.message : String(error)}`, {
282
+ cause: error
283
+ });
284
+ }
285
+ }
286
+
287
+ /**
288
+ * Detects conflicts between local intents and onchain state
289
+ */
290
+ export async function detectConflicts(connection) {
291
+ const conflicts = [];
292
+ try {
293
+ const allIntents = await getAllSecureIntents();
294
+ for (const intent of allIntents) {
295
+ // Skip already settled or failed intents
296
+ if (intent.status !== 'pending') continue;
297
+
298
+ // Check for conflicts
299
+ const validation = await validateIntentOnchain(intent, connection);
300
+ if (!validation.valid) {
301
+ conflicts.push({
302
+ intentId: intent.id,
303
+ conflict: validation.error || 'Unknown conflict'
304
+ });
305
+ }
306
+ }
307
+ return conflicts;
308
+ } catch (error) {
309
+ throw new NetworkError('Conflict detection failed', {
310
+ cause: error
311
+ });
312
+ }
313
+ }
314
+
315
+ /**
316
+ * Gets reconciliation state summary
317
+ */
318
+ export async function getReconciliationState(connection) {
319
+ const allIntents = await getAllSecureIntents();
320
+ const slot = await connection.getSlot('confirmed');
321
+ return {
322
+ lastSyncTime: Math.floor(Date.now() / 1000),
323
+ lastSyncSlot: slot,
324
+ processedIntents: allIntents.filter(i => i.status === 'settled').map(i => i.id),
325
+ failedIntents: allIntents.filter(i => i.status === 'failed').map(i => i.id),
326
+ conflictingIntents: allIntents.filter(i => isIntentExpired(i) && i.status === 'pending').map(i => i.id)
327
+ };
328
+ }
329
+ //# sourceMappingURL=reconciliation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["PublicKey","Transaction","SystemProgram","isIntentExpired","secureStoreIntent","getAllSecureIntents","TossError","NetworkError","validateIntentOnchain","intent","connection","valid","error","senderPublicKey","from","senderAccountInfo","getAccountInfo","lamports","amount","recipientPublicKey","to","recipientAccountInfo","signatures","getSignaturesForAddress","limit","sig","tx","getParsedTransaction","signature","transaction","message","instructions","instruction","parsed","type","parsedIx","info","source","destination","slot","blockTime","timeDiff","Math","floor","Date","now","Error","String","buildTransactionFromIntent","feePayer","feePayerPubkey","blockhash","lastValidBlockHeight","getLatestBlockhash","transferInstruction","transfer","fromPubkey","toPubkey","add","nonceAccount","nonceAuth","nonceAccountPubkey","nonceAuthPubkey","nonceAdvanceInstruction","nonceAdvance","noncePubkey","authorizedPubkey","recentBlockhash","submitTransactionToChain","maxRetries","lastError","attempt","rawTransaction","serialize","sendRawTransaction","skipPreflight","preflightCommitment","confirmation","confirmTransaction","value","err","JSON","stringify","includes","delay","pow","Promise","resolve","setTimeout","context","cause","settleIntent","timestamp","validation","intentId","id","status","reconcilePendingIntents","allIntents","pendingIntents","filter","i","length","sort","a","b","createdAt","settlementResults","result","push","newStatus","updatedIntent","updatedAt","undefined","detectConflicts","conflicts","conflict","getReconciliationState","getSlot","lastSyncTime","lastSyncSlot","processedIntents","map","failedIntents","conflictingIntents"],"sourceRoot":"../../src","sources":["reconciliation.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAEEA,SAAS,EACTC,WAAW,EACXC,aAAa,QACR,iBAAiB;AAExB,SAASC,eAAe,QAAQ,aAAU;AAC1C,SACEC,iBAAiB,EACjBC,mBAAmB,QACd,4BAAyB;AAChC,SAASC,SAAS,EAAEC,YAAY,QAAQ,aAAU;;AAElD;AACA;AACA;;AASA;AACA;AACA;;AASA;AACA;AACA;AACA,OAAO,eAAeC,qBAAqBA,CACzCC,MAAoB,EACpBC,UAAsB,EACuB;EAC7C,IAAI;IACF;IACA,IAAIP,eAAe,CAACM,MAAM,CAAC,EAAE;MAC3B,OAAO;QACLE,KAAK,EAAE,KAAK;QACZC,KAAK,EAAE;MACT,CAAC;IACH;;IAEA;IACA,MAAMC,eAAe,GAAG,IAAIb,SAAS,CAACS,MAAM,CAACK,IAAI,CAAC;IAClD,MAAMC,iBAAi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