@sip-protocol/sdk 0.1.7 → 0.1.9
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.js +22 -5
- package/dist/index.mjs +22 -5
- package/package.json +1 -1
- package/src/adapters/near-intents.ts +39 -8
package/dist/index.js
CHANGED
|
@@ -1970,6 +1970,7 @@ var NEARIntentsAdapter = class {
|
|
|
1970
1970
|
async prepareSwap(request, recipientMetaAddress, senderAddress) {
|
|
1971
1971
|
this.validateRequest(request);
|
|
1972
1972
|
let recipientAddress;
|
|
1973
|
+
let refundAddress = senderAddress;
|
|
1973
1974
|
let stealthData;
|
|
1974
1975
|
let sharedSecret;
|
|
1975
1976
|
if (request.privacyLevel !== import_types3.PrivacyLevel.TRANSPARENT) {
|
|
@@ -1982,13 +1983,29 @@ var NEARIntentsAdapter = class {
|
|
|
1982
1983
|
const metaAddr = typeof recipientMetaAddress === "string" ? decodeStealthMetaAddress(recipientMetaAddress) : recipientMetaAddress;
|
|
1983
1984
|
const { stealthAddress, sharedSecret: secret } = generateStealthAddress(metaAddr);
|
|
1984
1985
|
const outputChainType = CHAIN_BLOCKCHAIN_MAP[request.outputAsset.chain];
|
|
1985
|
-
if (outputChainType
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1986
|
+
if (outputChainType !== "evm") {
|
|
1987
|
+
throw new ValidationError(
|
|
1988
|
+
`Stealth addresses are not supported for ${request.outputAsset.chain} output. SIP stealth addresses use secp256k1 (EIP-5564 style) which only works for EVM chains. For ${request.outputAsset.chain} output, please connect a wallet or use an EVM output chain.`,
|
|
1989
|
+
"outputAsset",
|
|
1990
|
+
{ outputChain: request.outputAsset.chain, outputChainType }
|
|
1991
|
+
);
|
|
1989
1992
|
}
|
|
1993
|
+
recipientAddress = publicKeyToEthAddress(stealthAddress.address);
|
|
1990
1994
|
stealthData = stealthAddress;
|
|
1991
1995
|
sharedSecret = secret;
|
|
1996
|
+
if (!senderAddress) {
|
|
1997
|
+
const inputChainType = CHAIN_BLOCKCHAIN_MAP[request.inputAsset.chain];
|
|
1998
|
+
if (inputChainType === "evm") {
|
|
1999
|
+
const refundStealth = generateStealthAddress(metaAddr);
|
|
2000
|
+
refundAddress = publicKeyToEthAddress(refundStealth.stealthAddress.address);
|
|
2001
|
+
} else {
|
|
2002
|
+
throw new ValidationError(
|
|
2003
|
+
`senderAddress is required for refunds on ${request.inputAsset.chain}. Stealth addresses are only supported for EVM-compatible chains. Please connect a wallet or provide a sender address.`,
|
|
2004
|
+
"senderAddress",
|
|
2005
|
+
{ inputChain: request.inputAsset.chain, inputChainType }
|
|
2006
|
+
);
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
1992
2009
|
} else {
|
|
1993
2010
|
if (!senderAddress) {
|
|
1994
2011
|
throw new ValidationError(
|
|
@@ -1998,7 +2015,7 @@ var NEARIntentsAdapter = class {
|
|
|
1998
2015
|
}
|
|
1999
2016
|
recipientAddress = senderAddress;
|
|
2000
2017
|
}
|
|
2001
|
-
const quoteRequest = this.buildQuoteRequest(request, recipientAddress,
|
|
2018
|
+
const quoteRequest = this.buildQuoteRequest(request, recipientAddress, refundAddress);
|
|
2002
2019
|
return {
|
|
2003
2020
|
request,
|
|
2004
2021
|
quoteRequest,
|
package/dist/index.mjs
CHANGED
|
@@ -1779,6 +1779,7 @@ var NEARIntentsAdapter = class {
|
|
|
1779
1779
|
async prepareSwap(request, recipientMetaAddress, senderAddress) {
|
|
1780
1780
|
this.validateRequest(request);
|
|
1781
1781
|
let recipientAddress;
|
|
1782
|
+
let refundAddress = senderAddress;
|
|
1782
1783
|
let stealthData;
|
|
1783
1784
|
let sharedSecret;
|
|
1784
1785
|
if (request.privacyLevel !== PrivacyLevel.TRANSPARENT) {
|
|
@@ -1791,13 +1792,29 @@ var NEARIntentsAdapter = class {
|
|
|
1791
1792
|
const metaAddr = typeof recipientMetaAddress === "string" ? decodeStealthMetaAddress(recipientMetaAddress) : recipientMetaAddress;
|
|
1792
1793
|
const { stealthAddress, sharedSecret: secret } = generateStealthAddress(metaAddr);
|
|
1793
1794
|
const outputChainType = CHAIN_BLOCKCHAIN_MAP[request.outputAsset.chain];
|
|
1794
|
-
if (outputChainType
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1795
|
+
if (outputChainType !== "evm") {
|
|
1796
|
+
throw new ValidationError(
|
|
1797
|
+
`Stealth addresses are not supported for ${request.outputAsset.chain} output. SIP stealth addresses use secp256k1 (EIP-5564 style) which only works for EVM chains. For ${request.outputAsset.chain} output, please connect a wallet or use an EVM output chain.`,
|
|
1798
|
+
"outputAsset",
|
|
1799
|
+
{ outputChain: request.outputAsset.chain, outputChainType }
|
|
1800
|
+
);
|
|
1798
1801
|
}
|
|
1802
|
+
recipientAddress = publicKeyToEthAddress(stealthAddress.address);
|
|
1799
1803
|
stealthData = stealthAddress;
|
|
1800
1804
|
sharedSecret = secret;
|
|
1805
|
+
if (!senderAddress) {
|
|
1806
|
+
const inputChainType = CHAIN_BLOCKCHAIN_MAP[request.inputAsset.chain];
|
|
1807
|
+
if (inputChainType === "evm") {
|
|
1808
|
+
const refundStealth = generateStealthAddress(metaAddr);
|
|
1809
|
+
refundAddress = publicKeyToEthAddress(refundStealth.stealthAddress.address);
|
|
1810
|
+
} else {
|
|
1811
|
+
throw new ValidationError(
|
|
1812
|
+
`senderAddress is required for refunds on ${request.inputAsset.chain}. Stealth addresses are only supported for EVM-compatible chains. Please connect a wallet or provide a sender address.`,
|
|
1813
|
+
"senderAddress",
|
|
1814
|
+
{ inputChain: request.inputAsset.chain, inputChainType }
|
|
1815
|
+
);
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1801
1818
|
} else {
|
|
1802
1819
|
if (!senderAddress) {
|
|
1803
1820
|
throw new ValidationError(
|
|
@@ -1807,7 +1824,7 @@ var NEARIntentsAdapter = class {
|
|
|
1807
1824
|
}
|
|
1808
1825
|
recipientAddress = senderAddress;
|
|
1809
1826
|
}
|
|
1810
|
-
const quoteRequest = this.buildQuoteRequest(request, recipientAddress,
|
|
1827
|
+
const quoteRequest = this.buildQuoteRequest(request, recipientAddress, refundAddress);
|
|
1811
1828
|
return {
|
|
1812
1829
|
request,
|
|
1813
1830
|
quoteRequest,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sip-protocol/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
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",
|
|
@@ -229,6 +229,7 @@ export class NEARIntentsAdapter {
|
|
|
229
229
|
|
|
230
230
|
// Determine recipient address
|
|
231
231
|
let recipientAddress: string
|
|
232
|
+
let refundAddress: string | undefined = senderAddress
|
|
232
233
|
let stealthData: PreparedSwap['stealthAddress']
|
|
233
234
|
let sharedSecret: HexString | undefined
|
|
234
235
|
|
|
@@ -246,19 +247,49 @@ export class NEARIntentsAdapter {
|
|
|
246
247
|
? decodeStealthMetaAddress(recipientMetaAddress)
|
|
247
248
|
: recipientMetaAddress
|
|
248
249
|
|
|
249
|
-
// Generate stealth address
|
|
250
|
+
// Generate stealth address for recipient (output chain)
|
|
250
251
|
const { stealthAddress, sharedSecret: secret } = generateStealthAddress(metaAddr)
|
|
251
252
|
|
|
252
|
-
//
|
|
253
|
-
//
|
|
253
|
+
// Stealth addresses are secp256k1-based (EIP-5564 style) and only work for EVM chains.
|
|
254
|
+
// Non-EVM chains (Solana, Bitcoin, etc.) use different cryptographic schemes
|
|
255
|
+
// and cannot receive funds at secp256k1-derived addresses.
|
|
254
256
|
const outputChainType = CHAIN_BLOCKCHAIN_MAP[request.outputAsset.chain]
|
|
255
|
-
if (outputChainType
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
257
|
+
if (outputChainType !== 'evm') {
|
|
258
|
+
throw new ValidationError(
|
|
259
|
+
`Stealth addresses are not supported for ${request.outputAsset.chain} output. ` +
|
|
260
|
+
`SIP stealth addresses use secp256k1 (EIP-5564 style) which only works for EVM chains. ` +
|
|
261
|
+
`For ${request.outputAsset.chain} output, please connect a wallet or use an EVM output chain.`,
|
|
262
|
+
'outputAsset',
|
|
263
|
+
{ outputChain: request.outputAsset.chain, outputChainType }
|
|
264
|
+
)
|
|
259
265
|
}
|
|
266
|
+
|
|
267
|
+
// For EVM chains, convert stealth public key to ETH address format
|
|
268
|
+
// The 1Click API expects 20-byte Ethereum addresses, not 33-byte secp256k1 public keys
|
|
269
|
+
recipientAddress = publicKeyToEthAddress(stealthAddress.address)
|
|
260
270
|
stealthData = stealthAddress
|
|
261
271
|
sharedSecret = secret
|
|
272
|
+
|
|
273
|
+
// Generate refund address for input chain (if no sender address provided)
|
|
274
|
+
if (!senderAddress) {
|
|
275
|
+
const inputChainType = CHAIN_BLOCKCHAIN_MAP[request.inputAsset.chain]
|
|
276
|
+
if (inputChainType === 'evm') {
|
|
277
|
+
// For EVM input chains, generate a stealth address and convert to ETH address
|
|
278
|
+
const refundStealth = generateStealthAddress(metaAddr)
|
|
279
|
+
refundAddress = publicKeyToEthAddress(refundStealth.stealthAddress.address)
|
|
280
|
+
} else {
|
|
281
|
+
// For non-EVM input chains (Solana, Bitcoin, etc.), we cannot generate
|
|
282
|
+
// valid stealth addresses because they use different cryptographic schemes.
|
|
283
|
+
// Require sender address for refunds on these chains.
|
|
284
|
+
throw new ValidationError(
|
|
285
|
+
`senderAddress is required for refunds on ${request.inputAsset.chain}. ` +
|
|
286
|
+
`Stealth addresses are only supported for EVM-compatible chains. ` +
|
|
287
|
+
`Please connect a wallet or provide a sender address.`,
|
|
288
|
+
'senderAddress',
|
|
289
|
+
{ inputChain: request.inputAsset.chain, inputChainType }
|
|
290
|
+
)
|
|
291
|
+
}
|
|
292
|
+
}
|
|
262
293
|
} else {
|
|
263
294
|
// Transparent mode uses direct address
|
|
264
295
|
if (!senderAddress) {
|
|
@@ -271,7 +302,7 @@ export class NEARIntentsAdapter {
|
|
|
271
302
|
}
|
|
272
303
|
|
|
273
304
|
// Build quote request
|
|
274
|
-
const quoteRequest = this.buildQuoteRequest(request, recipientAddress,
|
|
305
|
+
const quoteRequest = this.buildQuoteRequest(request, recipientAddress, refundAddress)
|
|
275
306
|
|
|
276
307
|
return {
|
|
277
308
|
request,
|