@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/dist/index.d.mts +3236 -1554
- package/dist/index.d.ts +3236 -1554
- package/dist/index.js +9185 -3521
- package/dist/index.mjs +8995 -3376
- package/package.json +5 -2
- package/src/adapters/near-intents.ts +48 -35
- package/src/adapters/oneclick-client.ts +9 -1
- package/src/compliance/compliance-manager.ts +1035 -0
- package/src/compliance/index.ts +43 -0
- package/src/index.ts +129 -2
- package/src/payment/index.ts +54 -0
- package/src/payment/payment.ts +623 -0
- package/src/payment/stablecoins.ts +306 -0
- package/src/privacy.ts +127 -94
- package/src/proofs/circuits/fulfillment_proof.json +1 -0
- package/src/proofs/circuits/funding_proof.json +1 -0
- package/src/proofs/circuits/validity_proof.json +1 -0
- package/src/proofs/interface.ts +13 -1
- package/src/proofs/noir.ts +967 -97
- package/src/secure-memory.ts +147 -0
- package/src/sip.ts +399 -37
- package/src/stealth.ts +116 -84
- package/src/treasury/index.ts +43 -0
- package/src/treasury/treasury.ts +911 -0
- package/src/wallet/hardware/index.ts +87 -0
- package/src/wallet/hardware/ledger.ts +628 -0
- package/src/wallet/hardware/mock.ts +667 -0
- package/src/wallet/hardware/trezor.ts +657 -0
- package/src/wallet/hardware/types.ts +317 -0
- package/src/wallet/index.ts +40 -0
- package/src/zcash/shielded-service.ts +59 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sip-protocol/sdk",
|
|
3
|
-
"version": "0.1.
|
|
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
|
-
"@
|
|
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
|
|
112
|
-
'near:wNEAR': '
|
|
118
|
+
'near:NEAR': 'nep141:wrap.near',
|
|
119
|
+
'near:wNEAR': 'nep141:wrap.near',
|
|
113
120
|
|
|
114
|
-
// Ethereum assets
|
|
115
|
-
'ethereum:ETH': 'eth
|
|
116
|
-
'ethereum:USDC': '
|
|
117
|
-
'ethereum:USDT': '
|
|
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
|
|
126
|
+
// Solana assets (via OMFT bridge)
|
|
127
|
+
'solana:SOL': 'nep141:sol.omft.near',
|
|
121
128
|
|
|
122
129
|
// Zcash assets
|
|
123
|
-
'zcash:ZEC': '
|
|
130
|
+
'zcash:ZEC': 'nep141:zec.omft.near',
|
|
124
131
|
|
|
125
132
|
// Arbitrum assets
|
|
126
|
-
'arbitrum:ETH': 'arb
|
|
133
|
+
'arbitrum:ETH': 'nep141:arb.omft.near',
|
|
127
134
|
|
|
128
135
|
// Base assets
|
|
129
|
-
'base:ETH': 'base
|
|
136
|
+
'base:ETH': 'nep141:base.omft.near',
|
|
130
137
|
|
|
131
138
|
// Polygon assets
|
|
132
|
-
'polygon:MATIC': '
|
|
139
|
+
'polygon:MATIC': 'nep141:matic.omft.near',
|
|
133
140
|
}
|
|
134
141
|
|
|
135
142
|
/**
|
|
136
|
-
* Chain ID to
|
|
143
|
+
* Chain ID to blockchain name mapping (for address format validation)
|
|
137
144
|
*/
|
|
138
|
-
const
|
|
145
|
+
const CHAIN_BLOCKCHAIN_MAP: Record<ChainId, string> = {
|
|
139
146
|
near: 'near',
|
|
140
|
-
ethereum: '
|
|
141
|
-
solana: '
|
|
147
|
+
ethereum: 'evm',
|
|
148
|
+
solana: 'solana',
|
|
142
149
|
zcash: 'zcash',
|
|
143
|
-
polygon: '
|
|
144
|
-
arbitrum: '
|
|
145
|
-
optimism: '
|
|
146
|
-
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
|
|
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):
|
|
396
|
-
const mapped =
|
|
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
|
-
//
|
|
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
|
-
|
|
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> {
|