@chainlink/ccip-sdk 0.96.0 → 1.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 (247) hide show
  1. package/README.md +12 -9
  2. package/dist/api/index.d.ts +21 -8
  3. package/dist/api/index.d.ts.map +1 -1
  4. package/dist/api/index.js +42 -13
  5. package/dist/api/index.js.map +1 -1
  6. package/dist/api/types.d.ts +0 -2
  7. package/dist/api/types.d.ts.map +1 -1
  8. package/dist/aptos/exec.d.ts +2 -2
  9. package/dist/aptos/exec.d.ts.map +1 -1
  10. package/dist/aptos/exec.js.map +1 -1
  11. package/dist/aptos/hasher.d.ts.map +1 -1
  12. package/dist/aptos/hasher.js +1 -1
  13. package/dist/aptos/hasher.js.map +1 -1
  14. package/dist/aptos/index.d.ts +17 -16
  15. package/dist/aptos/index.d.ts.map +1 -1
  16. package/dist/aptos/index.js +42 -73
  17. package/dist/aptos/index.js.map +1 -1
  18. package/dist/aptos/logs.d.ts +2 -2
  19. package/dist/aptos/logs.d.ts.map +1 -1
  20. package/dist/aptos/types.d.ts +2 -19
  21. package/dist/aptos/types.d.ts.map +1 -1
  22. package/dist/aptos/types.js +0 -11
  23. package/dist/aptos/types.js.map +1 -1
  24. package/dist/chain.d.ts +538 -158
  25. package/dist/chain.d.ts.map +1 -1
  26. package/dist/chain.js +132 -19
  27. package/dist/chain.js.map +1 -1
  28. package/dist/commits.d.ts +4 -6
  29. package/dist/commits.d.ts.map +1 -1
  30. package/dist/commits.js +4 -4
  31. package/dist/commits.js.map +1 -1
  32. package/dist/errors/CCIPError.d.ts +33 -4
  33. package/dist/errors/CCIPError.d.ts.map +1 -1
  34. package/dist/errors/CCIPError.js +33 -4
  35. package/dist/errors/CCIPError.js.map +1 -1
  36. package/dist/errors/codes.d.ts +3 -0
  37. package/dist/errors/codes.d.ts.map +1 -1
  38. package/dist/errors/codes.js +3 -1
  39. package/dist/errors/codes.js.map +1 -1
  40. package/dist/errors/index.d.ts +4 -4
  41. package/dist/errors/index.d.ts.map +1 -1
  42. package/dist/errors/index.js +4 -4
  43. package/dist/errors/index.js.map +1 -1
  44. package/dist/errors/recovery.d.ts.map +1 -1
  45. package/dist/errors/recovery.js +4 -1
  46. package/dist/errors/recovery.js.map +1 -1
  47. package/dist/errors/specialized.d.ts +1695 -120
  48. package/dist/errors/specialized.d.ts.map +1 -1
  49. package/dist/errors/specialized.js +1715 -123
  50. package/dist/errors/specialized.js.map +1 -1
  51. package/dist/errors/utils.d.ts.map +1 -1
  52. package/dist/errors/utils.js +0 -1
  53. package/dist/errors/utils.js.map +1 -1
  54. package/dist/evm/abi/OffRamp_2_0.d.ts +764 -0
  55. package/dist/evm/abi/OffRamp_2_0.d.ts.map +1 -0
  56. package/dist/evm/abi/OffRamp_2_0.js +744 -0
  57. package/dist/evm/abi/OffRamp_2_0.js.map +1 -0
  58. package/dist/evm/abi/OnRamp_2_0.d.ts +925 -0
  59. package/dist/evm/abi/OnRamp_2_0.d.ts.map +1 -0
  60. package/dist/evm/abi/OnRamp_2_0.js +992 -0
  61. package/dist/evm/abi/OnRamp_2_0.js.map +1 -0
  62. package/dist/evm/const.d.ts +12 -2
  63. package/dist/evm/const.d.ts.map +1 -1
  64. package/dist/evm/const.js +8 -2
  65. package/dist/evm/const.js.map +1 -1
  66. package/dist/evm/errors.d.ts.map +1 -1
  67. package/dist/evm/errors.js +7 -2
  68. package/dist/evm/errors.js.map +1 -1
  69. package/dist/evm/extra-args.d.ts.map +1 -1
  70. package/dist/evm/extra-args.js +5 -24
  71. package/dist/evm/extra-args.js.map +1 -1
  72. package/dist/evm/hasher.d.ts.map +1 -1
  73. package/dist/evm/hasher.js +23 -13
  74. package/dist/evm/hasher.js.map +1 -1
  75. package/dist/evm/index.d.ts +73 -16
  76. package/dist/evm/index.d.ts.map +1 -1
  77. package/dist/evm/index.js +241 -146
  78. package/dist/evm/index.js.map +1 -1
  79. package/dist/evm/logs.d.ts +1 -1
  80. package/dist/evm/logs.js +1 -1
  81. package/dist/evm/messages.d.ts +59 -5
  82. package/dist/evm/messages.d.ts.map +1 -1
  83. package/dist/evm/messages.js +210 -0
  84. package/dist/evm/messages.js.map +1 -1
  85. package/dist/evm/offchain.d.ts +1 -14
  86. package/dist/evm/offchain.d.ts.map +1 -1
  87. package/dist/evm/offchain.js +1 -133
  88. package/dist/evm/offchain.js.map +1 -1
  89. package/dist/evm/types.d.ts +7 -2
  90. package/dist/evm/types.d.ts.map +1 -1
  91. package/dist/evm/types.js +22 -1
  92. package/dist/evm/types.js.map +1 -1
  93. package/dist/execution.d.ts +62 -22
  94. package/dist/execution.d.ts.map +1 -1
  95. package/dist/execution.js +98 -61
  96. package/dist/execution.js.map +1 -1
  97. package/dist/extra-args.d.ts +13 -3
  98. package/dist/extra-args.d.ts.map +1 -1
  99. package/dist/extra-args.js +13 -3
  100. package/dist/extra-args.js.map +1 -1
  101. package/dist/gas.d.ts +25 -2
  102. package/dist/gas.d.ts.map +1 -1
  103. package/dist/gas.js +30 -4
  104. package/dist/gas.js.map +1 -1
  105. package/dist/index.d.ts +3 -2
  106. package/dist/index.d.ts.map +1 -1
  107. package/dist/index.js +2 -1
  108. package/dist/index.js.map +1 -1
  109. package/dist/offchain.d.ts +23 -6
  110. package/dist/offchain.d.ts.map +1 -1
  111. package/dist/offchain.js +92 -17
  112. package/dist/offchain.js.map +1 -1
  113. package/dist/requests.d.ts +85 -14
  114. package/dist/requests.d.ts.map +1 -1
  115. package/dist/requests.js +99 -17
  116. package/dist/requests.js.map +1 -1
  117. package/dist/selectors.d.ts.map +1 -1
  118. package/dist/selectors.js +12 -0
  119. package/dist/selectors.js.map +1 -1
  120. package/dist/shared/bcs-codecs.d.ts +61 -0
  121. package/dist/shared/bcs-codecs.d.ts.map +1 -0
  122. package/dist/shared/bcs-codecs.js +102 -0
  123. package/dist/shared/bcs-codecs.js.map +1 -0
  124. package/dist/shared/constants.d.ts +3 -0
  125. package/dist/shared/constants.d.ts.map +1 -0
  126. package/dist/shared/constants.js +3 -0
  127. package/dist/shared/constants.js.map +1 -0
  128. package/dist/solana/exec.d.ts +2 -2
  129. package/dist/solana/exec.d.ts.map +1 -1
  130. package/dist/solana/exec.js.map +1 -1
  131. package/dist/solana/idl/1.6.0/BASE_TOKEN_POOL.d.ts +1 -1
  132. package/dist/solana/idl/1.6.0/BASE_TOKEN_POOL.js +1 -1
  133. package/dist/solana/idl/1.6.0/BURN_MINT_TOKEN_POOL.d.ts +1 -1
  134. package/dist/solana/idl/1.6.0/BURN_MINT_TOKEN_POOL.js +1 -1
  135. package/dist/solana/idl/1.6.0/CCIP_CCTP_TOKEN_POOL.d.ts +1 -1
  136. package/dist/solana/idl/1.6.0/CCIP_CCTP_TOKEN_POOL.js +1 -1
  137. package/dist/solana/idl/1.6.0/CCIP_COMMON.d.ts +16 -1
  138. package/dist/solana/idl/1.6.0/CCIP_COMMON.d.ts.map +1 -1
  139. package/dist/solana/idl/1.6.0/CCIP_COMMON.js +16 -1
  140. package/dist/solana/idl/1.6.0/CCIP_COMMON.js.map +1 -1
  141. package/dist/solana/idl/1.6.0/CCIP_OFFRAMP.d.ts +1 -1
  142. package/dist/solana/idl/1.6.0/CCIP_OFFRAMP.js +1 -1
  143. package/dist/solana/idl/1.6.0/CCIP_ROUTER.d.ts +1 -1
  144. package/dist/solana/idl/1.6.0/CCIP_ROUTER.js +1 -1
  145. package/dist/solana/index.d.ts +85 -24
  146. package/dist/solana/index.d.ts.map +1 -1
  147. package/dist/solana/index.js +69 -37
  148. package/dist/solana/index.js.map +1 -1
  149. package/dist/solana/offchain.d.ts +1 -13
  150. package/dist/solana/offchain.d.ts.map +1 -1
  151. package/dist/solana/offchain.js +1 -66
  152. package/dist/solana/offchain.js.map +1 -1
  153. package/dist/solana/utils.d.ts +4 -4
  154. package/dist/solana/utils.d.ts.map +1 -1
  155. package/dist/solana/utils.js +1 -1
  156. package/dist/solana/utils.js.map +1 -1
  157. package/dist/sui/hasher.d.ts.map +1 -1
  158. package/dist/sui/hasher.js +1 -1
  159. package/dist/sui/hasher.js.map +1 -1
  160. package/dist/sui/index.d.ts +18 -18
  161. package/dist/sui/index.d.ts.map +1 -1
  162. package/dist/sui/index.js +38 -39
  163. package/dist/sui/index.js.map +1 -1
  164. package/dist/sui/manuallyExec/encoder.d.ts +2 -2
  165. package/dist/sui/manuallyExec/encoder.d.ts.map +1 -1
  166. package/dist/sui/manuallyExec/encoder.js.map +1 -1
  167. package/dist/sui/manuallyExec/index.d.ts +2 -2
  168. package/dist/sui/manuallyExec/index.d.ts.map +1 -1
  169. package/dist/ton/exec.d.ts +3 -3
  170. package/dist/ton/exec.d.ts.map +1 -1
  171. package/dist/ton/exec.js +1 -1
  172. package/dist/ton/exec.js.map +1 -1
  173. package/dist/ton/index.d.ts +14 -22
  174. package/dist/ton/index.d.ts.map +1 -1
  175. package/dist/ton/index.js +26 -35
  176. package/dist/ton/index.js.map +1 -1
  177. package/dist/ton/types.d.ts +3 -5
  178. package/dist/ton/types.d.ts.map +1 -1
  179. package/dist/ton/types.js.map +1 -1
  180. package/dist/types.d.ts +55 -20
  181. package/dist/types.d.ts.map +1 -1
  182. package/dist/types.js +6 -1
  183. package/dist/types.js.map +1 -1
  184. package/dist/utils.d.ts +65 -2
  185. package/dist/utils.d.ts.map +1 -1
  186. package/dist/utils.js +74 -2
  187. package/dist/utils.js.map +1 -1
  188. package/package.json +14 -10
  189. package/src/api/index.ts +53 -17
  190. package/src/api/types.ts +0 -2
  191. package/src/aptos/exec.ts +2 -2
  192. package/src/aptos/hasher.ts +1 -1
  193. package/src/aptos/index.ts +55 -100
  194. package/src/aptos/logs.ts +2 -2
  195. package/src/aptos/types.ts +2 -15
  196. package/src/chain.ts +594 -171
  197. package/src/commits.ts +9 -9
  198. package/src/errors/CCIPError.ts +33 -4
  199. package/src/errors/codes.ts +3 -1
  200. package/src/errors/index.ts +4 -0
  201. package/src/errors/recovery.ts +7 -1
  202. package/src/errors/specialized.ts +1726 -130
  203. package/src/errors/utils.ts +0 -1
  204. package/src/evm/abi/OffRamp_2_0.ts +743 -0
  205. package/src/evm/abi/OnRamp_2_0.ts +991 -0
  206. package/src/evm/const.ts +10 -3
  207. package/src/evm/errors.ts +6 -2
  208. package/src/evm/extra-args.ts +4 -21
  209. package/src/evm/hasher.ts +30 -18
  210. package/src/evm/index.ts +314 -176
  211. package/src/evm/logs.ts +1 -1
  212. package/src/evm/messages.ts +323 -11
  213. package/src/evm/offchain.ts +2 -191
  214. package/src/evm/types.ts +20 -2
  215. package/src/execution.ts +125 -86
  216. package/src/extra-args.ts +13 -3
  217. package/src/gas.ts +29 -3
  218. package/src/index.ts +10 -3
  219. package/src/offchain.ts +125 -28
  220. package/src/requests.ts +114 -19
  221. package/src/selectors.ts +12 -0
  222. package/src/shared/bcs-codecs.ts +132 -0
  223. package/src/shared/constants.ts +2 -0
  224. package/src/solana/exec.ts +4 -4
  225. package/src/solana/idl/1.6.0/BASE_TOKEN_POOL.ts +2 -2
  226. package/src/solana/idl/1.6.0/BURN_MINT_TOKEN_POOL.ts +2 -2
  227. package/src/solana/idl/1.6.0/CCIP_CCTP_TOKEN_POOL.ts +2 -2
  228. package/src/solana/idl/1.6.0/CCIP_COMMON.ts +32 -2
  229. package/src/solana/idl/1.6.0/CCIP_OFFRAMP.ts +2 -2
  230. package/src/solana/idl/1.6.0/CCIP_ROUTER.ts +2 -2
  231. package/src/solana/index.ts +110 -85
  232. package/src/solana/offchain.ts +3 -100
  233. package/src/solana/utils.ts +8 -5
  234. package/src/sui/hasher.ts +1 -1
  235. package/src/sui/index.ts +55 -59
  236. package/src/sui/manuallyExec/encoder.ts +2 -2
  237. package/src/sui/manuallyExec/index.ts +2 -2
  238. package/src/ton/exec.ts +4 -7
  239. package/src/ton/index.ts +45 -53
  240. package/src/ton/types.ts +4 -7
  241. package/src/types.ts +81 -37
  242. package/src/utils.ts +73 -2
  243. package/dist/aptos/utils.d.ts +0 -12
  244. package/dist/aptos/utils.d.ts.map +0 -1
  245. package/dist/aptos/utils.js +0 -15
  246. package/dist/aptos/utils.js.map +0 -1
  247. package/src/aptos/utils.ts +0 -24
package/src/types.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import type { AbiParametersToPrimitiveTypes, ExtractAbiEvent } from 'abitype'
2
- import type { BytesLike, Log } from 'ethers'
2
+ import type { BytesLike, Log as EVMLog } from 'ethers'
3
+ import type { SetOptional } from 'type-fest'
3
4
 
4
5
  import type { APICCIPRequestMetadata } from './api/types.ts'
5
6
  import type OffRamp_1_6_ABI from './evm/abi/OffRamp_1_6.ts'
6
- import type { CCIPMessage_EVM, CCIPMessage_V1_6_EVM } from './evm/messages.ts'
7
+ import type { CCIPMessage_EVM, CCIPMessage_V1_6_EVM, CCIPMessage_V2_0 } from './evm/messages.ts'
7
8
  import type { ExtraArgs } from './extra-args.ts'
8
9
  import type { CCIPMessage_V1_6_Solana } from './solana/types.ts'
9
10
  import type { CCIPMessage_V1_6_Sui } from './sui/types.ts'
10
- import type { CCIPMessage_V1_6_TON } from './ton/types.ts'
11
11
  // v1.6 Base type from EVM contains the intersection of all other CCIPMessage v1.6 types
12
12
  export type { CCIPMessage_V1_6 } from './evm/messages.ts'
13
13
 
@@ -88,6 +88,7 @@ export const CCIPVersion = {
88
88
  V1_2: '1.2.0',
89
89
  V1_5: '1.5.0',
90
90
  V1_6: '1.6.0',
91
+ V2_0: '2.0.0',
91
92
  } as const
92
93
  /** Type representing one of the supported CCIP versions. */
93
94
  export type CCIPVersion = (typeof CCIPVersion)[keyof typeof CCIPVersion]
@@ -153,20 +154,23 @@ export interface Lane<V extends CCIPVersion = CCIPVersion> {
153
154
  /**
154
155
  * Union type representing a CCIP message across different versions and chain families.
155
156
  */
156
- export type CCIPMessage<V extends CCIPVersion = CCIPVersion> = V extends
157
- | typeof CCIPVersion.V1_2
158
- | typeof CCIPVersion.V1_5
159
- ? CCIPMessage_EVM<V>
160
- : CCIPMessage_V1_6_EVM | CCIPMessage_V1_6_Solana | CCIPMessage_V1_6_Sui | CCIPMessage_V1_6_TON
157
+ export type CCIPMessage<V extends CCIPVersion = CCIPVersion> = V extends typeof CCIPVersion.V2_0
158
+ ? CCIPMessage_V2_0
159
+ : V extends typeof CCIPVersion.V1_6
160
+ ? CCIPMessage_V1_6_EVM | CCIPMessage_V1_6_Solana | CCIPMessage_V1_6_Sui
161
+ : CCIPMessage_EVM<V>
161
162
 
162
163
  /**
163
164
  * Generic log structure compatible across chain families.
164
165
  */
165
- export type Log_ = Pick<Log, 'topics' | 'index' | 'address' | 'blockNumber' | 'transactionHash'> & {
166
+ export type ChainLog = Pick<
167
+ EVMLog,
168
+ 'topics' | 'index' | 'address' | 'blockNumber' | 'transactionHash'
169
+ > & {
166
170
  /** Log data as bytes or parsed object. */
167
171
  data: BytesLike | Record<string, unknown>
168
172
  /** Optional reference to the containing transaction. */
169
- tx?: ChainTransaction
173
+ tx?: SetOptional<ChainTransaction, 'logs'>
170
174
  }
171
175
 
172
176
  /**
@@ -187,7 +191,7 @@ export type ChainTransaction = {
187
191
  /** Transaction hash. */
188
192
  hash: string
189
193
  /** Logs emitted by this transaction. */
190
- logs: readonly Log_[]
194
+ logs: readonly ChainLog[]
191
195
  /** Block number containing this transaction. */
192
196
  blockNumber: number
193
197
  /** Unix timestamp of the block. */
@@ -204,12 +208,10 @@ export type ChainTransaction = {
204
208
  export interface CCIPRequest<V extends CCIPVersion = CCIPVersion> {
205
209
  /** Lane configuration for this request. */
206
210
  lane: Lane<V>
207
- /** The CCIP message being sent. */
208
211
  message: CCIPMessage<V>
209
- /** Log event from the OnRamp. */
210
- log: Log_
212
+ log: ChainLog
211
213
  /** Transaction that emitted the request. */
212
- tx: Pick<ChainTransaction, 'hash' | 'logs' | 'blockNumber' | 'timestamp' | 'from' | 'error'>
214
+ tx: Omit<ChainTransaction, 'logs'>
213
215
 
214
216
  /**
215
217
  * API-enriched metadata. Present only when fetched via CCIP API.
@@ -236,22 +238,47 @@ export interface CCIPRequest<V extends CCIPVersion = CCIPVersion> {
236
238
  }
237
239
 
238
240
  /**
239
- * Commit report structure from the OffRamp CommitReportAccepted event.
241
+ * OnChain Commit report structure from the OffRamp CommitReportAccepted event.
240
242
  */
241
243
  export type CommitReport = AbiParametersToPrimitiveTypes<
242
244
  ExtractAbiEvent<typeof OffRamp_1_6_ABI, 'CommitReportAccepted'>['inputs']
243
245
  >[0][number]
244
246
 
245
247
  /**
246
- * CCIP commit information containing the report and its log.
248
+ * OffChain Verification result for a CCIP v2.0 message, returned by the indexer API.
247
249
  */
248
- export interface CCIPCommit {
249
- /** The commit report data. */
250
- report: CommitReport
251
- /** Log event from the commit. */
252
- log: Log_
250
+ export type VerifierResult = {
251
+ /** Verification data required for destination execution (e.g. signatures). */
252
+ ccvData: BytesLike
253
+ /** Source CCV contract address. */
254
+ sourceAddress: string
255
+ /** Destination CCV contract address. */
256
+ destAddress: string
257
+ /** Timestamp of the attestation (Unix seconds). */
258
+ timestamp?: number
253
259
  }
254
260
 
261
+ /**
262
+ * Verification data for a ccip message (onchain CommitReport, or offchain Verifications)
263
+ */
264
+ export type CCIPVerifications =
265
+ | {
266
+ /** The commit report data. */
267
+ report: CommitReport
268
+ /** Log event from the commit. */
269
+ log: ChainLog
270
+ }
271
+ | {
272
+ /** Policy for this request */
273
+ verificationPolicy: {
274
+ optionalCCVs: readonly string[]
275
+ requiredCCVs: readonly string[]
276
+ optionalThreshold: number
277
+ }
278
+ /** Verifications array; one for each requiredCCV is needed for exec */
279
+ verifications: VerifierResult[]
280
+ }
281
+
255
282
  /**
256
283
  * Enumeration of possible execution states for a CCIP message.
257
284
  */
@@ -287,7 +314,11 @@ export const MessageStatus = {
287
314
  Verifying: 'VERIFYING',
288
315
  /** Message has been verified by the CCIP network */
289
316
  Verified: 'VERIFIED',
290
- /** Unknown status returned by API */
317
+ /**
318
+ * API returned an unrecognized status value.
319
+ * This typically means the CCIP API has new status values that this SDK version
320
+ * doesn't recognize. Consider updating to the latest SDK version.
321
+ */
291
322
  Unknown: 'UNKNOWN',
292
323
  } as const
293
324
  /** Type representing a CCIP message lifecycle status. */
@@ -345,7 +376,7 @@ export interface CCIPExecution {
345
376
  /** Execution receipt data. */
346
377
  receipt: ExecutionReceipt
347
378
  /** Log event from the execution. */
348
- log: Log_
379
+ log: ChainLog
349
380
  /** Unix timestamp of the execution. */
350
381
  timestamp: number
351
382
  }
@@ -369,18 +400,26 @@ export type OffchainTokenData = { _tag: string; [k: string]: BytesLike } | undef
369
400
  * }
370
401
  * ```
371
402
  */
372
- export type ExecutionReport<M extends CCIPMessage = CCIPMessage> = {
373
- /** The CCIP message to execute. */
374
- message: M
375
- /** Merkle proofs for the message. */
376
- proofs: readonly BytesLike[]
377
- /** Bit flags for proof verification. */
378
- proofFlagBits: bigint
379
- /** Merkle root for verification. */
380
- merkleRoot: string
381
- /** Offchain token data for each token transfer. */
382
- offchainTokenData: readonly OffchainTokenData[]
383
- }
403
+ export type ExecutionInput<M extends CCIPMessage = CCIPMessage> =
404
+ M extends CCIPMessage<typeof CCIPVersion.V2_0>
405
+ ? {
406
+ /** encodedMessage as per CCIPv2 codec */
407
+ encodedMessage: M['encodedMessage']
408
+ /** Off-Chain verifications containing verifierResults' ccvData and ccvs addresses */
409
+ verifications: Pick<VerifierResult, 'ccvData' | 'destAddress'>[]
410
+ }
411
+ : {
412
+ /** The CCIP message to execute. */
413
+ message: M
414
+ /** Merkle proofs for the message. */
415
+ proofs: readonly BytesLike[]
416
+ /** Bit flags for proof verification. */
417
+ proofFlagBits: bigint
418
+ /** Merkle root for verification. */
419
+ merkleRoot: string
420
+ /** Offchain token data for each token transfer. */
421
+ offchainTokenData: readonly OffchainTokenData[]
422
+ }
384
423
 
385
424
  /**
386
425
  * A message to be sent to another network.
@@ -396,7 +435,12 @@ export type ExecutionReport<M extends CCIPMessage = CCIPMessage> = {
396
435
  * ```
397
436
  */
398
437
  export type AnyMessage = {
399
- /** Receiver address on the destination chain. */
438
+ /**
439
+ * Receiver address on the destination chain.
440
+ * Must be a valid address for the destination chain family. For instance:
441
+ * - EVM: 20-byte hex (e.g., `0x6d1af98d635d3121286ddda1a0c2d7078b1523ed`)
442
+ * - Solana: Base58 public key (e.g., `7EcDhSYGxXyscszYEp35KHN8vvw3svAuLKTzXwCFLtV`)
443
+ */
400
444
  receiver: BytesLike
401
445
  /** Extra arguments for gas limits and other settings. */
402
446
  extraArgs: ExtraArgs
package/src/utils.ts CHANGED
@@ -131,6 +131,23 @@ const networkInfoFromChainId = memoize((chainId: NetworkInfo['chainId']): Networ
131
131
  * - Chain name as string ("ethereum-mainnet")
132
132
  * @returns Complete NetworkInfo object
133
133
  * @throws {@link CCIPChainNotFoundError} if chain is not found
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * import { networkInfo } from '@chainlink/ccip-sdk'
138
+ *
139
+ * // By chain name
140
+ * const sepolia = networkInfo('ethereum-testnet-sepolia')
141
+ * console.log('Selector:', sepolia.chainSelector)
142
+ *
143
+ * // By chain selector
144
+ * const fuji = networkInfo(14767482510784806043n)
145
+ * console.log('Name:', fuji.name) // 'avalanche-testnet-fuji'
146
+ *
147
+ * // By chain ID
148
+ * const mainnet = networkInfo(1)
149
+ * console.log('Family:', mainnet.family) // 'EVM'
150
+ * ```
134
151
  */
135
152
  export const networkInfo = memoize(function networkInfo_(
136
153
  selectorOrIdOrName: bigint | number | string,
@@ -206,6 +223,15 @@ export function* blockRangeGenerator(
206
223
  * @param _key - Property key (unused).
207
224
  * @param value - Value to transform.
208
225
  * @returns String representation if BigInt, otherwise unchanged value.
226
+ * @example
227
+ * ```typescript
228
+ * import { bigIntReplacer } from '@chainlink/ccip-sdk'
229
+ *
230
+ * const data = { amount: 1000000000000000000n }
231
+ * const json = JSON.stringify(data, bigIntReplacer)
232
+ * console.log(json) // '{"amount":"1000000000000000000"}'
233
+ * ```
234
+ * @see {@link bigIntReviver} - Revive BigInt values when parsing
209
235
  */
210
236
  export function bigIntReplacer(_key: string, value: unknown): unknown {
211
237
  if (typeof value === 'bigint') {
@@ -219,6 +245,15 @@ export function bigIntReplacer(_key: string, value: unknown): unknown {
219
245
  * @param _key - Property key (unused).
220
246
  * @param value - Value to transform.
221
247
  * @returns BigInt if numeric string, otherwise unchanged value.
248
+ * @example
249
+ * ```typescript
250
+ * import { bigIntReviver } from '@chainlink/ccip-sdk'
251
+ *
252
+ * const json = '{"amount":"1000000000000000000"}'
253
+ * const data = JSON.parse(json, bigIntReviver)
254
+ * console.log(typeof data.amount) // 'bigint'
255
+ * ```
256
+ * @see {@link bigIntReplacer} - Stringify BigInt values
222
257
  */
223
258
  export function bigIntReviver(_key: string, value: unknown): unknown {
224
259
  if (typeof value === 'string' && /^\d+$/.test(value)) {
@@ -238,11 +273,25 @@ export function parseJson<T = unknown>(text: string): T {
238
273
  }
239
274
 
240
275
  /**
241
- * Decode address from a 32-byte hex string
242
- * @param address - Address bytes to decode
276
+ * Decode address from a 32-byte hex string.
277
+ *
278
+ * @param address - Address bytes to decode (hex string or Uint8Array)
243
279
  * @param family - Chain family for address format (defaults to EVM)
244
280
  * @returns Decoded address string
245
281
  * @throws {@link CCIPChainFamilyUnsupportedError} if chain family is not supported
282
+ *
283
+ * @example
284
+ * ```typescript
285
+ * import { decodeAddress, ChainFamily } from '@chainlink/ccip-sdk'
286
+ *
287
+ * // Decode EVM address from 32-byte hex
288
+ * const evmAddr = decodeAddress('0x000000000000000000000000abc123...', ChainFamily.EVM)
289
+ * console.log(evmAddr) // '0xABC123...'
290
+ *
291
+ * // Decode Solana address
292
+ * const solAddr = decodeAddress(bytes, ChainFamily.Solana)
293
+ * console.log(solAddr) // Base58 encoded address
294
+ * ```
246
295
  */
247
296
  export function decodeAddress(address: BytesLike, family: ChainFamily = ChainFamily.EVM): string {
248
297
  const chain = supportedChains[family]
@@ -320,6 +369,20 @@ export function isBase64(data: unknown): data is string {
320
369
  * @param data - Bytes, number array, or Base64 string.
321
370
  * @returns Uint8Array representation.
322
371
  * @throws {@link CCIPDataFormatUnsupportedError} if data format is not recognized
372
+ *
373
+ * @example
374
+ * ```typescript
375
+ * import { getDataBytes } from '@chainlink/ccip-sdk'
376
+ *
377
+ * // From hex string
378
+ * const bytes1 = getDataBytes('0x1234abcd')
379
+ *
380
+ * // From number array
381
+ * const bytes2 = getDataBytes([0x12, 0x34, 0xab, 0xcd])
382
+ *
383
+ * // From Base64
384
+ * const bytes3 = getDataBytes('EjSrzQ==')
385
+ * ```
323
386
  */
324
387
  export function getDataBytes(data: BytesLike | readonly number[]): Uint8Array {
325
388
  if (Array.isArray(data)) return new Uint8Array(data)
@@ -369,6 +432,14 @@ export function getAddressBytes(address: BytesLike | readonly number[]): Uint8Ar
369
432
  ? '0x' + address
370
433
  : address,
371
434
  )
435
+ } else if (typeof address === 'string' && /^-?\d+:[0-9a-f]{64}$/i.test(address)) {
436
+ // TON raw format: "workchain:hash" → 36-byte CCIP format (4-byte BE workchain + 32-byte hash)
437
+ const [workchain, hash] = address.split(':')
438
+ const buf = new Uint8Array(36)
439
+ const view = new DataView(buf.buffer)
440
+ view.setInt32(0, parseInt(workchain!, 10), false) // big-endian
441
+ buf.set(getBytes('0x' + hash), 4)
442
+ bytes = buf
372
443
  } else {
373
444
  try {
374
445
  const bytes_ = bs58.decode(address as string)
@@ -1,12 +0,0 @@
1
- import { type BigNumberish, type BytesLike } from 'ethers';
2
- /**
3
- * Encodes a numeric value as a 32-byte hex string.
4
- * @param value - Numeric value to encode.
5
- * @returns 32-byte hex string representation of the value.
6
- */
7
- export declare const encodeNumber: (value: BigNumberish) => string;
8
- /**
9
- * Encodes dynamic bytes without the struct offset prefix.
10
- */
11
- export declare const encodeRawBytes: (value: BytesLike) => string;
12
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/aptos/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,SAAS,EAKf,MAAM,QAAQ,CAAA;AAEf;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,YAAY,KAAG,MAA4B,CAAA;AAE/E;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,SAAS,KAAG,MAI9C,CAAA"}
@@ -1,15 +0,0 @@
1
- import { concat, dataLength, toBeHex, zeroPadBytes, } from 'ethers';
2
- /**
3
- * Encodes a numeric value as a 32-byte hex string.
4
- * @param value - Numeric value to encode.
5
- * @returns 32-byte hex string representation of the value.
6
- */
7
- export const encodeNumber = (value) => toBeHex(value, 32);
8
- /**
9
- * Encodes dynamic bytes without the struct offset prefix.
10
- */
11
- export const encodeRawBytes = (value) => concat([
12
- encodeNumber(dataLength(value)),
13
- zeroPadBytes(value, Math.ceil(dataLength(value) / 32) * 32),
14
- ]);
15
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/aptos/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,MAAM,EACN,UAAU,EACV,OAAO,EACP,YAAY,GACb,MAAM,QAAQ,CAAA;AAEf;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAmB,EAAU,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;AAE/E;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAgB,EAAU,EAAE,CACzD,MAAM,CAAC;IACL,YAAY,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAC/B,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC;CAC5D,CAAC,CAAA"}
@@ -1,24 +0,0 @@
1
- import {
2
- type BigNumberish,
3
- type BytesLike,
4
- concat,
5
- dataLength,
6
- toBeHex,
7
- zeroPadBytes,
8
- } from 'ethers'
9
-
10
- /**
11
- * Encodes a numeric value as a 32-byte hex string.
12
- * @param value - Numeric value to encode.
13
- * @returns 32-byte hex string representation of the value.
14
- */
15
- export const encodeNumber = (value: BigNumberish): string => toBeHex(value, 32)
16
-
17
- /**
18
- * Encodes dynamic bytes without the struct offset prefix.
19
- */
20
- export const encodeRawBytes = (value: BytesLike): string =>
21
- concat([
22
- encodeNumber(dataLength(value)),
23
- zeroPadBytes(value, Math.ceil(dataLength(value) / 32) * 32),
24
- ])