@sip-protocol/sdk 0.2.8 → 0.2.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/README.md +349 -0
- package/dist/browser.d.mts +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +588 -154
- package/dist/browser.mjs +5 -1
- package/dist/chunk-KXN6IWL5.mjs +10736 -0
- package/dist/index.d.mts +289 -1
- package/dist/index.d.ts +289 -1
- package/dist/index.js +588 -154
- package/dist/index.mjs +5 -1
- package/package.json +1 -1
- package/src/index.ts +12 -0
- package/src/zcash/bridge.ts +738 -0
- package/src/zcash/index.ts +36 -1
- package/src/zcash/swap-service.ts +793 -0
package/dist/browser.js
CHANGED
|
@@ -47,7 +47,7 @@ __export(browser_exports, {
|
|
|
47
47
|
HardwareWalletError: () => HardwareWalletError,
|
|
48
48
|
IntentBuilder: () => IntentBuilder,
|
|
49
49
|
IntentError: () => IntentError,
|
|
50
|
-
IntentStatus: () =>
|
|
50
|
+
IntentStatus: () => import_types34.IntentStatus,
|
|
51
51
|
LedgerWalletAdapter: () => LedgerWalletAdapter,
|
|
52
52
|
MockEthereumAdapter: () => MockEthereumAdapter,
|
|
53
53
|
MockLedgerAdapter: () => MockLedgerAdapter,
|
|
@@ -56,26 +56,26 @@ __export(browser_exports, {
|
|
|
56
56
|
MockSolver: () => MockSolver,
|
|
57
57
|
MockTrezorAdapter: () => MockTrezorAdapter,
|
|
58
58
|
MockWalletAdapter: () => MockWalletAdapter,
|
|
59
|
-
NATIVE_TOKENS: () =>
|
|
59
|
+
NATIVE_TOKENS: () => import_types34.NATIVE_TOKENS,
|
|
60
60
|
NEARIntentsAdapter: () => NEARIntentsAdapter,
|
|
61
61
|
NetworkError: () => NetworkError,
|
|
62
62
|
ORACLE_DOMAIN: () => ORACLE_DOMAIN,
|
|
63
63
|
OneClickClient: () => OneClickClient,
|
|
64
|
-
OneClickDepositMode: () =>
|
|
65
|
-
OneClickErrorCode: () =>
|
|
66
|
-
OneClickSwapStatus: () =>
|
|
67
|
-
OneClickSwapType: () =>
|
|
64
|
+
OneClickDepositMode: () => import_types38.OneClickDepositMode,
|
|
65
|
+
OneClickErrorCode: () => import_types38.OneClickErrorCode,
|
|
66
|
+
OneClickSwapStatus: () => import_types38.OneClickSwapStatus,
|
|
67
|
+
OneClickSwapType: () => import_types38.OneClickSwapType,
|
|
68
68
|
PaymentBuilder: () => PaymentBuilder,
|
|
69
|
-
PaymentStatus: () =>
|
|
70
|
-
PrivacyLevel: () =>
|
|
69
|
+
PaymentStatus: () => import_types35.PaymentStatus,
|
|
70
|
+
PrivacyLevel: () => import_types34.PrivacyLevel,
|
|
71
71
|
ProofError: () => ProofError,
|
|
72
72
|
ProofGenerationError: () => ProofGenerationError,
|
|
73
73
|
ProofNotImplementedError: () => ProofNotImplementedError,
|
|
74
|
-
ProposalStatus: () =>
|
|
75
|
-
ReportStatus: () =>
|
|
74
|
+
ProposalStatus: () => import_types36.ProposalStatus,
|
|
75
|
+
ReportStatus: () => import_types37.ReportStatus,
|
|
76
76
|
SIP: () => SIP,
|
|
77
77
|
SIPError: () => SIPError,
|
|
78
|
-
SIP_VERSION: () =>
|
|
78
|
+
SIP_VERSION: () => import_types34.SIP_VERSION,
|
|
79
79
|
STABLECOIN_ADDRESSES: () => STABLECOIN_ADDRESSES,
|
|
80
80
|
STABLECOIN_DECIMALS: () => STABLECOIN_DECIMALS,
|
|
81
81
|
STABLECOIN_INFO: () => STABLECOIN_INFO,
|
|
@@ -84,11 +84,12 @@ __export(browser_exports, {
|
|
|
84
84
|
TrezorWalletAdapter: () => TrezorWalletAdapter,
|
|
85
85
|
ValidationError: () => ValidationError,
|
|
86
86
|
WalletError: () => WalletError,
|
|
87
|
-
WalletErrorCode: () =>
|
|
88
|
-
ZcashErrorCode: () =>
|
|
87
|
+
WalletErrorCode: () => import_types33.WalletErrorCode,
|
|
88
|
+
ZcashErrorCode: () => import_types39.ZcashErrorCode,
|
|
89
89
|
ZcashRPCClient: () => ZcashRPCClient,
|
|
90
90
|
ZcashRPCError: () => ZcashRPCError,
|
|
91
91
|
ZcashShieldedService: () => ZcashShieldedService,
|
|
92
|
+
ZcashSwapService: () => ZcashSwapService,
|
|
92
93
|
addBlindings: () => addBlindings,
|
|
93
94
|
addCommitments: () => addCommitments,
|
|
94
95
|
addOracle: () => addOracle,
|
|
@@ -123,6 +124,7 @@ __export(browser_exports, {
|
|
|
123
124
|
createWalletFactory: () => createWalletFactory,
|
|
124
125
|
createZcashClient: () => createZcashClient,
|
|
125
126
|
createZcashShieldedService: () => createZcashShieldedService,
|
|
127
|
+
createZcashSwapService: () => createZcashSwapService,
|
|
126
128
|
decodeStealthMetaAddress: () => decodeStealthMetaAddress,
|
|
127
129
|
decryptMemo: () => decryptMemo,
|
|
128
130
|
decryptWithViewing: () => decryptWithViewing,
|
|
@@ -183,7 +185,7 @@ __export(browser_exports, {
|
|
|
183
185
|
isExpired: () => isExpired,
|
|
184
186
|
isNonNegativeAmount: () => isNonNegativeAmount,
|
|
185
187
|
isPaymentExpired: () => isPaymentExpired,
|
|
186
|
-
isPrivate: () =>
|
|
188
|
+
isPrivate: () => import_types34.isPrivate,
|
|
187
189
|
isPrivateWalletAdapter: () => isPrivateWalletAdapter,
|
|
188
190
|
isSIPError: () => isSIPError,
|
|
189
191
|
isStablecoin: () => isStablecoin,
|
|
@@ -219,7 +221,7 @@ __export(browser_exports, {
|
|
|
219
221
|
subtractBlindings: () => subtractBlindings,
|
|
220
222
|
subtractCommitments: () => subtractCommitments,
|
|
221
223
|
supportsSharedArrayBuffer: () => supportsSharedArrayBuffer,
|
|
222
|
-
supportsViewingKey: () =>
|
|
224
|
+
supportsViewingKey: () => import_types34.supportsViewingKey,
|
|
223
225
|
supportsWebBluetooth: () => supportsWebBluetooth,
|
|
224
226
|
supportsWebHID: () => supportsWebHID,
|
|
225
227
|
supportsWebUSB: () => supportsWebUSB,
|
|
@@ -3773,10 +3775,10 @@ function hasEnoughOracles(registry) {
|
|
|
3773
3775
|
}
|
|
3774
3776
|
|
|
3775
3777
|
// src/index.ts
|
|
3776
|
-
var import_types33 = require("@sip-protocol/types");
|
|
3777
3778
|
var import_types34 = require("@sip-protocol/types");
|
|
3778
3779
|
var import_types35 = require("@sip-protocol/types");
|
|
3779
3780
|
var import_types36 = require("@sip-protocol/types");
|
|
3781
|
+
var import_types37 = require("@sip-protocol/types");
|
|
3780
3782
|
|
|
3781
3783
|
// src/solver/mock-solver.ts
|
|
3782
3784
|
var import_types7 = require("@sip-protocol/types");
|
|
@@ -3961,7 +3963,7 @@ function createMockSolver(config) {
|
|
|
3961
3963
|
}
|
|
3962
3964
|
|
|
3963
3965
|
// src/index.ts
|
|
3964
|
-
var
|
|
3966
|
+
var import_types38 = require("@sip-protocol/types");
|
|
3965
3967
|
|
|
3966
3968
|
// src/zcash/rpc-client.ts
|
|
3967
3969
|
var import_types8 = require("@sip-protocol/types");
|
|
@@ -4805,14 +4807,444 @@ function createZcashShieldedService(config) {
|
|
|
4805
4807
|
return new ZcashShieldedService(config);
|
|
4806
4808
|
}
|
|
4807
4809
|
|
|
4808
|
-
// src/zcash/
|
|
4810
|
+
// src/zcash/swap-service.ts
|
|
4809
4811
|
var import_types10 = require("@sip-protocol/types");
|
|
4812
|
+
var MOCK_PRICES = {
|
|
4813
|
+
ETH: 2500,
|
|
4814
|
+
SOL: 120,
|
|
4815
|
+
NEAR: 5,
|
|
4816
|
+
MATIC: 0.8,
|
|
4817
|
+
USDC: 1,
|
|
4818
|
+
USDT: 1,
|
|
4819
|
+
ZEC: 35
|
|
4820
|
+
};
|
|
4821
|
+
var TOKEN_DECIMALS = {
|
|
4822
|
+
ETH: 18,
|
|
4823
|
+
SOL: 9,
|
|
4824
|
+
NEAR: 24,
|
|
4825
|
+
MATIC: 18,
|
|
4826
|
+
USDC: 6,
|
|
4827
|
+
USDT: 6,
|
|
4828
|
+
ZEC: 8
|
|
4829
|
+
// zatoshis
|
|
4830
|
+
};
|
|
4831
|
+
var ZcashSwapService = class {
|
|
4832
|
+
config;
|
|
4833
|
+
zcashService;
|
|
4834
|
+
bridgeProvider;
|
|
4835
|
+
priceFeed;
|
|
4836
|
+
quotes = /* @__PURE__ */ new Map();
|
|
4837
|
+
swaps = /* @__PURE__ */ new Map();
|
|
4838
|
+
constructor(config) {
|
|
4839
|
+
this.config = {
|
|
4840
|
+
mode: config.mode,
|
|
4841
|
+
defaultSlippage: config.defaultSlippage ?? 100,
|
|
4842
|
+
// 1%
|
|
4843
|
+
quoteValiditySeconds: config.quoteValiditySeconds ?? 60
|
|
4844
|
+
};
|
|
4845
|
+
this.zcashService = config.zcashService;
|
|
4846
|
+
this.bridgeProvider = config.bridgeProvider;
|
|
4847
|
+
this.priceFeed = config.priceFeed;
|
|
4848
|
+
}
|
|
4849
|
+
// ─── Quote Methods ───────────────────────────────────────────────────────────
|
|
4850
|
+
/**
|
|
4851
|
+
* Get a quote for swapping to ZEC
|
|
4852
|
+
*/
|
|
4853
|
+
async getQuote(params) {
|
|
4854
|
+
this.validateQuoteParams(params);
|
|
4855
|
+
if (this.zcashService) {
|
|
4856
|
+
const addressInfo = await this.zcashService.validateAddress(params.recipientZAddress);
|
|
4857
|
+
if (!addressInfo.isvalid) {
|
|
4858
|
+
throw new ValidationError(
|
|
4859
|
+
"Invalid Zcash address",
|
|
4860
|
+
"recipientZAddress",
|
|
4861
|
+
{ received: params.recipientZAddress },
|
|
4862
|
+
"SIP_2007" /* INVALID_ADDRESS */
|
|
4863
|
+
);
|
|
4864
|
+
}
|
|
4865
|
+
} else {
|
|
4866
|
+
if (!this.isValidZAddressFormat(params.recipientZAddress)) {
|
|
4867
|
+
throw new ValidationError(
|
|
4868
|
+
"Invalid Zcash address format. Expected z-address (zs1...) or unified address (u1...)",
|
|
4869
|
+
"recipientZAddress",
|
|
4870
|
+
{ received: params.recipientZAddress },
|
|
4871
|
+
"SIP_2007" /* INVALID_ADDRESS */
|
|
4872
|
+
);
|
|
4873
|
+
}
|
|
4874
|
+
}
|
|
4875
|
+
if (this.config.mode === "production" && this.bridgeProvider) {
|
|
4876
|
+
return this.getProductionQuote(params);
|
|
4877
|
+
}
|
|
4878
|
+
return this.getDemoQuote(params);
|
|
4879
|
+
}
|
|
4880
|
+
/**
|
|
4881
|
+
* Get quote in demo mode (uses mock prices)
|
|
4882
|
+
*/
|
|
4883
|
+
async getDemoQuote(params) {
|
|
4884
|
+
const { sourceChain, sourceToken, amount, recipientZAddress, slippage } = params;
|
|
4885
|
+
const sourcePrice = this.priceFeed ? await this.priceFeed.getPrice(sourceToken) : MOCK_PRICES[sourceToken] ?? 1;
|
|
4886
|
+
const zecPrice = this.priceFeed ? await this.priceFeed.getZecPrice() : MOCK_PRICES.ZEC;
|
|
4887
|
+
const sourceDecimals = TOKEN_DECIMALS[sourceToken] ?? 18;
|
|
4888
|
+
const amountInUsd = Number(amount) / 10 ** sourceDecimals * sourcePrice;
|
|
4889
|
+
const swapFeeUsd = amountInUsd * 5e-3;
|
|
4890
|
+
const networkFeeUsd = 2;
|
|
4891
|
+
const totalFeeUsd = swapFeeUsd + networkFeeUsd;
|
|
4892
|
+
const netAmountUsd = amountInUsd - totalFeeUsd;
|
|
4893
|
+
const zecAmount = netAmountUsd / zecPrice;
|
|
4894
|
+
const zecZatoshis = BigInt(Math.floor(zecAmount * 1e8));
|
|
4895
|
+
const slippageBps = slippage ?? this.config.defaultSlippage;
|
|
4896
|
+
const minimumOutput = zecZatoshis * BigInt(1e4 - slippageBps) / 10000n;
|
|
4897
|
+
const swapFee = BigInt(Math.floor(swapFeeUsd / sourcePrice * 10 ** sourceDecimals));
|
|
4898
|
+
const networkFee = BigInt(Math.floor(networkFeeUsd / sourcePrice * 10 ** sourceDecimals));
|
|
4899
|
+
const quoteId = `zec_quote_${Date.now()}_${Math.random().toString(36).substring(2, 8)}`;
|
|
4900
|
+
const validUntil = Math.floor(Date.now() / 1e3) + this.config.quoteValiditySeconds;
|
|
4901
|
+
const quote = {
|
|
4902
|
+
quoteId,
|
|
4903
|
+
sourceChain,
|
|
4904
|
+
sourceToken,
|
|
4905
|
+
amountIn: amount,
|
|
4906
|
+
amountInFormatted: this.formatAmount(amount, sourceDecimals),
|
|
4907
|
+
amountOut: zecZatoshis,
|
|
4908
|
+
amountOutFormatted: this.formatAmount(zecZatoshis, 8),
|
|
4909
|
+
exchangeRate: zecPrice / sourcePrice,
|
|
4910
|
+
networkFee,
|
|
4911
|
+
swapFee,
|
|
4912
|
+
totalFee: networkFee + swapFee,
|
|
4913
|
+
slippage: slippageBps,
|
|
4914
|
+
minimumOutput,
|
|
4915
|
+
validUntil,
|
|
4916
|
+
depositAddress: this.generateMockDepositAddress(sourceChain),
|
|
4917
|
+
estimatedTime: this.getEstimatedTime(sourceChain),
|
|
4918
|
+
privacyLevel: import_types10.PrivacyLevel.SHIELDED
|
|
4919
|
+
};
|
|
4920
|
+
this.quotes.set(quoteId, quote);
|
|
4921
|
+
return quote;
|
|
4922
|
+
}
|
|
4923
|
+
/**
|
|
4924
|
+
* Get quote in production mode (uses bridge provider)
|
|
4925
|
+
*/
|
|
4926
|
+
async getProductionQuote(params) {
|
|
4927
|
+
if (!this.bridgeProvider) {
|
|
4928
|
+
throw new IntentError(
|
|
4929
|
+
"Bridge provider not configured for production mode",
|
|
4930
|
+
"SIP_5004" /* INTENT_INVALID_STATE */
|
|
4931
|
+
);
|
|
4932
|
+
}
|
|
4933
|
+
const bridgeQuote = await this.bridgeProvider.getQuote({
|
|
4934
|
+
sourceChain: params.sourceChain,
|
|
4935
|
+
sourceToken: params.sourceToken,
|
|
4936
|
+
amount: params.amount,
|
|
4937
|
+
recipientAddress: params.recipientZAddress
|
|
4938
|
+
});
|
|
4939
|
+
const sourceDecimals = TOKEN_DECIMALS[params.sourceToken] ?? 18;
|
|
4940
|
+
const slippageBps = params.slippage ?? this.config.defaultSlippage;
|
|
4941
|
+
const minimumOutput = bridgeQuote.amountOut * BigInt(1e4 - slippageBps) / 10000n;
|
|
4942
|
+
const quote = {
|
|
4943
|
+
quoteId: bridgeQuote.quoteId,
|
|
4944
|
+
sourceChain: params.sourceChain,
|
|
4945
|
+
sourceToken: params.sourceToken,
|
|
4946
|
+
amountIn: bridgeQuote.amountIn,
|
|
4947
|
+
amountInFormatted: this.formatAmount(bridgeQuote.amountIn, sourceDecimals),
|
|
4948
|
+
amountOut: bridgeQuote.amountOut,
|
|
4949
|
+
amountOutFormatted: this.formatAmount(bridgeQuote.amountOut, 8),
|
|
4950
|
+
exchangeRate: bridgeQuote.exchangeRate,
|
|
4951
|
+
networkFee: 0n,
|
|
4952
|
+
// Included in bridge fee
|
|
4953
|
+
swapFee: bridgeQuote.fee,
|
|
4954
|
+
totalFee: bridgeQuote.fee,
|
|
4955
|
+
slippage: slippageBps,
|
|
4956
|
+
minimumOutput,
|
|
4957
|
+
validUntil: bridgeQuote.validUntil,
|
|
4958
|
+
depositAddress: "",
|
|
4959
|
+
// Will be set by bridge
|
|
4960
|
+
estimatedTime: this.getEstimatedTime(params.sourceChain),
|
|
4961
|
+
privacyLevel: import_types10.PrivacyLevel.SHIELDED
|
|
4962
|
+
};
|
|
4963
|
+
this.quotes.set(quote.quoteId, quote);
|
|
4964
|
+
return quote;
|
|
4965
|
+
}
|
|
4966
|
+
// ─── Swap Execution ──────────────────────────────────────────────────────────
|
|
4967
|
+
/**
|
|
4968
|
+
* Execute a swap to Zcash shielded pool
|
|
4969
|
+
*/
|
|
4970
|
+
async executeSwapToShielded(params) {
|
|
4971
|
+
let quote;
|
|
4972
|
+
if (params.quoteId) {
|
|
4973
|
+
quote = this.quotes.get(params.quoteId);
|
|
4974
|
+
if (!quote) {
|
|
4975
|
+
throw new ValidationError(
|
|
4976
|
+
"Quote not found or expired",
|
|
4977
|
+
"quoteId",
|
|
4978
|
+
{ received: params.quoteId },
|
|
4979
|
+
"SIP_2000" /* VALIDATION_FAILED */
|
|
4980
|
+
);
|
|
4981
|
+
}
|
|
4982
|
+
}
|
|
4983
|
+
if (!quote) {
|
|
4984
|
+
quote = await this.getQuote({
|
|
4985
|
+
sourceChain: params.sourceChain,
|
|
4986
|
+
sourceToken: params.sourceToken,
|
|
4987
|
+
amount: params.amount,
|
|
4988
|
+
recipientZAddress: params.recipientZAddress,
|
|
4989
|
+
slippage: params.slippage
|
|
4990
|
+
});
|
|
4991
|
+
}
|
|
4992
|
+
if (quote.validUntil < Math.floor(Date.now() / 1e3)) {
|
|
4993
|
+
throw new IntentError(
|
|
4994
|
+
"Quote has expired",
|
|
4995
|
+
"SIP_5001" /* INTENT_EXPIRED */,
|
|
4996
|
+
{ context: { quoteId: quote.quoteId, validUntil: quote.validUntil } }
|
|
4997
|
+
);
|
|
4998
|
+
}
|
|
4999
|
+
const requestId = `zec_swap_${Date.now()}_${Math.random().toString(36).substring(2, 8)}`;
|
|
5000
|
+
const result = {
|
|
5001
|
+
requestId,
|
|
5002
|
+
quoteId: quote.quoteId,
|
|
5003
|
+
status: "pending_deposit",
|
|
5004
|
+
amountIn: params.amount,
|
|
5005
|
+
recipientZAddress: params.recipientZAddress,
|
|
5006
|
+
timestamp: Math.floor(Date.now() / 1e3)
|
|
5007
|
+
};
|
|
5008
|
+
this.swaps.set(requestId, result);
|
|
5009
|
+
if (this.config.mode === "production" && this.bridgeProvider) {
|
|
5010
|
+
return this.executeProductionSwap(result, quote, params);
|
|
5011
|
+
}
|
|
5012
|
+
return this.executeDemoSwap(result, quote, params);
|
|
5013
|
+
}
|
|
5014
|
+
/**
|
|
5015
|
+
* Execute swap in demo mode
|
|
5016
|
+
*/
|
|
5017
|
+
async executeDemoSwap(result, quote, params) {
|
|
5018
|
+
result.status = "deposit_confirmed";
|
|
5019
|
+
result.sourceTxHash = `0x${this.randomHex(64)}`;
|
|
5020
|
+
this.swaps.set(result.requestId, { ...result });
|
|
5021
|
+
await this.delay(100);
|
|
5022
|
+
result.status = "swapping";
|
|
5023
|
+
this.swaps.set(result.requestId, { ...result });
|
|
5024
|
+
await this.delay(100);
|
|
5025
|
+
result.status = "sending_zec";
|
|
5026
|
+
this.swaps.set(result.requestId, { ...result });
|
|
5027
|
+
if (this.zcashService) {
|
|
5028
|
+
try {
|
|
5029
|
+
const zecAmount = Number(quote.amountOut) / 1e8;
|
|
5030
|
+
const sendResult = await this.zcashService.sendShielded({
|
|
5031
|
+
to: params.recipientZAddress,
|
|
5032
|
+
amount: zecAmount,
|
|
5033
|
+
memo: params.memo ?? `SIP Swap: ${params.sourceToken} \u2192 ZEC`
|
|
5034
|
+
});
|
|
5035
|
+
result.status = "completed";
|
|
5036
|
+
result.zcashTxId = sendResult.txid;
|
|
5037
|
+
result.amountOut = quote.amountOut;
|
|
5038
|
+
} catch (error) {
|
|
5039
|
+
result.status = "completed";
|
|
5040
|
+
result.zcashTxId = this.randomHex(64);
|
|
5041
|
+
result.amountOut = quote.amountOut;
|
|
5042
|
+
}
|
|
5043
|
+
} else {
|
|
5044
|
+
result.status = "completed";
|
|
5045
|
+
result.zcashTxId = this.randomHex(64);
|
|
5046
|
+
result.amountOut = quote.amountOut;
|
|
5047
|
+
}
|
|
5048
|
+
this.swaps.set(result.requestId, { ...result });
|
|
5049
|
+
return result;
|
|
5050
|
+
}
|
|
5051
|
+
/**
|
|
5052
|
+
* Execute swap in production mode
|
|
5053
|
+
*/
|
|
5054
|
+
async executeProductionSwap(result, quote, params) {
|
|
5055
|
+
if (!this.bridgeProvider) {
|
|
5056
|
+
throw new IntentError(
|
|
5057
|
+
"Bridge provider not configured",
|
|
5058
|
+
"SIP_5004" /* INTENT_INVALID_STATE */
|
|
5059
|
+
);
|
|
5060
|
+
}
|
|
5061
|
+
try {
|
|
5062
|
+
const bridgeResult = await this.bridgeProvider.executeSwap({
|
|
5063
|
+
sourceChain: params.sourceChain,
|
|
5064
|
+
sourceToken: params.sourceToken,
|
|
5065
|
+
amount: params.amount,
|
|
5066
|
+
recipientAddress: params.recipientZAddress,
|
|
5067
|
+
quoteId: quote.quoteId,
|
|
5068
|
+
depositAddress: quote.depositAddress
|
|
5069
|
+
});
|
|
5070
|
+
result.sourceTxHash = bridgeResult.txHash;
|
|
5071
|
+
result.status = bridgeResult.status === "completed" ? "completed" : "swapping";
|
|
5072
|
+
if (bridgeResult.amountReceived) {
|
|
5073
|
+
result.amountOut = bridgeResult.amountReceived;
|
|
5074
|
+
}
|
|
5075
|
+
} catch (error) {
|
|
5076
|
+
result.status = "failed";
|
|
5077
|
+
result.error = error instanceof Error ? error.message : "Bridge execution failed";
|
|
5078
|
+
}
|
|
5079
|
+
this.swaps.set(result.requestId, { ...result });
|
|
5080
|
+
return result;
|
|
5081
|
+
}
|
|
5082
|
+
// ─── Status Methods ──────────────────────────────────────────────────────────
|
|
5083
|
+
/**
|
|
5084
|
+
* Get swap status
|
|
5085
|
+
*/
|
|
5086
|
+
async getSwapStatus(requestId) {
|
|
5087
|
+
return this.swaps.get(requestId) ?? null;
|
|
5088
|
+
}
|
|
5089
|
+
/**
|
|
5090
|
+
* Wait for swap completion
|
|
5091
|
+
*/
|
|
5092
|
+
async waitForCompletion(requestId, timeout = 3e5, pollInterval = 5e3) {
|
|
5093
|
+
const startTime = Date.now();
|
|
5094
|
+
while (Date.now() - startTime < timeout) {
|
|
5095
|
+
const status = await this.getSwapStatus(requestId);
|
|
5096
|
+
if (!status) {
|
|
5097
|
+
throw new IntentError(
|
|
5098
|
+
"Swap not found",
|
|
5099
|
+
"SIP_5003" /* INTENT_NOT_FOUND */,
|
|
5100
|
+
{ context: { requestId } }
|
|
5101
|
+
);
|
|
5102
|
+
}
|
|
5103
|
+
if (status.status === "completed") {
|
|
5104
|
+
return status;
|
|
5105
|
+
}
|
|
5106
|
+
if (status.status === "failed" || status.status === "expired") {
|
|
5107
|
+
throw new IntentError(
|
|
5108
|
+
`Swap ${status.status}: ${status.error ?? "Unknown error"}`,
|
|
5109
|
+
"SIP_5000" /* INTENT_FAILED */,
|
|
5110
|
+
{ context: { requestId, status } }
|
|
5111
|
+
);
|
|
5112
|
+
}
|
|
5113
|
+
await this.delay(pollInterval);
|
|
5114
|
+
}
|
|
5115
|
+
throw new NetworkError(
|
|
5116
|
+
"Swap completion timeout",
|
|
5117
|
+
"SIP_6001" /* NETWORK_TIMEOUT */,
|
|
5118
|
+
{ context: { requestId, timeout } }
|
|
5119
|
+
);
|
|
5120
|
+
}
|
|
5121
|
+
// ─── Utility Methods ─────────────────────────────────────────────────────────
|
|
5122
|
+
/**
|
|
5123
|
+
* Get supported source chains
|
|
5124
|
+
*/
|
|
5125
|
+
async getSupportedChains() {
|
|
5126
|
+
if (this.bridgeProvider) {
|
|
5127
|
+
return this.bridgeProvider.getSupportedChains();
|
|
5128
|
+
}
|
|
5129
|
+
return ["ethereum", "solana", "near", "polygon", "arbitrum", "base"];
|
|
5130
|
+
}
|
|
5131
|
+
/**
|
|
5132
|
+
* Get supported source tokens for a chain
|
|
5133
|
+
*/
|
|
5134
|
+
getSupportedTokens(chain) {
|
|
5135
|
+
const tokensByChain = {
|
|
5136
|
+
ethereum: ["ETH", "USDC", "USDT"],
|
|
5137
|
+
solana: ["SOL", "USDC", "USDT"],
|
|
5138
|
+
near: ["NEAR", "USDC", "USDT"],
|
|
5139
|
+
polygon: ["MATIC", "USDC", "USDT"],
|
|
5140
|
+
arbitrum: ["ETH", "USDC", "USDT"],
|
|
5141
|
+
base: ["ETH", "USDC"]
|
|
5142
|
+
};
|
|
5143
|
+
return tokensByChain[chain] ?? [];
|
|
5144
|
+
}
|
|
5145
|
+
/**
|
|
5146
|
+
* Check if a swap route is supported
|
|
5147
|
+
*/
|
|
5148
|
+
isRouteSupported(chain, token) {
|
|
5149
|
+
return this.getSupportedTokens(chain).includes(token);
|
|
5150
|
+
}
|
|
5151
|
+
// ─── Private Helpers ─────────────────────────────────────────────────────────
|
|
5152
|
+
validateQuoteParams(params) {
|
|
5153
|
+
if (!params.sourceChain) {
|
|
5154
|
+
throw new ValidationError("Source chain is required", "sourceChain", void 0, "SIP_2000" /* VALIDATION_FAILED */);
|
|
5155
|
+
}
|
|
5156
|
+
if (!params.sourceToken) {
|
|
5157
|
+
throw new ValidationError("Source token is required", "sourceToken", void 0, "SIP_2000" /* VALIDATION_FAILED */);
|
|
5158
|
+
}
|
|
5159
|
+
if (!params.amount || params.amount <= 0n) {
|
|
5160
|
+
throw new ValidationError("Amount must be positive", "amount", { received: params.amount }, "SIP_2004" /* INVALID_AMOUNT */);
|
|
5161
|
+
}
|
|
5162
|
+
if (!params.recipientZAddress) {
|
|
5163
|
+
throw new ValidationError("Recipient z-address is required", "recipientZAddress", void 0, "SIP_2000" /* VALIDATION_FAILED */);
|
|
5164
|
+
}
|
|
5165
|
+
if (!this.isRouteSupported(params.sourceChain, params.sourceToken)) {
|
|
5166
|
+
throw new ValidationError(
|
|
5167
|
+
`Unsupported swap route: ${params.sourceChain}:${params.sourceToken} \u2192 ZEC`,
|
|
5168
|
+
"sourceToken",
|
|
5169
|
+
{ chain: params.sourceChain, token: params.sourceToken },
|
|
5170
|
+
"SIP_2000" /* VALIDATION_FAILED */
|
|
5171
|
+
);
|
|
5172
|
+
}
|
|
5173
|
+
}
|
|
5174
|
+
isValidZAddressFormat(address) {
|
|
5175
|
+
return address.startsWith("zs1") || address.startsWith("u1") || address.startsWith("ztestsapling") || address.startsWith("utest");
|
|
5176
|
+
}
|
|
5177
|
+
generateMockDepositAddress(chain) {
|
|
5178
|
+
switch (chain) {
|
|
5179
|
+
case "ethereum":
|
|
5180
|
+
case "polygon":
|
|
5181
|
+
case "arbitrum":
|
|
5182
|
+
case "base":
|
|
5183
|
+
return `0x${this.randomHex(40)}`;
|
|
5184
|
+
case "solana":
|
|
5185
|
+
return this.randomBase58(44);
|
|
5186
|
+
case "near":
|
|
5187
|
+
return `deposit_${this.randomHex(8)}.near`;
|
|
5188
|
+
default:
|
|
5189
|
+
return `0x${this.randomHex(40)}`;
|
|
5190
|
+
}
|
|
5191
|
+
}
|
|
5192
|
+
getEstimatedTime(chain) {
|
|
5193
|
+
const times = {
|
|
5194
|
+
ethereum: 900,
|
|
5195
|
+
// ~15 min (confirmations + processing)
|
|
5196
|
+
solana: 300,
|
|
5197
|
+
// ~5 min
|
|
5198
|
+
near: 300,
|
|
5199
|
+
// ~5 min
|
|
5200
|
+
polygon: 600,
|
|
5201
|
+
// ~10 min
|
|
5202
|
+
arbitrum: 600,
|
|
5203
|
+
// ~10 min
|
|
5204
|
+
base: 600
|
|
5205
|
+
// ~10 min
|
|
5206
|
+
};
|
|
5207
|
+
return times[chain] ?? 600;
|
|
5208
|
+
}
|
|
5209
|
+
formatAmount(amount, decimals) {
|
|
5210
|
+
const divisor = 10 ** decimals;
|
|
5211
|
+
const whole = amount / BigInt(divisor);
|
|
5212
|
+
const fraction = amount % BigInt(divisor);
|
|
5213
|
+
const fractionStr = fraction.toString().padStart(decimals, "0").replace(/0+$/, "");
|
|
5214
|
+
return fractionStr ? `${whole}.${fractionStr}` : whole.toString();
|
|
5215
|
+
}
|
|
5216
|
+
randomHex(length) {
|
|
5217
|
+
const chars = "0123456789abcdef";
|
|
5218
|
+
let result = "";
|
|
5219
|
+
for (let i = 0; i < length; i++) {
|
|
5220
|
+
result += chars[Math.floor(Math.random() * chars.length)];
|
|
5221
|
+
}
|
|
5222
|
+
return result;
|
|
5223
|
+
}
|
|
5224
|
+
randomBase58(length) {
|
|
5225
|
+
const chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
5226
|
+
let result = "";
|
|
5227
|
+
for (let i = 0; i < length; i++) {
|
|
5228
|
+
result += chars[Math.floor(Math.random() * chars.length)];
|
|
5229
|
+
}
|
|
5230
|
+
return result;
|
|
5231
|
+
}
|
|
5232
|
+
delay(ms) {
|
|
5233
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
5234
|
+
}
|
|
5235
|
+
};
|
|
5236
|
+
function createZcashSwapService(config) {
|
|
5237
|
+
return new ZcashSwapService(config);
|
|
5238
|
+
}
|
|
5239
|
+
|
|
5240
|
+
// src/zcash/index.ts
|
|
5241
|
+
var import_types11 = require("@sip-protocol/types");
|
|
4810
5242
|
|
|
4811
5243
|
// src/index.ts
|
|
4812
|
-
var
|
|
5244
|
+
var import_types39 = require("@sip-protocol/types");
|
|
4813
5245
|
|
|
4814
5246
|
// src/payment/payment.ts
|
|
4815
|
-
var
|
|
5247
|
+
var import_types12 = require("@sip-protocol/types");
|
|
4816
5248
|
var import_sha2569 = require("@noble/hashes/sha256");
|
|
4817
5249
|
var import_utils11 = require("@noble/hashes/utils");
|
|
4818
5250
|
var import_chacha2 = require("@noble/ciphers/chacha.js");
|
|
@@ -4999,7 +5431,7 @@ var PaymentBuilder = class {
|
|
|
4999
5431
|
_amount;
|
|
5000
5432
|
_recipientMetaAddress;
|
|
5001
5433
|
_recipientAddress;
|
|
5002
|
-
_privacy =
|
|
5434
|
+
_privacy = import_types12.PrivacyLevel.SHIELDED;
|
|
5003
5435
|
_viewingKey;
|
|
5004
5436
|
_sourceChain;
|
|
5005
5437
|
_destinationChain;
|
|
@@ -5282,7 +5714,7 @@ async function createShieldedPayment(params, options) {
|
|
|
5282
5714
|
} else {
|
|
5283
5715
|
resolvedToken = token;
|
|
5284
5716
|
}
|
|
5285
|
-
if (privacy !==
|
|
5717
|
+
if (privacy !== import_types12.PrivacyLevel.TRANSPARENT && !recipientMetaAddress) {
|
|
5286
5718
|
throw new ValidationError(
|
|
5287
5719
|
"recipientMetaAddress is required for shielded/compliant privacy modes",
|
|
5288
5720
|
"recipientMetaAddress",
|
|
@@ -5290,7 +5722,7 @@ async function createShieldedPayment(params, options) {
|
|
|
5290
5722
|
"SIP_2008" /* MISSING_REQUIRED */
|
|
5291
5723
|
);
|
|
5292
5724
|
}
|
|
5293
|
-
if (privacy ===
|
|
5725
|
+
if (privacy === import_types12.PrivacyLevel.TRANSPARENT && !recipientAddress) {
|
|
5294
5726
|
throw new ValidationError(
|
|
5295
5727
|
"recipientAddress is required for transparent mode",
|
|
5296
5728
|
"recipientAddress",
|
|
@@ -5298,7 +5730,7 @@ async function createShieldedPayment(params, options) {
|
|
|
5298
5730
|
"SIP_2008" /* MISSING_REQUIRED */
|
|
5299
5731
|
);
|
|
5300
5732
|
}
|
|
5301
|
-
if (privacy ===
|
|
5733
|
+
if (privacy === import_types12.PrivacyLevel.COMPLIANT && !viewingKey) {
|
|
5302
5734
|
throw new ValidationError(
|
|
5303
5735
|
"viewingKey is required for compliant mode",
|
|
5304
5736
|
"viewingKey",
|
|
@@ -5320,7 +5752,7 @@ async function createShieldedPayment(params, options) {
|
|
|
5320
5752
|
const now = Math.floor(Date.now() / 1e3);
|
|
5321
5753
|
const payment = {
|
|
5322
5754
|
paymentId,
|
|
5323
|
-
version:
|
|
5755
|
+
version: import_types12.SIP_VERSION,
|
|
5324
5756
|
privacyLevel: privacy,
|
|
5325
5757
|
createdAt: now,
|
|
5326
5758
|
expiry: now + ttl,
|
|
@@ -5331,7 +5763,7 @@ async function createShieldedPayment(params, options) {
|
|
|
5331
5763
|
purpose,
|
|
5332
5764
|
viewingKeyHash
|
|
5333
5765
|
};
|
|
5334
|
-
if (privacy !==
|
|
5766
|
+
if (privacy !== import_types12.PrivacyLevel.TRANSPARENT && recipientMetaAddress) {
|
|
5335
5767
|
const metaAddress = decodeStealthMetaAddress(recipientMetaAddress);
|
|
5336
5768
|
const { stealthAddress } = generateStealthAddress(metaAddress);
|
|
5337
5769
|
payment.recipientStealth = stealthAddress;
|
|
@@ -5348,7 +5780,7 @@ async function createShieldedPayment(params, options) {
|
|
|
5348
5780
|
payment.recipientAddress = recipientAddress;
|
|
5349
5781
|
payment.memo = memo;
|
|
5350
5782
|
}
|
|
5351
|
-
if (privacy !==
|
|
5783
|
+
if (privacy !== import_types12.PrivacyLevel.TRANSPARENT && proofProvider?.isReady) {
|
|
5352
5784
|
const hexToUint8 = (hex) => {
|
|
5353
5785
|
const cleanHex = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
5354
5786
|
return (0, import_utils11.hexToBytes)(cleanHex);
|
|
@@ -5414,7 +5846,7 @@ function decryptMemo(encryptedMemo, viewingKey) {
|
|
|
5414
5846
|
function trackPayment(payment) {
|
|
5415
5847
|
return {
|
|
5416
5848
|
...payment,
|
|
5417
|
-
status:
|
|
5849
|
+
status: import_types12.PaymentStatus.DRAFT
|
|
5418
5850
|
};
|
|
5419
5851
|
}
|
|
5420
5852
|
function isPaymentExpired(payment) {
|
|
@@ -5447,7 +5879,7 @@ function getPaymentSummary(payment) {
|
|
|
5447
5879
|
}
|
|
5448
5880
|
|
|
5449
5881
|
// src/treasury/treasury.ts
|
|
5450
|
-
var
|
|
5882
|
+
var import_types13 = require("@sip-protocol/types");
|
|
5451
5883
|
var import_secp256k13 = require("@noble/curves/secp256k1");
|
|
5452
5884
|
var import_sha25610 = require("@noble/hashes/sha256");
|
|
5453
5885
|
var import_utils12 = require("@noble/hashes/utils");
|
|
@@ -5480,7 +5912,7 @@ var Treasury = class _Treasury {
|
|
|
5480
5912
|
...m,
|
|
5481
5913
|
addedAt: now
|
|
5482
5914
|
})),
|
|
5483
|
-
defaultPrivacy: params.defaultPrivacy ??
|
|
5915
|
+
defaultPrivacy: params.defaultPrivacy ?? import_types13.PrivacyLevel.SHIELDED,
|
|
5484
5916
|
masterViewingKey,
|
|
5485
5917
|
dailyLimit: params.dailyLimit,
|
|
5486
5918
|
transactionLimit: params.transactionLimit,
|
|
@@ -5559,7 +5991,7 @@ var Treasury = class _Treasury {
|
|
|
5559
5991
|
proposalId,
|
|
5560
5992
|
treasuryId: this.config.treasuryId,
|
|
5561
5993
|
type: "payment",
|
|
5562
|
-
status:
|
|
5994
|
+
status: import_types13.ProposalStatus.PENDING,
|
|
5563
5995
|
proposer: "",
|
|
5564
5996
|
// Should be set by caller
|
|
5565
5997
|
title: params.title,
|
|
@@ -5592,7 +6024,7 @@ var Treasury = class _Treasury {
|
|
|
5592
6024
|
proposalId,
|
|
5593
6025
|
treasuryId: this.config.treasuryId,
|
|
5594
6026
|
type: "batch_payment",
|
|
5595
|
-
status:
|
|
6027
|
+
status: import_types13.ProposalStatus.PENDING,
|
|
5596
6028
|
proposer: "",
|
|
5597
6029
|
title: params.title,
|
|
5598
6030
|
description: params.description,
|
|
@@ -5626,7 +6058,7 @@ var Treasury = class _Treasury {
|
|
|
5626
6058
|
* Get pending proposals
|
|
5627
6059
|
*/
|
|
5628
6060
|
getPendingProposals() {
|
|
5629
|
-
return this.getAllProposals().filter((p) => p.status ===
|
|
6061
|
+
return this.getAllProposals().filter((p) => p.status === import_types13.ProposalStatus.PENDING);
|
|
5630
6062
|
}
|
|
5631
6063
|
/**
|
|
5632
6064
|
* Sign a proposal
|
|
@@ -5657,7 +6089,7 @@ var Treasury = class _Treasury {
|
|
|
5657
6089
|
"SIP_2001" /* INVALID_INPUT */
|
|
5658
6090
|
);
|
|
5659
6091
|
}
|
|
5660
|
-
if (proposal.status !==
|
|
6092
|
+
if (proposal.status !== import_types13.ProposalStatus.PENDING) {
|
|
5661
6093
|
throw new ValidationError(
|
|
5662
6094
|
`proposal is not pending: ${proposal.status}`,
|
|
5663
6095
|
"proposalId",
|
|
@@ -5667,7 +6099,7 @@ var Treasury = class _Treasury {
|
|
|
5667
6099
|
}
|
|
5668
6100
|
const now = Math.floor(Date.now() / 1e3);
|
|
5669
6101
|
if (now > proposal.expiresAt) {
|
|
5670
|
-
proposal.status =
|
|
6102
|
+
proposal.status = import_types13.ProposalStatus.EXPIRED;
|
|
5671
6103
|
throw new ValidationError(
|
|
5672
6104
|
"proposal has expired",
|
|
5673
6105
|
"proposalId",
|
|
@@ -5699,9 +6131,9 @@ var Treasury = class _Treasury {
|
|
|
5699
6131
|
const approvals = proposal.signatures.filter((s) => s.approved).length;
|
|
5700
6132
|
const rejections = proposal.signatures.filter((s) => !s.approved).length;
|
|
5701
6133
|
if (approvals >= proposal.requiredSignatures) {
|
|
5702
|
-
proposal.status =
|
|
6134
|
+
proposal.status = import_types13.ProposalStatus.APPROVED;
|
|
5703
6135
|
} else if (rejections > this.config.totalSigners - proposal.requiredSignatures) {
|
|
5704
|
-
proposal.status =
|
|
6136
|
+
proposal.status = import_types13.ProposalStatus.REJECTED;
|
|
5705
6137
|
}
|
|
5706
6138
|
return proposal;
|
|
5707
6139
|
}
|
|
@@ -5718,7 +6150,7 @@ var Treasury = class _Treasury {
|
|
|
5718
6150
|
"SIP_2001" /* INVALID_INPUT */
|
|
5719
6151
|
);
|
|
5720
6152
|
}
|
|
5721
|
-
if (proposal.status !==
|
|
6153
|
+
if (proposal.status !== import_types13.ProposalStatus.APPROVED) {
|
|
5722
6154
|
throw new ValidationError(
|
|
5723
6155
|
`proposal is not approved: ${proposal.status}`,
|
|
5724
6156
|
"proposalId",
|
|
@@ -5731,8 +6163,8 @@ var Treasury = class _Treasury {
|
|
|
5731
6163
|
const payment = await createShieldedPayment({
|
|
5732
6164
|
token: proposal.payment.token,
|
|
5733
6165
|
amount: proposal.payment.amount,
|
|
5734
|
-
recipientMetaAddress: proposal.payment.privacy !==
|
|
5735
|
-
recipientAddress: proposal.payment.privacy ===
|
|
6166
|
+
recipientMetaAddress: proposal.payment.privacy !== import_types13.PrivacyLevel.TRANSPARENT ? proposal.payment.recipient : void 0,
|
|
6167
|
+
recipientAddress: proposal.payment.privacy === import_types13.PrivacyLevel.TRANSPARENT ? proposal.payment.recipient : void 0,
|
|
5736
6168
|
privacy: proposal.payment.privacy,
|
|
5737
6169
|
viewingKey: this.config.masterViewingKey?.key,
|
|
5738
6170
|
sourceChain: this.config.chain,
|
|
@@ -5745,8 +6177,8 @@ var Treasury = class _Treasury {
|
|
|
5745
6177
|
const payment = await createShieldedPayment({
|
|
5746
6178
|
token: proposal.batchPayment.token,
|
|
5747
6179
|
amount: recipient.amount,
|
|
5748
|
-
recipientMetaAddress: proposal.batchPayment.privacy !==
|
|
5749
|
-
recipientAddress: proposal.batchPayment.privacy ===
|
|
6180
|
+
recipientMetaAddress: proposal.batchPayment.privacy !== import_types13.PrivacyLevel.TRANSPARENT ? recipient.address : void 0,
|
|
6181
|
+
recipientAddress: proposal.batchPayment.privacy === import_types13.PrivacyLevel.TRANSPARENT ? recipient.address : void 0,
|
|
5750
6182
|
privacy: proposal.batchPayment.privacy,
|
|
5751
6183
|
viewingKey: this.config.masterViewingKey?.key,
|
|
5752
6184
|
sourceChain: this.config.chain,
|
|
@@ -5756,7 +6188,7 @@ var Treasury = class _Treasury {
|
|
|
5756
6188
|
payments.push(payment);
|
|
5757
6189
|
}
|
|
5758
6190
|
}
|
|
5759
|
-
proposal.status =
|
|
6191
|
+
proposal.status = import_types13.ProposalStatus.EXECUTED;
|
|
5760
6192
|
proposal.executedAt = Math.floor(Date.now() / 1e3);
|
|
5761
6193
|
proposal.resultPayments = payments;
|
|
5762
6194
|
return payments;
|
|
@@ -5785,7 +6217,7 @@ var Treasury = class _Treasury {
|
|
|
5785
6217
|
"SIP_2001" /* INVALID_INPUT */
|
|
5786
6218
|
);
|
|
5787
6219
|
}
|
|
5788
|
-
if (proposal.status !==
|
|
6220
|
+
if (proposal.status !== import_types13.ProposalStatus.PENDING) {
|
|
5789
6221
|
throw new ValidationError(
|
|
5790
6222
|
`proposal is not pending: ${proposal.status}`,
|
|
5791
6223
|
"proposalId",
|
|
@@ -5793,7 +6225,7 @@ var Treasury = class _Treasury {
|
|
|
5793
6225
|
"SIP_2001" /* INVALID_INPUT */
|
|
5794
6226
|
);
|
|
5795
6227
|
}
|
|
5796
|
-
proposal.status =
|
|
6228
|
+
proposal.status = import_types13.ProposalStatus.CANCELLED;
|
|
5797
6229
|
return proposal;
|
|
5798
6230
|
}
|
|
5799
6231
|
// ─── Auditor Access ──────────────────────────────────────────────────────────
|
|
@@ -5890,7 +6322,7 @@ var Treasury = class _Treasury {
|
|
|
5890
6322
|
getCommittedAmount(token) {
|
|
5891
6323
|
let committed = 0n;
|
|
5892
6324
|
for (const proposal of this.proposals.values()) {
|
|
5893
|
-
if (proposal.status !==
|
|
6325
|
+
if (proposal.status !== import_types13.ProposalStatus.PENDING) continue;
|
|
5894
6326
|
if (proposal.type === "payment" && proposal.payment) {
|
|
5895
6327
|
if (proposal.payment.token.symbol === token.symbol && proposal.payment.token.chain === token.chain) {
|
|
5896
6328
|
committed += proposal.payment.amount;
|
|
@@ -6133,7 +6565,7 @@ function validateBatchProposalParams(params, config) {
|
|
|
6133
6565
|
}
|
|
6134
6566
|
|
|
6135
6567
|
// src/compliance/compliance-manager.ts
|
|
6136
|
-
var
|
|
6568
|
+
var import_types14 = require("@sip-protocol/types");
|
|
6137
6569
|
var import_utils13 = require("@noble/hashes/utils");
|
|
6138
6570
|
var DEFAULTS2 = {
|
|
6139
6571
|
riskThreshold: 70,
|
|
@@ -6501,7 +6933,7 @@ var ComplianceManager = class _ComplianceManager {
|
|
|
6501
6933
|
title: params.title,
|
|
6502
6934
|
description: params.description,
|
|
6503
6935
|
format: params.format,
|
|
6504
|
-
status:
|
|
6936
|
+
status: import_types14.ReportStatus.GENERATING,
|
|
6505
6937
|
requestedBy,
|
|
6506
6938
|
requestedAt: now,
|
|
6507
6939
|
startDate: params.startDate,
|
|
@@ -6530,10 +6962,10 @@ var ComplianceManager = class _ComplianceManager {
|
|
|
6530
6962
|
} else if (params.format === "csv") {
|
|
6531
6963
|
report.content = this.generateCSV(transactions);
|
|
6532
6964
|
}
|
|
6533
|
-
report.status =
|
|
6965
|
+
report.status = import_types14.ReportStatus.COMPLETED;
|
|
6534
6966
|
report.generatedAt = Math.floor(Date.now() / 1e3);
|
|
6535
6967
|
} catch (error) {
|
|
6536
|
-
report.status =
|
|
6968
|
+
report.status = import_types14.ReportStatus.FAILED;
|
|
6537
6969
|
report.error = error instanceof Error ? error.message : "Unknown error";
|
|
6538
6970
|
}
|
|
6539
6971
|
this.addAuditLog(requestedBy, "report_generated", {
|
|
@@ -6896,10 +7328,10 @@ function validateReportParams(params) {
|
|
|
6896
7328
|
}
|
|
6897
7329
|
|
|
6898
7330
|
// src/wallet/errors.ts
|
|
6899
|
-
var
|
|
7331
|
+
var import_types15 = require("@sip-protocol/types");
|
|
6900
7332
|
var WalletError = class extends SIPError {
|
|
6901
7333
|
walletCode;
|
|
6902
|
-
constructor(message, walletCode =
|
|
7334
|
+
constructor(message, walletCode = import_types15.WalletErrorCode.UNKNOWN, options) {
|
|
6903
7335
|
super(message, "SIP_7000" /* WALLET_ERROR */, options);
|
|
6904
7336
|
this.walletCode = walletCode;
|
|
6905
7337
|
this.name = "WalletError";
|
|
@@ -6909,10 +7341,10 @@ var WalletError = class extends SIPError {
|
|
|
6909
7341
|
*/
|
|
6910
7342
|
isConnectionError() {
|
|
6911
7343
|
const codes = [
|
|
6912
|
-
|
|
6913
|
-
|
|
6914
|
-
|
|
6915
|
-
|
|
7344
|
+
import_types15.WalletErrorCode.NOT_INSTALLED,
|
|
7345
|
+
import_types15.WalletErrorCode.CONNECTION_REJECTED,
|
|
7346
|
+
import_types15.WalletErrorCode.CONNECTION_FAILED,
|
|
7347
|
+
import_types15.WalletErrorCode.NOT_CONNECTED
|
|
6916
7348
|
];
|
|
6917
7349
|
return codes.includes(this.walletCode);
|
|
6918
7350
|
}
|
|
@@ -6921,9 +7353,9 @@ var WalletError = class extends SIPError {
|
|
|
6921
7353
|
*/
|
|
6922
7354
|
isSigningError() {
|
|
6923
7355
|
const codes = [
|
|
6924
|
-
|
|
6925
|
-
|
|
6926
|
-
|
|
7356
|
+
import_types15.WalletErrorCode.SIGNING_REJECTED,
|
|
7357
|
+
import_types15.WalletErrorCode.SIGNING_FAILED,
|
|
7358
|
+
import_types15.WalletErrorCode.INVALID_MESSAGE
|
|
6927
7359
|
];
|
|
6928
7360
|
return codes.includes(this.walletCode);
|
|
6929
7361
|
}
|
|
@@ -6932,10 +7364,10 @@ var WalletError = class extends SIPError {
|
|
|
6932
7364
|
*/
|
|
6933
7365
|
isTransactionError() {
|
|
6934
7366
|
const codes = [
|
|
6935
|
-
|
|
6936
|
-
|
|
6937
|
-
|
|
6938
|
-
|
|
7367
|
+
import_types15.WalletErrorCode.INSUFFICIENT_FUNDS,
|
|
7368
|
+
import_types15.WalletErrorCode.TRANSACTION_REJECTED,
|
|
7369
|
+
import_types15.WalletErrorCode.TRANSACTION_FAILED,
|
|
7370
|
+
import_types15.WalletErrorCode.INVALID_TRANSACTION
|
|
6939
7371
|
];
|
|
6940
7372
|
return codes.includes(this.walletCode);
|
|
6941
7373
|
}
|
|
@@ -6944,9 +7376,9 @@ var WalletError = class extends SIPError {
|
|
|
6944
7376
|
*/
|
|
6945
7377
|
isPrivacyError() {
|
|
6946
7378
|
const codes = [
|
|
6947
|
-
|
|
6948
|
-
|
|
6949
|
-
|
|
7379
|
+
import_types15.WalletErrorCode.STEALTH_NOT_SUPPORTED,
|
|
7380
|
+
import_types15.WalletErrorCode.VIEWING_KEY_NOT_SUPPORTED,
|
|
7381
|
+
import_types15.WalletErrorCode.SHIELDED_NOT_SUPPORTED
|
|
6950
7382
|
];
|
|
6951
7383
|
return codes.includes(this.walletCode);
|
|
6952
7384
|
}
|
|
@@ -6955,10 +7387,10 @@ var WalletError = class extends SIPError {
|
|
|
6955
7387
|
*/
|
|
6956
7388
|
isUserRejection() {
|
|
6957
7389
|
const codes = [
|
|
6958
|
-
|
|
6959
|
-
|
|
6960
|
-
|
|
6961
|
-
|
|
7390
|
+
import_types15.WalletErrorCode.CONNECTION_REJECTED,
|
|
7391
|
+
import_types15.WalletErrorCode.SIGNING_REJECTED,
|
|
7392
|
+
import_types15.WalletErrorCode.TRANSACTION_REJECTED,
|
|
7393
|
+
import_types15.WalletErrorCode.CHAIN_SWITCH_REJECTED
|
|
6962
7394
|
];
|
|
6963
7395
|
return codes.includes(this.walletCode);
|
|
6964
7396
|
}
|
|
@@ -6966,15 +7398,15 @@ var WalletError = class extends SIPError {
|
|
|
6966
7398
|
function notConnectedError() {
|
|
6967
7399
|
return new WalletError(
|
|
6968
7400
|
"Wallet not connected. Call connect() first.",
|
|
6969
|
-
|
|
7401
|
+
import_types15.WalletErrorCode.NOT_CONNECTED
|
|
6970
7402
|
);
|
|
6971
7403
|
}
|
|
6972
|
-
function featureNotSupportedError(feature, code =
|
|
7404
|
+
function featureNotSupportedError(feature, code = import_types15.WalletErrorCode.UNKNOWN) {
|
|
6973
7405
|
return new WalletError(`${feature} is not supported by this wallet`, code);
|
|
6974
7406
|
}
|
|
6975
7407
|
|
|
6976
7408
|
// src/wallet/base-adapter.ts
|
|
6977
|
-
var
|
|
7409
|
+
var import_types16 = require("@sip-protocol/types");
|
|
6978
7410
|
var BaseWalletAdapter = class {
|
|
6979
7411
|
_address = "";
|
|
6980
7412
|
_publicKey = "";
|
|
@@ -7137,12 +7569,12 @@ var MockWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7137
7569
|
this._connectionState = "connecting";
|
|
7138
7570
|
if (this.shouldFailConnect) {
|
|
7139
7571
|
this.setError(
|
|
7140
|
-
|
|
7572
|
+
import_types16.WalletErrorCode.CONNECTION_FAILED,
|
|
7141
7573
|
"Mock connection failure"
|
|
7142
7574
|
);
|
|
7143
7575
|
throw new WalletError(
|
|
7144
7576
|
"Mock connection failure",
|
|
7145
|
-
|
|
7577
|
+
import_types16.WalletErrorCode.CONNECTION_FAILED
|
|
7146
7578
|
);
|
|
7147
7579
|
}
|
|
7148
7580
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
@@ -7154,7 +7586,7 @@ var MockWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7154
7586
|
async signMessage(message) {
|
|
7155
7587
|
this.requireConnected();
|
|
7156
7588
|
if (this.shouldFailSign) {
|
|
7157
|
-
throw new WalletError("Mock signing failure",
|
|
7589
|
+
throw new WalletError("Mock signing failure", import_types16.WalletErrorCode.SIGNING_FAILED);
|
|
7158
7590
|
}
|
|
7159
7591
|
const mockSig = new Uint8Array(64);
|
|
7160
7592
|
for (let i = 0; i < 64; i++) {
|
|
@@ -7169,7 +7601,7 @@ var MockWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7169
7601
|
async signTransaction(tx) {
|
|
7170
7602
|
this.requireConnected();
|
|
7171
7603
|
if (this.shouldFailSign) {
|
|
7172
|
-
throw new WalletError("Mock signing failure",
|
|
7604
|
+
throw new WalletError("Mock signing failure", import_types16.WalletErrorCode.SIGNING_FAILED);
|
|
7173
7605
|
}
|
|
7174
7606
|
const signature = await this.signMessage(
|
|
7175
7607
|
new TextEncoder().encode(JSON.stringify(tx.data))
|
|
@@ -7351,7 +7783,7 @@ function isPrivateWalletAdapter(adapter) {
|
|
|
7351
7783
|
}
|
|
7352
7784
|
|
|
7353
7785
|
// src/wallet/solana/adapter.ts
|
|
7354
|
-
var
|
|
7786
|
+
var import_types17 = require("@sip-protocol/types");
|
|
7355
7787
|
|
|
7356
7788
|
// src/wallet/solana/types.ts
|
|
7357
7789
|
function getSolanaProvider(wallet = "phantom") {
|
|
@@ -7472,19 +7904,19 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7472
7904
|
}
|
|
7473
7905
|
if (!this.provider) {
|
|
7474
7906
|
this.setError(
|
|
7475
|
-
|
|
7907
|
+
import_types17.WalletErrorCode.NOT_INSTALLED,
|
|
7476
7908
|
`${this.walletName} wallet is not installed`
|
|
7477
7909
|
);
|
|
7478
7910
|
throw new WalletError(
|
|
7479
7911
|
`${this.walletName} wallet is not installed`,
|
|
7480
|
-
|
|
7912
|
+
import_types17.WalletErrorCode.NOT_INSTALLED
|
|
7481
7913
|
);
|
|
7482
7914
|
}
|
|
7483
7915
|
const { publicKey } = await this.provider.connect();
|
|
7484
7916
|
if (!publicKey) {
|
|
7485
7917
|
throw new WalletError(
|
|
7486
7918
|
"No public key returned from wallet",
|
|
7487
|
-
|
|
7919
|
+
import_types17.WalletErrorCode.CONNECTION_FAILED
|
|
7488
7920
|
);
|
|
7489
7921
|
}
|
|
7490
7922
|
this.setupEventHandlers();
|
|
@@ -7494,11 +7926,11 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7494
7926
|
} catch (error) {
|
|
7495
7927
|
const message = error instanceof Error ? error.message : "Connection failed";
|
|
7496
7928
|
if (message.includes("User rejected") || message.includes("rejected")) {
|
|
7497
|
-
this.setError(
|
|
7498
|
-
throw new WalletError(message,
|
|
7929
|
+
this.setError(import_types17.WalletErrorCode.CONNECTION_REJECTED, message);
|
|
7930
|
+
throw new WalletError(message, import_types17.WalletErrorCode.CONNECTION_REJECTED);
|
|
7499
7931
|
}
|
|
7500
|
-
this.setError(
|
|
7501
|
-
throw error instanceof WalletError ? error : new WalletError(message,
|
|
7932
|
+
this.setError(import_types17.WalletErrorCode.CONNECTION_FAILED, message);
|
|
7933
|
+
throw error instanceof WalletError ? error : new WalletError(message, import_types17.WalletErrorCode.CONNECTION_FAILED, { cause: error });
|
|
7502
7934
|
}
|
|
7503
7935
|
}
|
|
7504
7936
|
/**
|
|
@@ -7521,7 +7953,7 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7521
7953
|
async signMessage(message) {
|
|
7522
7954
|
this.requireConnected();
|
|
7523
7955
|
if (!this.provider) {
|
|
7524
|
-
throw new WalletError("Provider not available",
|
|
7956
|
+
throw new WalletError("Provider not available", import_types17.WalletErrorCode.NOT_CONNECTED);
|
|
7525
7957
|
}
|
|
7526
7958
|
try {
|
|
7527
7959
|
const { signature } = await this.provider.signMessage(message);
|
|
@@ -7532,9 +7964,9 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7532
7964
|
} catch (error) {
|
|
7533
7965
|
const message2 = error instanceof Error ? error.message : "Signing failed";
|
|
7534
7966
|
if (message2.includes("User rejected") || message2.includes("rejected")) {
|
|
7535
|
-
throw new WalletError(message2,
|
|
7967
|
+
throw new WalletError(message2, import_types17.WalletErrorCode.SIGNING_REJECTED);
|
|
7536
7968
|
}
|
|
7537
|
-
throw new WalletError(message2,
|
|
7969
|
+
throw new WalletError(message2, import_types17.WalletErrorCode.SIGNING_FAILED, {
|
|
7538
7970
|
cause: error
|
|
7539
7971
|
});
|
|
7540
7972
|
}
|
|
@@ -7547,7 +7979,7 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7547
7979
|
async signTransaction(tx) {
|
|
7548
7980
|
this.requireConnected();
|
|
7549
7981
|
if (!this.provider) {
|
|
7550
|
-
throw new WalletError("Provider not available",
|
|
7982
|
+
throw new WalletError("Provider not available", import_types17.WalletErrorCode.NOT_CONNECTED);
|
|
7551
7983
|
}
|
|
7552
7984
|
try {
|
|
7553
7985
|
const solTx = tx.data;
|
|
@@ -7566,9 +7998,9 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7566
7998
|
} catch (error) {
|
|
7567
7999
|
const message = error instanceof Error ? error.message : "Signing failed";
|
|
7568
8000
|
if (message.includes("User rejected") || message.includes("rejected")) {
|
|
7569
|
-
throw new WalletError(message,
|
|
8001
|
+
throw new WalletError(message, import_types17.WalletErrorCode.SIGNING_REJECTED);
|
|
7570
8002
|
}
|
|
7571
|
-
throw new WalletError(message,
|
|
8003
|
+
throw new WalletError(message, import_types17.WalletErrorCode.SIGNING_FAILED, {
|
|
7572
8004
|
cause: error
|
|
7573
8005
|
});
|
|
7574
8006
|
}
|
|
@@ -7579,7 +8011,7 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7579
8011
|
async signAndSendTransaction(tx) {
|
|
7580
8012
|
this.requireConnected();
|
|
7581
8013
|
if (!this.provider) {
|
|
7582
|
-
throw new WalletError("Provider not available",
|
|
8014
|
+
throw new WalletError("Provider not available", import_types17.WalletErrorCode.NOT_CONNECTED);
|
|
7583
8015
|
}
|
|
7584
8016
|
try {
|
|
7585
8017
|
const solTx = tx.data;
|
|
@@ -7594,12 +8026,12 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7594
8026
|
} catch (error) {
|
|
7595
8027
|
const message = error instanceof Error ? error.message : "Transaction failed";
|
|
7596
8028
|
if (message.includes("User rejected") || message.includes("rejected")) {
|
|
7597
|
-
throw new WalletError(message,
|
|
8029
|
+
throw new WalletError(message, import_types17.WalletErrorCode.TRANSACTION_REJECTED);
|
|
7598
8030
|
}
|
|
7599
8031
|
if (message.includes("insufficient") || message.includes("Insufficient")) {
|
|
7600
|
-
throw new WalletError(message,
|
|
8032
|
+
throw new WalletError(message, import_types17.WalletErrorCode.INSUFFICIENT_FUNDS);
|
|
7601
8033
|
}
|
|
7602
|
-
throw new WalletError(message,
|
|
8034
|
+
throw new WalletError(message, import_types17.WalletErrorCode.TRANSACTION_FAILED, {
|
|
7603
8035
|
cause: error
|
|
7604
8036
|
});
|
|
7605
8037
|
}
|
|
@@ -7612,16 +8044,16 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7612
8044
|
async signAllTransactions(transactions) {
|
|
7613
8045
|
this.requireConnected();
|
|
7614
8046
|
if (!this.provider) {
|
|
7615
|
-
throw new WalletError("Provider not available",
|
|
8047
|
+
throw new WalletError("Provider not available", import_types17.WalletErrorCode.NOT_CONNECTED);
|
|
7616
8048
|
}
|
|
7617
8049
|
try {
|
|
7618
8050
|
return await this.provider.signAllTransactions(transactions);
|
|
7619
8051
|
} catch (error) {
|
|
7620
8052
|
const message = error instanceof Error ? error.message : "Signing failed";
|
|
7621
8053
|
if (message.includes("User rejected") || message.includes("rejected")) {
|
|
7622
|
-
throw new WalletError(message,
|
|
8054
|
+
throw new WalletError(message, import_types17.WalletErrorCode.SIGNING_REJECTED);
|
|
7623
8055
|
}
|
|
7624
|
-
throw new WalletError(message,
|
|
8056
|
+
throw new WalletError(message, import_types17.WalletErrorCode.SIGNING_FAILED, {
|
|
7625
8057
|
cause: error
|
|
7626
8058
|
});
|
|
7627
8059
|
}
|
|
@@ -7642,7 +8074,7 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7642
8074
|
} catch (error) {
|
|
7643
8075
|
throw new WalletError(
|
|
7644
8076
|
"Failed to get balance",
|
|
7645
|
-
|
|
8077
|
+
import_types17.WalletErrorCode.UNKNOWN,
|
|
7646
8078
|
{ cause: error }
|
|
7647
8079
|
);
|
|
7648
8080
|
}
|
|
@@ -7655,7 +8087,7 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7655
8087
|
if (asset.chain !== "solana") {
|
|
7656
8088
|
throw new WalletError(
|
|
7657
8089
|
`Asset chain ${asset.chain} not supported by Solana adapter`,
|
|
7658
|
-
|
|
8090
|
+
import_types17.WalletErrorCode.UNSUPPORTED_CHAIN
|
|
7659
8091
|
);
|
|
7660
8092
|
}
|
|
7661
8093
|
if (!asset.address) {
|
|
@@ -7773,7 +8205,7 @@ function createSolanaAdapter(config = {}) {
|
|
|
7773
8205
|
}
|
|
7774
8206
|
|
|
7775
8207
|
// src/wallet/solana/mock.ts
|
|
7776
|
-
var
|
|
8208
|
+
var import_types19 = require("@sip-protocol/types");
|
|
7777
8209
|
var MockPublicKey = class {
|
|
7778
8210
|
base58;
|
|
7779
8211
|
bytes;
|
|
@@ -7839,8 +8271,8 @@ var MockSolanaAdapter = class extends BaseWalletAdapter {
|
|
|
7839
8271
|
this._connectionState = "connecting";
|
|
7840
8272
|
await this.simulateLatency();
|
|
7841
8273
|
if (this.shouldFailConnect) {
|
|
7842
|
-
this.setError(
|
|
7843
|
-
throw new WalletError("Mock connection failure",
|
|
8274
|
+
this.setError(import_types19.WalletErrorCode.CONNECTION_FAILED, "Mock connection failure");
|
|
8275
|
+
throw new WalletError("Mock connection failure", import_types19.WalletErrorCode.CONNECTION_FAILED);
|
|
7844
8276
|
}
|
|
7845
8277
|
const hexPubKey = "0x" + Buffer.from(this.mockPublicKey.toBytes()).toString("hex");
|
|
7846
8278
|
this.setConnected(this.mockAddress, hexPubKey);
|
|
@@ -7859,7 +8291,7 @@ var MockSolanaAdapter = class extends BaseWalletAdapter {
|
|
|
7859
8291
|
this.requireConnected();
|
|
7860
8292
|
await this.simulateLatency();
|
|
7861
8293
|
if (this.shouldFailSign) {
|
|
7862
|
-
throw new WalletError("Mock signing failure",
|
|
8294
|
+
throw new WalletError("Mock signing failure", import_types19.WalletErrorCode.SIGNING_REJECTED);
|
|
7863
8295
|
}
|
|
7864
8296
|
const mockSig = new Uint8Array(64);
|
|
7865
8297
|
for (let i = 0; i < 64; i++) {
|
|
@@ -7877,7 +8309,7 @@ var MockSolanaAdapter = class extends BaseWalletAdapter {
|
|
|
7877
8309
|
this.requireConnected();
|
|
7878
8310
|
await this.simulateLatency();
|
|
7879
8311
|
if (this.shouldFailSign) {
|
|
7880
|
-
throw new WalletError("Mock signing failure",
|
|
8312
|
+
throw new WalletError("Mock signing failure", import_types19.WalletErrorCode.SIGNING_REJECTED);
|
|
7881
8313
|
}
|
|
7882
8314
|
const solTx = tx.data;
|
|
7883
8315
|
this.signedTransactions.push(solTx);
|
|
@@ -7897,10 +8329,10 @@ var MockSolanaAdapter = class extends BaseWalletAdapter {
|
|
|
7897
8329
|
this.requireConnected();
|
|
7898
8330
|
await this.simulateLatency();
|
|
7899
8331
|
if (this.shouldFailSign) {
|
|
7900
|
-
throw new WalletError("Mock signing failure",
|
|
8332
|
+
throw new WalletError("Mock signing failure", import_types19.WalletErrorCode.SIGNING_REJECTED);
|
|
7901
8333
|
}
|
|
7902
8334
|
if (this.shouldFailTransaction) {
|
|
7903
|
-
throw new WalletError("Mock transaction failure",
|
|
8335
|
+
throw new WalletError("Mock transaction failure", import_types19.WalletErrorCode.TRANSACTION_FAILED);
|
|
7904
8336
|
}
|
|
7905
8337
|
const txSig = `mock_tx_${Date.now()}_${Math.random().toString(36).slice(2)}`;
|
|
7906
8338
|
this.sentTransactions.push(txSig);
|
|
@@ -7920,7 +8352,7 @@ var MockSolanaAdapter = class extends BaseWalletAdapter {
|
|
|
7920
8352
|
this.requireConnected();
|
|
7921
8353
|
await this.simulateLatency();
|
|
7922
8354
|
if (this.shouldFailSign) {
|
|
7923
|
-
throw new WalletError("Mock signing failure",
|
|
8355
|
+
throw new WalletError("Mock signing failure", import_types19.WalletErrorCode.SIGNING_REJECTED);
|
|
7924
8356
|
}
|
|
7925
8357
|
this.signedTransactions.push(...transactions);
|
|
7926
8358
|
return transactions.map((tx) => {
|
|
@@ -7947,7 +8379,7 @@ var MockSolanaAdapter = class extends BaseWalletAdapter {
|
|
|
7947
8379
|
if (asset.chain !== "solana") {
|
|
7948
8380
|
throw new WalletError(
|
|
7949
8381
|
`Asset chain ${asset.chain} not supported by Solana adapter`,
|
|
7950
|
-
|
|
8382
|
+
import_types19.WalletErrorCode.UNSUPPORTED_CHAIN
|
|
7951
8383
|
);
|
|
7952
8384
|
}
|
|
7953
8385
|
if (!asset.address) {
|
|
@@ -8116,7 +8548,7 @@ function createMockSolanaAdapter(config = {}) {
|
|
|
8116
8548
|
}
|
|
8117
8549
|
|
|
8118
8550
|
// src/wallet/ethereum/adapter.ts
|
|
8119
|
-
var
|
|
8551
|
+
var import_types21 = require("@sip-protocol/types");
|
|
8120
8552
|
|
|
8121
8553
|
// src/wallet/ethereum/types.ts
|
|
8122
8554
|
var EthereumChainId = {
|
|
@@ -8258,7 +8690,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8258
8690
|
this._connectionState = "error";
|
|
8259
8691
|
throw new WalletError(
|
|
8260
8692
|
`${this.walletType} wallet not found. Please install the extension.`,
|
|
8261
|
-
|
|
8693
|
+
import_types21.WalletErrorCode.NOT_INSTALLED
|
|
8262
8694
|
);
|
|
8263
8695
|
}
|
|
8264
8696
|
const accounts = await this.provider.request({
|
|
@@ -8268,7 +8700,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8268
8700
|
this._connectionState = "error";
|
|
8269
8701
|
throw new WalletError(
|
|
8270
8702
|
"No accounts returned from wallet",
|
|
8271
|
-
|
|
8703
|
+
import_types21.WalletErrorCode.CONNECTION_REJECTED
|
|
8272
8704
|
);
|
|
8273
8705
|
}
|
|
8274
8706
|
const address = normalizeAddress(accounts[0]);
|
|
@@ -8288,12 +8720,12 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8288
8720
|
if (rpcError.code === 4001) {
|
|
8289
8721
|
throw new WalletError(
|
|
8290
8722
|
"User rejected connection request",
|
|
8291
|
-
|
|
8723
|
+
import_types21.WalletErrorCode.CONNECTION_REJECTED
|
|
8292
8724
|
);
|
|
8293
8725
|
}
|
|
8294
8726
|
throw new WalletError(
|
|
8295
8727
|
`Failed to connect: ${rpcError.message || String(error)}`,
|
|
8296
|
-
|
|
8728
|
+
import_types21.WalletErrorCode.CONNECTION_FAILED
|
|
8297
8729
|
);
|
|
8298
8730
|
}
|
|
8299
8731
|
}
|
|
@@ -8313,7 +8745,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8313
8745
|
if (!this.provider) {
|
|
8314
8746
|
throw new WalletError(
|
|
8315
8747
|
"Provider not available",
|
|
8316
|
-
|
|
8748
|
+
import_types21.WalletErrorCode.NOT_CONNECTED
|
|
8317
8749
|
);
|
|
8318
8750
|
}
|
|
8319
8751
|
try {
|
|
@@ -8331,12 +8763,12 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8331
8763
|
if (rpcError.code === 4001) {
|
|
8332
8764
|
throw new WalletError(
|
|
8333
8765
|
"User rejected signing request",
|
|
8334
|
-
|
|
8766
|
+
import_types21.WalletErrorCode.SIGNING_REJECTED
|
|
8335
8767
|
);
|
|
8336
8768
|
}
|
|
8337
8769
|
throw new WalletError(
|
|
8338
8770
|
`Failed to sign message: ${rpcError.message || String(error)}`,
|
|
8339
|
-
|
|
8771
|
+
import_types21.WalletErrorCode.SIGNING_FAILED
|
|
8340
8772
|
);
|
|
8341
8773
|
}
|
|
8342
8774
|
}
|
|
@@ -8348,7 +8780,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8348
8780
|
if (!this.provider) {
|
|
8349
8781
|
throw new WalletError(
|
|
8350
8782
|
"Provider not available",
|
|
8351
|
-
|
|
8783
|
+
import_types21.WalletErrorCode.NOT_CONNECTED
|
|
8352
8784
|
);
|
|
8353
8785
|
}
|
|
8354
8786
|
try {
|
|
@@ -8365,12 +8797,12 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8365
8797
|
if (rpcError.code === 4001) {
|
|
8366
8798
|
throw new WalletError(
|
|
8367
8799
|
"User rejected signing request",
|
|
8368
|
-
|
|
8800
|
+
import_types21.WalletErrorCode.SIGNING_REJECTED
|
|
8369
8801
|
);
|
|
8370
8802
|
}
|
|
8371
8803
|
throw new WalletError(
|
|
8372
8804
|
`Failed to sign typed data: ${rpcError.message || String(error)}`,
|
|
8373
|
-
|
|
8805
|
+
import_types21.WalletErrorCode.SIGNING_FAILED
|
|
8374
8806
|
);
|
|
8375
8807
|
}
|
|
8376
8808
|
}
|
|
@@ -8382,7 +8814,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8382
8814
|
if (!this.provider) {
|
|
8383
8815
|
throw new WalletError(
|
|
8384
8816
|
"Provider not available",
|
|
8385
|
-
|
|
8817
|
+
import_types21.WalletErrorCode.NOT_CONNECTED
|
|
8386
8818
|
);
|
|
8387
8819
|
}
|
|
8388
8820
|
try {
|
|
@@ -8410,7 +8842,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8410
8842
|
if (rpcError.code === 4001) {
|
|
8411
8843
|
throw new WalletError(
|
|
8412
8844
|
"User rejected transaction signing",
|
|
8413
|
-
|
|
8845
|
+
import_types21.WalletErrorCode.SIGNING_REJECTED
|
|
8414
8846
|
);
|
|
8415
8847
|
}
|
|
8416
8848
|
if (rpcError.code === -32601 || rpcError.message?.includes("not supported")) {
|
|
@@ -8428,7 +8860,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8428
8860
|
}
|
|
8429
8861
|
throw new WalletError(
|
|
8430
8862
|
`Failed to sign transaction: ${rpcError.message || String(error)}`,
|
|
8431
|
-
|
|
8863
|
+
import_types21.WalletErrorCode.TRANSACTION_FAILED
|
|
8432
8864
|
);
|
|
8433
8865
|
}
|
|
8434
8866
|
}
|
|
@@ -8440,7 +8872,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8440
8872
|
if (!this.provider) {
|
|
8441
8873
|
throw new WalletError(
|
|
8442
8874
|
"Provider not available",
|
|
8443
|
-
|
|
8875
|
+
import_types21.WalletErrorCode.NOT_CONNECTED
|
|
8444
8876
|
);
|
|
8445
8877
|
}
|
|
8446
8878
|
try {
|
|
@@ -8462,12 +8894,12 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8462
8894
|
if (rpcError.code === 4001) {
|
|
8463
8895
|
throw new WalletError(
|
|
8464
8896
|
"User rejected transaction",
|
|
8465
|
-
|
|
8897
|
+
import_types21.WalletErrorCode.TRANSACTION_REJECTED
|
|
8466
8898
|
);
|
|
8467
8899
|
}
|
|
8468
8900
|
throw new WalletError(
|
|
8469
8901
|
`Failed to send transaction: ${rpcError.message || String(error)}`,
|
|
8470
|
-
|
|
8902
|
+
import_types21.WalletErrorCode.TRANSACTION_FAILED
|
|
8471
8903
|
);
|
|
8472
8904
|
}
|
|
8473
8905
|
}
|
|
@@ -8502,7 +8934,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8502
8934
|
} catch (error) {
|
|
8503
8935
|
throw new WalletError(
|
|
8504
8936
|
`Failed to fetch balance: ${String(error)}`,
|
|
8505
|
-
|
|
8937
|
+
import_types21.WalletErrorCode.UNKNOWN
|
|
8506
8938
|
);
|
|
8507
8939
|
}
|
|
8508
8940
|
}
|
|
@@ -8514,7 +8946,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8514
8946
|
if (asset.chain !== "ethereum") {
|
|
8515
8947
|
throw new WalletError(
|
|
8516
8948
|
`Asset chain ${asset.chain} not supported by Ethereum adapter`,
|
|
8517
|
-
|
|
8949
|
+
import_types21.WalletErrorCode.UNSUPPORTED_CHAIN
|
|
8518
8950
|
);
|
|
8519
8951
|
}
|
|
8520
8952
|
if (!asset.address) {
|
|
@@ -8539,7 +8971,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8539
8971
|
} catch (error) {
|
|
8540
8972
|
throw new WalletError(
|
|
8541
8973
|
`Failed to fetch token balance: ${String(error)}`,
|
|
8542
|
-
|
|
8974
|
+
import_types21.WalletErrorCode.UNKNOWN
|
|
8543
8975
|
);
|
|
8544
8976
|
}
|
|
8545
8977
|
}
|
|
@@ -8551,7 +8983,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8551
8983
|
if (!this.provider) {
|
|
8552
8984
|
throw new WalletError(
|
|
8553
8985
|
"Provider not available",
|
|
8554
|
-
|
|
8986
|
+
import_types21.WalletErrorCode.NOT_CONNECTED
|
|
8555
8987
|
);
|
|
8556
8988
|
}
|
|
8557
8989
|
try {
|
|
@@ -8566,18 +8998,18 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8566
8998
|
if (rpcError.code === 4001) {
|
|
8567
8999
|
throw new WalletError(
|
|
8568
9000
|
"User rejected chain switch",
|
|
8569
|
-
|
|
9001
|
+
import_types21.WalletErrorCode.CHAIN_SWITCH_REJECTED
|
|
8570
9002
|
);
|
|
8571
9003
|
}
|
|
8572
9004
|
if (rpcError.code === 4902) {
|
|
8573
9005
|
throw new WalletError(
|
|
8574
9006
|
`Chain ${chainId} not added to wallet`,
|
|
8575
|
-
|
|
9007
|
+
import_types21.WalletErrorCode.UNSUPPORTED_CHAIN
|
|
8576
9008
|
);
|
|
8577
9009
|
}
|
|
8578
9010
|
throw new WalletError(
|
|
8579
9011
|
`Failed to switch chain: ${rpcError.message || String(error)}`,
|
|
8580
|
-
|
|
9012
|
+
import_types21.WalletErrorCode.CHAIN_SWITCH_FAILED
|
|
8581
9013
|
);
|
|
8582
9014
|
}
|
|
8583
9015
|
}
|
|
@@ -8613,7 +9045,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8613
9045
|
}
|
|
8614
9046
|
throw new WalletError(
|
|
8615
9047
|
`Transaction ${txHash} not confirmed after ${maxAttempts * 5} seconds`,
|
|
8616
|
-
|
|
9048
|
+
import_types21.WalletErrorCode.TRANSACTION_FAILED
|
|
8617
9049
|
);
|
|
8618
9050
|
}
|
|
8619
9051
|
/**
|
|
@@ -8687,7 +9119,7 @@ function createEthereumAdapter(config) {
|
|
|
8687
9119
|
}
|
|
8688
9120
|
|
|
8689
9121
|
// src/wallet/ethereum/mock.ts
|
|
8690
|
-
var
|
|
9122
|
+
var import_types23 = require("@sip-protocol/types");
|
|
8691
9123
|
var MockEthereumAdapter = class extends BaseWalletAdapter {
|
|
8692
9124
|
chain = "ethereum";
|
|
8693
9125
|
name = "mock-ethereum";
|
|
@@ -8728,7 +9160,7 @@ var MockEthereumAdapter = class extends BaseWalletAdapter {
|
|
|
8728
9160
|
this._connectionState = "error";
|
|
8729
9161
|
throw new WalletError(
|
|
8730
9162
|
"Mock connection rejected",
|
|
8731
|
-
|
|
9163
|
+
import_types23.WalletErrorCode.CONNECTION_REJECTED
|
|
8732
9164
|
);
|
|
8733
9165
|
}
|
|
8734
9166
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
@@ -8740,7 +9172,7 @@ var MockEthereumAdapter = class extends BaseWalletAdapter {
|
|
|
8740
9172
|
this._connectionState = "error";
|
|
8741
9173
|
throw new WalletError(
|
|
8742
9174
|
`Mock connection failed: ${String(error)}`,
|
|
8743
|
-
|
|
9175
|
+
import_types23.WalletErrorCode.CONNECTION_FAILED
|
|
8744
9176
|
);
|
|
8745
9177
|
}
|
|
8746
9178
|
}
|
|
@@ -8758,7 +9190,7 @@ var MockEthereumAdapter = class extends BaseWalletAdapter {
|
|
|
8758
9190
|
if (this._shouldFailSign) {
|
|
8759
9191
|
throw new WalletError(
|
|
8760
9192
|
"Mock signing rejected",
|
|
8761
|
-
|
|
9193
|
+
import_types23.WalletErrorCode.SIGNING_REJECTED
|
|
8762
9194
|
);
|
|
8763
9195
|
}
|
|
8764
9196
|
const msgHex = Buffer.from(message).toString("hex");
|
|
@@ -8776,7 +9208,7 @@ var MockEthereumAdapter = class extends BaseWalletAdapter {
|
|
|
8776
9208
|
if (this._shouldFailSign) {
|
|
8777
9209
|
throw new WalletError(
|
|
8778
9210
|
"Mock signing rejected",
|
|
8779
|
-
|
|
9211
|
+
import_types23.WalletErrorCode.SIGNING_REJECTED
|
|
8780
9212
|
);
|
|
8781
9213
|
}
|
|
8782
9214
|
const mockSig = `0x${"1".repeat(130)}`;
|
|
@@ -8793,7 +9225,7 @@ var MockEthereumAdapter = class extends BaseWalletAdapter {
|
|
|
8793
9225
|
if (this._shouldFailSign) {
|
|
8794
9226
|
throw new WalletError(
|
|
8795
9227
|
"Mock signing rejected",
|
|
8796
|
-
|
|
9228
|
+
import_types23.WalletErrorCode.SIGNING_REJECTED
|
|
8797
9229
|
);
|
|
8798
9230
|
}
|
|
8799
9231
|
this._signedTransactions.push(tx);
|
|
@@ -8818,7 +9250,7 @@ var MockEthereumAdapter = class extends BaseWalletAdapter {
|
|
|
8818
9250
|
if (this._shouldFailTransaction) {
|
|
8819
9251
|
throw new WalletError(
|
|
8820
9252
|
"Mock transaction failed",
|
|
8821
|
-
|
|
9253
|
+
import_types23.WalletErrorCode.TRANSACTION_FAILED
|
|
8822
9254
|
);
|
|
8823
9255
|
}
|
|
8824
9256
|
this._signedTransactions.push(tx);
|
|
@@ -8848,7 +9280,7 @@ var MockEthereumAdapter = class extends BaseWalletAdapter {
|
|
|
8848
9280
|
if (asset.chain !== "ethereum") {
|
|
8849
9281
|
throw new WalletError(
|
|
8850
9282
|
`Asset chain ${asset.chain} not supported by Ethereum adapter`,
|
|
8851
|
-
|
|
9283
|
+
import_types23.WalletErrorCode.UNSUPPORTED_CHAIN
|
|
8852
9284
|
);
|
|
8853
9285
|
}
|
|
8854
9286
|
if (!asset.address) {
|
|
@@ -9127,7 +9559,7 @@ function getAvailableTransports() {
|
|
|
9127
9559
|
}
|
|
9128
9560
|
|
|
9129
9561
|
// src/wallet/hardware/ledger.ts
|
|
9130
|
-
var
|
|
9562
|
+
var import_types26 = require("@sip-protocol/types");
|
|
9131
9563
|
var LedgerWalletAdapter = class extends BaseWalletAdapter {
|
|
9132
9564
|
chain;
|
|
9133
9565
|
name = "ledger";
|
|
@@ -9280,7 +9712,7 @@ var LedgerWalletAdapter = class extends BaseWalletAdapter {
|
|
|
9280
9712
|
async getBalance() {
|
|
9281
9713
|
throw new WalletError(
|
|
9282
9714
|
"Hardware wallets do not track balances. Use an RPC provider.",
|
|
9283
|
-
|
|
9715
|
+
import_types26.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
9284
9716
|
);
|
|
9285
9717
|
}
|
|
9286
9718
|
/**
|
|
@@ -9291,7 +9723,7 @@ var LedgerWalletAdapter = class extends BaseWalletAdapter {
|
|
|
9291
9723
|
async getTokenBalance(_asset) {
|
|
9292
9724
|
throw new WalletError(
|
|
9293
9725
|
"Hardware wallets do not track balances. Use an RPC provider.",
|
|
9294
|
-
|
|
9726
|
+
import_types26.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
9295
9727
|
);
|
|
9296
9728
|
}
|
|
9297
9729
|
// ─── Account Management ─────────────────────────────────────────────────────
|
|
@@ -9579,7 +10011,7 @@ function createLedgerAdapter(config) {
|
|
|
9579
10011
|
}
|
|
9580
10012
|
|
|
9581
10013
|
// src/wallet/hardware/trezor.ts
|
|
9582
|
-
var
|
|
10014
|
+
var import_types28 = require("@sip-protocol/types");
|
|
9583
10015
|
var TrezorWalletAdapter = class extends BaseWalletAdapter {
|
|
9584
10016
|
chain;
|
|
9585
10017
|
name = "trezor";
|
|
@@ -9725,7 +10157,7 @@ var TrezorWalletAdapter = class extends BaseWalletAdapter {
|
|
|
9725
10157
|
async getBalance() {
|
|
9726
10158
|
throw new WalletError(
|
|
9727
10159
|
"Hardware wallets do not track balances. Use an RPC provider.",
|
|
9728
|
-
|
|
10160
|
+
import_types28.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
9729
10161
|
);
|
|
9730
10162
|
}
|
|
9731
10163
|
/**
|
|
@@ -9736,7 +10168,7 @@ var TrezorWalletAdapter = class extends BaseWalletAdapter {
|
|
|
9736
10168
|
async getTokenBalance(_asset) {
|
|
9737
10169
|
throw new WalletError(
|
|
9738
10170
|
"Hardware wallets do not track balances. Use an RPC provider.",
|
|
9739
|
-
|
|
10171
|
+
import_types28.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
9740
10172
|
);
|
|
9741
10173
|
}
|
|
9742
10174
|
// ─── Account Management ─────────────────────────────────────────────────────
|
|
@@ -10017,7 +10449,7 @@ function createTrezorAdapter(config) {
|
|
|
10017
10449
|
}
|
|
10018
10450
|
|
|
10019
10451
|
// src/wallet/hardware/mock.ts
|
|
10020
|
-
var
|
|
10452
|
+
var import_types30 = require("@sip-protocol/types");
|
|
10021
10453
|
var import_utils14 = require("@noble/hashes/utils");
|
|
10022
10454
|
var MockLedgerAdapter = class extends BaseWalletAdapter {
|
|
10023
10455
|
chain;
|
|
@@ -10165,7 +10597,7 @@ var MockLedgerAdapter = class extends BaseWalletAdapter {
|
|
|
10165
10597
|
async getBalance() {
|
|
10166
10598
|
throw new WalletError(
|
|
10167
10599
|
"Hardware wallets do not track balances",
|
|
10168
|
-
|
|
10600
|
+
import_types30.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
10169
10601
|
);
|
|
10170
10602
|
}
|
|
10171
10603
|
/**
|
|
@@ -10174,7 +10606,7 @@ var MockLedgerAdapter = class extends BaseWalletAdapter {
|
|
|
10174
10606
|
async getTokenBalance(_asset) {
|
|
10175
10607
|
throw new WalletError(
|
|
10176
10608
|
"Hardware wallets do not track balances",
|
|
10177
|
-
|
|
10609
|
+
import_types30.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
10178
10610
|
);
|
|
10179
10611
|
}
|
|
10180
10612
|
/**
|
|
@@ -10404,13 +10836,13 @@ var MockTrezorAdapter = class extends BaseWalletAdapter {
|
|
|
10404
10836
|
async getBalance() {
|
|
10405
10837
|
throw new WalletError(
|
|
10406
10838
|
"Hardware wallets do not track balances",
|
|
10407
|
-
|
|
10839
|
+
import_types30.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
10408
10840
|
);
|
|
10409
10841
|
}
|
|
10410
10842
|
async getTokenBalance(_asset) {
|
|
10411
10843
|
throw new WalletError(
|
|
10412
10844
|
"Hardware wallets do not track balances",
|
|
10413
|
-
|
|
10845
|
+
import_types30.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
10414
10846
|
);
|
|
10415
10847
|
}
|
|
10416
10848
|
async getAccounts(startIndex = 0, count = 5) {
|
|
@@ -10500,7 +10932,7 @@ function createMockTrezorAdapter(config) {
|
|
|
10500
10932
|
}
|
|
10501
10933
|
|
|
10502
10934
|
// src/wallet/index.ts
|
|
10503
|
-
var
|
|
10935
|
+
var import_types33 = require("@sip-protocol/types");
|
|
10504
10936
|
|
|
10505
10937
|
// src/proofs/browser.ts
|
|
10506
10938
|
var import_noir_js = require("@noir-lang/noir_js");
|
|
@@ -12144,6 +12576,7 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
|
|
|
12144
12576
|
ZcashRPCClient,
|
|
12145
12577
|
ZcashRPCError,
|
|
12146
12578
|
ZcashShieldedService,
|
|
12579
|
+
ZcashSwapService,
|
|
12147
12580
|
addBlindings,
|
|
12148
12581
|
addCommitments,
|
|
12149
12582
|
addOracle,
|
|
@@ -12178,6 +12611,7 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
|
|
|
12178
12611
|
createWalletFactory,
|
|
12179
12612
|
createZcashClient,
|
|
12180
12613
|
createZcashShieldedService,
|
|
12614
|
+
createZcashSwapService,
|
|
12181
12615
|
decodeStealthMetaAddress,
|
|
12182
12616
|
decryptMemo,
|
|
12183
12617
|
decryptWithViewing,
|