@aptos-labs/cross-chain-core 5.8.2 → 6.0.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 (52) hide show
  1. package/README.md +26 -0
  2. package/dist/CrossChainCore.d.ts +95 -0
  3. package/dist/CrossChainCore.d.ts.map +1 -1
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +908 -404
  7. package/dist/index.js.map +1 -1
  8. package/dist/index.mjs +914 -409
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/providers/wormhole/index.d.ts +2 -0
  11. package/dist/providers/wormhole/index.d.ts.map +1 -1
  12. package/dist/providers/wormhole/signers/AptosLocalSigner.d.ts +9 -7
  13. package/dist/providers/wormhole/signers/AptosLocalSigner.d.ts.map +1 -1
  14. package/dist/providers/wormhole/signers/AptosSigner.d.ts +2 -1
  15. package/dist/providers/wormhole/signers/AptosSigner.d.ts.map +1 -1
  16. package/dist/providers/wormhole/signers/EthereumSigner.d.ts +1 -1
  17. package/dist/providers/wormhole/signers/EthereumSigner.d.ts.map +1 -1
  18. package/dist/providers/wormhole/signers/Signer.d.ts +11 -3
  19. package/dist/providers/wormhole/signers/Signer.d.ts.map +1 -1
  20. package/dist/providers/wormhole/signers/SolanaLocalSigner.d.ts +69 -0
  21. package/dist/providers/wormhole/signers/SolanaLocalSigner.d.ts.map +1 -0
  22. package/dist/providers/wormhole/signers/SolanaSigner.d.ts +12 -20
  23. package/dist/providers/wormhole/signers/SolanaSigner.d.ts.map +1 -1
  24. package/dist/providers/wormhole/signers/solanaUtils.d.ts +68 -0
  25. package/dist/providers/wormhole/signers/solanaUtils.d.ts.map +1 -0
  26. package/dist/providers/wormhole/types.d.ts +120 -0
  27. package/dist/providers/wormhole/types.d.ts.map +1 -1
  28. package/dist/providers/wormhole/utils.d.ts +26 -0
  29. package/dist/providers/wormhole/utils.d.ts.map +1 -0
  30. package/dist/providers/wormhole/wormhole.d.ts +62 -6
  31. package/dist/providers/wormhole/wormhole.d.ts.map +1 -1
  32. package/dist/utils/receiptSerialization.d.ts +38 -0
  33. package/dist/utils/receiptSerialization.d.ts.map +1 -0
  34. package/dist/version.d.ts +1 -1
  35. package/package.json +3 -3
  36. package/src/CrossChainCore.ts +110 -3
  37. package/src/config/mainnet/chains.ts +2 -2
  38. package/src/config/testnet/chains.ts +2 -2
  39. package/src/index.ts +1 -0
  40. package/src/providers/wormhole/index.ts +2 -0
  41. package/src/providers/wormhole/signers/AptosLocalSigner.ts +31 -18
  42. package/src/providers/wormhole/signers/AptosSigner.ts +11 -2
  43. package/src/providers/wormhole/signers/EthereumSigner.ts +59 -8
  44. package/src/providers/wormhole/signers/Signer.ts +23 -6
  45. package/src/providers/wormhole/signers/SolanaLocalSigner.ts +250 -0
  46. package/src/providers/wormhole/signers/SolanaSigner.ts +49 -338
  47. package/src/providers/wormhole/signers/solanaUtils.ts +446 -0
  48. package/src/providers/wormhole/types.ts +167 -0
  49. package/src/providers/wormhole/utils.ts +72 -0
  50. package/src/providers/wormhole/wormhole.ts +309 -137
  51. package/src/utils/receiptSerialization.ts +141 -0
  52. package/src/version.ts +1 -1
@@ -0,0 +1,141 @@
1
+ import {
2
+ routes,
3
+ AttestationReceipt,
4
+ UniversalAddress,
5
+ } from "@wormhole-foundation/sdk";
6
+
7
+ // Cross-platform base64 helpers (no Node.js Buffer dependency)
8
+ function uint8ArrayToBase64(bytes: Uint8Array): string {
9
+ let binary = "";
10
+ for (let i = 0; i < bytes.length; i++) {
11
+ binary += String.fromCharCode(bytes[i]);
12
+ }
13
+ return btoa(binary);
14
+ }
15
+
16
+ function base64ToUint8Array(base64: string): Uint8Array {
17
+ const binary = atob(base64);
18
+ const bytes = new Uint8Array(binary.length);
19
+ for (let i = 0; i < binary.length; i++) {
20
+ bytes[i] = binary.charCodeAt(i);
21
+ }
22
+ return bytes;
23
+ }
24
+
25
+ /**
26
+ * Serializes a Wormhole receipt for JSON transport.
27
+ *
28
+ * JSON doesn't natively support BigInt, Uint8Array, or class instances.
29
+ * This function converts these types to a serializable format with type markers
30
+ * that can be reconstructed by `deserializeReceipt`.
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * import { serializeReceipt } from "@aptos-labs/cross-chain-core";
35
+ *
36
+ * // On the client side, before sending to server
37
+ * const serialized = serializeReceipt(receipt);
38
+ * await fetch("/api/claim", {
39
+ * method: "POST",
40
+ * body: JSON.stringify({ receipt: serialized }),
41
+ * });
42
+ * ```
43
+ */
44
+ export function serializeReceipt(
45
+ receipt: routes.Receipt<AttestationReceipt>,
46
+ ): unknown {
47
+ return JSON.parse(
48
+ JSON.stringify(receipt, (_key, value) => {
49
+ if (typeof value === "bigint") {
50
+ return { __type: "bigint", value: value.toString() };
51
+ }
52
+ // Check UniversalAddress before Uint8Array — if the SDK ever makes
53
+ // UniversalAddress extend Uint8Array the order matters.
54
+ if (value instanceof UniversalAddress) {
55
+ return {
56
+ __type: "UniversalAddress",
57
+ value: uint8ArrayToBase64(value.toUint8Array()),
58
+ };
59
+ }
60
+ if (value instanceof Uint8Array) {
61
+ return {
62
+ __type: "Uint8Array",
63
+ value: uint8ArrayToBase64(value),
64
+ };
65
+ }
66
+ return value;
67
+ }),
68
+ );
69
+ }
70
+
71
+ /**
72
+ * Deserializes a Wormhole receipt from JSON transport format.
73
+ *
74
+ * Reconstructs BigInt, Uint8Array, and UniversalAddress instances from
75
+ * the serialized format produced by `serializeReceipt`.
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * import { deserializeReceipt, SolanaLocalSigner } from "@aptos-labs/cross-chain-core";
80
+ *
81
+ * // On the server side, after receiving from client
82
+ * const receipt = deserializeReceipt(body.receipt);
83
+ * await cctpRoute.complete(signer, receipt);
84
+ * ```
85
+ */
86
+ export function deserializeReceipt(
87
+ obj: unknown,
88
+ ): routes.Receipt<AttestationReceipt> {
89
+ function revive(value: unknown, key?: string): unknown {
90
+ if (value && typeof value === "object") {
91
+ const objValue = value as Record<string, unknown>;
92
+
93
+ // Handle serialized BigInt, Uint8Array, and UniversalAddress
94
+ if ("__type" in objValue) {
95
+ if (objValue.__type === "bigint") {
96
+ return BigInt(objValue.value as string);
97
+ }
98
+ if (objValue.__type === "UniversalAddress") {
99
+ return new UniversalAddress(
100
+ base64ToUint8Array(objValue.value as string),
101
+ );
102
+ }
103
+ if (objValue.__type === "Uint8Array") {
104
+ return base64ToUint8Array(objValue.value as string);
105
+ }
106
+ }
107
+
108
+ // Backwards-compatible fallback: reconstruct UniversalAddress for known
109
+ // CCTP message address fields that were serialized without __type markers
110
+ // (i.e. data produced before UniversalAddress-aware serialization).
111
+ const addressFields = [
112
+ "sender",
113
+ "recipient",
114
+ "destinationCaller",
115
+ "burnToken",
116
+ "mintRecipient",
117
+ "messageSender",
118
+ ];
119
+ if (key && addressFields.includes(key) && "address" in objValue) {
120
+ const addressBytes = revive(objValue.address);
121
+ if (addressBytes instanceof Uint8Array) {
122
+ return new UniversalAddress(addressBytes);
123
+ }
124
+ }
125
+
126
+ // Recursively process nested objects and arrays
127
+ if (Array.isArray(value)) {
128
+ return value.map((v, i) => revive(v, String(i)));
129
+ }
130
+ const result: Record<string, unknown> = {};
131
+ for (const k in objValue) {
132
+ result[k] = revive(objValue[k], k);
133
+ }
134
+ return result;
135
+ }
136
+ return value;
137
+ }
138
+
139
+ return revive(obj) as routes.Receipt<AttestationReceipt>;
140
+ }
141
+
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const CROSS_CHAIN_CORE_VERSION = "5.8.2";
1
+ export const CROSS_CHAIN_CORE_VERSION = "6.0.0";