@sip-protocol/sdk 0.1.0 → 0.1.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sip-protocol/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.4",
4
4
  "description": "Core SDK for Shielded Intents Protocol - Privacy layer for cross-chain transactions",
5
5
  "author": "SIP Protocol <hello@sip-protocol.org>",
6
6
  "homepage": "https://sip-protocol.org",
@@ -27,10 +27,13 @@
27
27
  "src"
28
28
  ],
29
29
  "dependencies": {
30
+ "@aztec/bb.js": "^0.63.1",
30
31
  "@noble/ciphers": "^2.0.1",
31
32
  "@noble/curves": "^1.3.0",
32
33
  "@noble/hashes": "^1.3.3",
33
- "@sip-protocol/types": "0.1.0"
34
+ "@noir-lang/noir_js": "^1.0.0-beta.15",
35
+ "@noir-lang/types": "1.0.0-beta.15",
36
+ "@sip-protocol/types": "0.1.1"
34
37
  },
35
38
  "devDependencies": {
36
39
  "@vitest/coverage-v8": "1.6.1",
@@ -11,13 +11,15 @@ import {
11
11
  type OneClickQuoteResponse,
12
12
  type OneClickStatusResponse,
13
13
  type DefuseAssetId,
14
- type ChainType,
15
14
  type ChainId,
16
15
  type HexString,
17
16
  type Asset,
18
17
  PrivacyLevel,
19
18
  OneClickSwapType,
20
19
  OneClickSwapStatus,
20
+ OneClickDepositType,
21
+ OneClickRefundType,
22
+ OneClickRecipientType,
21
23
  } from '@sip-protocol/types'
22
24
  import { OneClickClient } from './oneclick-client'
23
25
  import { generateStealthAddress, decodeStealthMetaAddress } from '../stealth'
@@ -104,46 +106,52 @@ export interface NEARIntentsAdapterConfig {
104
106
  }
105
107
 
106
108
  /**
107
- * Default asset mapping from SIP format to Defuse asset identifier
109
+ * Default asset mapping from SIP format to Defuse asset identifier (NEP-141 format)
110
+ *
111
+ * These are the actual asset IDs used by the 1Click API.
112
+ * Format: nep141:<token-contract>.near
113
+ *
114
+ * @see https://1click.chaindefuser.com/v0/tokens
108
115
  */
109
116
  const DEFAULT_ASSET_MAPPINGS: Record<string, DefuseAssetId> = {
110
117
  // NEAR assets
111
- 'near:NEAR': 'near:mainnet:native',
112
- 'near:wNEAR': 'near:mainnet:wrap.near',
118
+ 'near:NEAR': 'nep141:wrap.near',
119
+ 'near:wNEAR': 'nep141:wrap.near',
113
120
 
114
- // Ethereum assets
115
- 'ethereum:ETH': 'eth:1:native',
116
- 'ethereum:USDC': 'eth:1:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
117
- 'ethereum:USDT': 'eth:1:0xdac17f958d2ee523a2206206994597c13d831ec7',
121
+ // Ethereum assets (via OMFT bridge)
122
+ 'ethereum:ETH': 'nep141:eth.omft.near',
123
+ 'ethereum:USDC': 'nep141:17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1',
124
+ 'ethereum:USDT': 'nep141:usdt.tether-token.near',
118
125
 
119
- // Solana assets
120
- 'solana:SOL': 'sol:mainnet:native',
126
+ // Solana assets (via OMFT bridge)
127
+ 'solana:SOL': 'nep141:sol.omft.near',
121
128
 
122
129
  // Zcash assets
123
- 'zcash:ZEC': 'zcash:mainnet:native',
130
+ 'zcash:ZEC': 'nep141:zec.omft.near',
124
131
 
125
132
  // Arbitrum assets
126
- 'arbitrum:ETH': 'arb:42161:native',
133
+ 'arbitrum:ETH': 'nep141:arb.omft.near',
127
134
 
128
135
  // Base assets
129
- 'base:ETH': 'base:8453:native',
136
+ 'base:ETH': 'nep141:base.omft.near',
130
137
 
131
138
  // Polygon assets
132
- 'polygon:MATIC': 'polygon:137:native',
139
+ 'polygon:MATIC': 'nep141:matic.omft.near',
133
140
  }
134
141
 
135
142
  /**
136
- * Chain ID to ChainType mapping
143
+ * Chain ID to blockchain name mapping (for address format validation)
137
144
  */
138
- const CHAIN_TYPE_MAP: Record<ChainId, ChainType> = {
145
+ const CHAIN_BLOCKCHAIN_MAP: Record<ChainId, string> = {
139
146
  near: 'near',
140
- ethereum: 'eth',
141
- solana: 'sol',
147
+ ethereum: 'evm',
148
+ solana: 'solana',
142
149
  zcash: 'zcash',
143
- polygon: 'polygon',
144
- arbitrum: 'arb',
145
- optimism: 'optimism',
146
- base: 'base',
150
+ polygon: 'evm',
151
+ arbitrum: 'evm',
152
+ optimism: 'evm',
153
+ base: 'evm',
154
+ bitcoin: 'bitcoin',
147
155
  }
148
156
 
149
157
  /**
@@ -390,10 +398,11 @@ export class NEARIntentsAdapter {
390
398
  }
391
399
 
392
400
  /**
393
- * Convert SIP chain ID to 1Click chain type
401
+ * Convert SIP chain ID to blockchain type
402
+ * @deprecated Use getBlockchainType() instead. The 1Click API now uses ORIGIN_CHAIN/DESTINATION_CHAIN types.
394
403
  */
395
- mapChainType(chain: ChainId): ChainType {
396
- const mapped = CHAIN_TYPE_MAP[chain]
404
+ mapChainType(chain: ChainId): string {
405
+ const mapped = CHAIN_BLOCKCHAIN_MAP[chain]
397
406
 
398
407
  if (!mapped) {
399
408
  throw new ValidationError(
@@ -431,7 +440,7 @@ export class NEARIntentsAdapter {
431
440
  recipient: string,
432
441
  refundTo?: string,
433
442
  ): OneClickQuoteRequest {
434
- // Map assets
443
+ // Map assets to NEP-141 format
435
444
  const originAsset = this.mapAsset(
436
445
  request.inputAsset.chain,
437
446
  request.inputAsset.symbol
@@ -441,14 +450,11 @@ export class NEARIntentsAdapter {
441
450
  request.outputAsset.symbol
442
451
  )
443
452
 
444
- // Map chain types
445
- const depositType = this.mapChainType(request.inputAsset.chain)
446
- const recipientType = this.mapChainType(request.outputAsset.chain)
447
- const refundType = depositType // Refund to same chain as deposit
448
-
449
- // Calculate deadline
453
+ // Calculate deadline (ISO 8601 format required)
450
454
  const deadline = new Date(Date.now() + this.defaultDeadlineOffset * 1000).toISOString()
451
455
 
456
+ // Use ORIGIN_CHAIN for deposits from external chains
457
+ // Use DESTINATION_CHAIN for sending to external chains
452
458
  return {
453
459
  swapType: OneClickSwapType.EXACT_INPUT,
454
460
  originAsset,
@@ -456,13 +462,20 @@ export class NEARIntentsAdapter {
456
462
  amount: request.inputAmount.toString(),
457
463
  recipient,
458
464
  refundTo: refundTo ?? recipient,
459
- depositType,
460
- recipientType,
461
- refundType,
465
+ depositType: OneClickDepositType.ORIGIN_CHAIN,
466
+ recipientType: OneClickRecipientType.DESTINATION_CHAIN,
467
+ refundType: OneClickRefundType.ORIGIN_CHAIN,
462
468
  slippageTolerance: this.defaultSlippage,
463
469
  deadline,
464
470
  }
465
471
  }
472
+
473
+ /**
474
+ * Get blockchain type for a chain (for address format validation)
475
+ */
476
+ getBlockchainType(chain: ChainId): string {
477
+ return CHAIN_BLOCKCHAIN_MAP[chain] ?? chain
478
+ }
466
479
  }
467
480
 
468
481
  /**
@@ -67,7 +67,9 @@ export class OneClickClient {
67
67
  this.baseUrl = config.baseUrl ?? DEFAULTS.baseUrl
68
68
  this.jwtToken = config.jwtToken
69
69
  this.timeout = config.timeout ?? DEFAULTS.timeout
70
- this.fetchFn = config.fetch ?? globalThis.fetch
70
+ // Bind fetch to globalThis to preserve 'this' context in browsers
71
+ // Without this, fetch() throws "Illegal invocation" when assigned to a property
72
+ this.fetchFn = config.fetch ?? globalThis.fetch.bind(globalThis)
71
73
  }
72
74
 
73
75
  /**
@@ -249,6 +251,12 @@ export class OneClickClient {
249
251
  if (!request.recipientType) {
250
252
  throw new ValidationError('recipientType is required', 'request.recipientType')
251
253
  }
254
+ if (request.slippageTolerance === undefined || request.slippageTolerance === null) {
255
+ throw new ValidationError('slippageTolerance is required (0-10000 basis points)', 'request.slippageTolerance')
256
+ }
257
+ if (!request.deadline) {
258
+ throw new ValidationError('deadline is required (ISO 8601 format)', 'request.deadline')
259
+ }
252
260
  }
253
261
 
254
262
  private async get<T>(path: string): Promise<T> {