@sip-protocol/sdk 0.2.10 → 0.3.1
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/browser.d.mts +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +1643 -266
- package/dist/browser.mjs +259 -5
- package/dist/chunk-4IFOPYJF.mjs +11950 -0
- package/dist/chunk-4VJHI66K.mjs +12120 -0
- package/dist/chunk-5BAS4D44.mjs +10283 -0
- package/dist/chunk-6WOV2YNG.mjs +10179 -0
- package/dist/chunk-7IMRM7LN.mjs +12149 -0
- package/dist/chunk-DU7LQDD2.mjs +10148 -0
- package/dist/{chunk-AV37IZST.mjs → chunk-JNNXNTSS.mjs} +14 -0
- package/dist/chunk-KXN6IWL5.mjs +10736 -0
- package/dist/chunk-MR7HRCRS.mjs +10165 -0
- package/dist/chunk-NDGUWOOZ.mjs +10157 -0
- package/dist/chunk-O4Y2ZUDL.mjs +12721 -0
- package/dist/chunk-UPTISVCY.mjs +10304 -0
- package/dist/chunk-VITVG25F.mjs +982 -0
- package/dist/chunk-VXSHK7US.mjs +10158 -0
- package/dist/chunk-W3YXIQ7L.mjs +11950 -0
- package/dist/chunk-YZCK337Y.mjs +12155 -0
- package/dist/index-Ba7njCU3.d.ts +6925 -0
- package/dist/index-Co26-vbG.d.mts +6925 -0
- package/dist/index-DAgedMrt.d.ts +6927 -0
- package/dist/index-DW7AQwcU.d.mts +6927 -0
- package/dist/{index-CAhjA4kh.d.mts → index-DqZoHYKI.d.mts} +362 -6
- package/dist/index-dTtK_DTl.d.ts +6762 -0
- package/dist/index-jnkYu-Z4.d.mts +6762 -0
- package/dist/{index-BFOKTz2z.d.ts → index-vB1N1mHd.d.ts} +362 -6
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1340 -199
- package/dist/index.mjs +19 -1
- package/dist/noir-BHQtFvRk.d.mts +467 -0
- package/dist/noir-BHQtFvRk.d.ts +467 -0
- package/package.json +14 -14
- package/src/index.ts +32 -0
- package/src/proofs/worker.ts +240 -4
- package/src/settlement/README.md +439 -0
- package/src/settlement/backends/direct-chain.ts +569 -0
- package/src/settlement/backends/index.ts +22 -0
- package/src/settlement/backends/near-intents.ts +480 -0
- package/src/settlement/backends/zcash-native.ts +516 -0
- package/src/settlement/index.ts +47 -0
- package/src/settlement/interface.ts +397 -0
- package/src/settlement/registry.ts +269 -0
- package/src/settlement/router.ts +383 -0
- package/src/zcash/bridge.ts +20 -2
- package/src/zcash/swap-service.ts +20 -2
- package/LICENSE +0 -21
package/dist/index.js
CHANGED
|
@@ -46,7 +46,7 @@ __export(index_exports, {
|
|
|
46
46
|
HardwareWalletError: () => HardwareWalletError,
|
|
47
47
|
IntentBuilder: () => IntentBuilder,
|
|
48
48
|
IntentError: () => IntentError,
|
|
49
|
-
IntentStatus: () =>
|
|
49
|
+
IntentStatus: () => import_types37.IntentStatus,
|
|
50
50
|
LedgerWalletAdapter: () => LedgerWalletAdapter,
|
|
51
51
|
MockEthereumAdapter: () => MockEthereumAdapter,
|
|
52
52
|
MockLedgerAdapter: () => MockLedgerAdapter,
|
|
@@ -55,36 +55,42 @@ __export(index_exports, {
|
|
|
55
55
|
MockSolver: () => MockSolver,
|
|
56
56
|
MockTrezorAdapter: () => MockTrezorAdapter,
|
|
57
57
|
MockWalletAdapter: () => MockWalletAdapter,
|
|
58
|
-
NATIVE_TOKENS: () =>
|
|
58
|
+
NATIVE_TOKENS: () => import_types37.NATIVE_TOKENS,
|
|
59
59
|
NEARIntentsAdapter: () => NEARIntentsAdapter,
|
|
60
|
+
NEARIntentsBackend: () => NEARIntentsBackend,
|
|
60
61
|
NetworkError: () => NetworkError,
|
|
61
62
|
ORACLE_DOMAIN: () => ORACLE_DOMAIN,
|
|
62
63
|
OneClickClient: () => OneClickClient,
|
|
63
|
-
OneClickDepositMode: () =>
|
|
64
|
-
OneClickErrorCode: () =>
|
|
65
|
-
OneClickSwapStatus: () =>
|
|
66
|
-
OneClickSwapType: () =>
|
|
64
|
+
OneClickDepositMode: () => import_types41.OneClickDepositMode,
|
|
65
|
+
OneClickErrorCode: () => import_types41.OneClickErrorCode,
|
|
66
|
+
OneClickSwapStatus: () => import_types41.OneClickSwapStatus,
|
|
67
|
+
OneClickSwapType: () => import_types41.OneClickSwapType,
|
|
67
68
|
PaymentBuilder: () => PaymentBuilder,
|
|
68
|
-
PaymentStatus: () =>
|
|
69
|
-
PrivacyLevel: () =>
|
|
69
|
+
PaymentStatus: () => import_types38.PaymentStatus,
|
|
70
|
+
PrivacyLevel: () => import_types37.PrivacyLevel,
|
|
70
71
|
ProofError: () => ProofError,
|
|
71
72
|
ProofGenerationError: () => ProofGenerationError,
|
|
72
73
|
ProofNotImplementedError: () => ProofNotImplementedError,
|
|
73
|
-
ProposalStatus: () =>
|
|
74
|
-
ReportStatus: () =>
|
|
74
|
+
ProposalStatus: () => import_types39.ProposalStatus,
|
|
75
|
+
ReportStatus: () => import_types40.ReportStatus,
|
|
75
76
|
SIP: () => SIP,
|
|
76
77
|
SIPError: () => SIPError,
|
|
77
|
-
SIP_VERSION: () =>
|
|
78
|
+
SIP_VERSION: () => import_types37.SIP_VERSION,
|
|
78
79
|
STABLECOIN_ADDRESSES: () => STABLECOIN_ADDRESSES,
|
|
79
80
|
STABLECOIN_DECIMALS: () => STABLECOIN_DECIMALS,
|
|
80
81
|
STABLECOIN_INFO: () => STABLECOIN_INFO,
|
|
82
|
+
SettlementRegistry: () => SettlementRegistry,
|
|
83
|
+
SettlementRegistryError: () => SettlementRegistryError,
|
|
84
|
+
SmartRouter: () => SmartRouter,
|
|
81
85
|
SolanaWalletAdapter: () => SolanaWalletAdapter,
|
|
86
|
+
SwapStatus: () => SwapStatus,
|
|
82
87
|
Treasury: () => Treasury,
|
|
83
88
|
TrezorWalletAdapter: () => TrezorWalletAdapter,
|
|
84
89
|
ValidationError: () => ValidationError,
|
|
85
90
|
WalletError: () => WalletError,
|
|
86
|
-
WalletErrorCode: () =>
|
|
87
|
-
ZcashErrorCode: () =>
|
|
91
|
+
WalletErrorCode: () => import_types36.WalletErrorCode,
|
|
92
|
+
ZcashErrorCode: () => import_types42.ZcashErrorCode,
|
|
93
|
+
ZcashNativeBackend: () => ZcashNativeBackend,
|
|
88
94
|
ZcashRPCClient: () => ZcashRPCClient,
|
|
89
95
|
ZcashRPCError: () => ZcashRPCError,
|
|
90
96
|
ZcashShieldedService: () => ZcashShieldedService,
|
|
@@ -113,15 +119,18 @@ __export(index_exports, {
|
|
|
113
119
|
createMockSolver: () => createMockSolver,
|
|
114
120
|
createMockTrezorAdapter: () => createMockTrezorAdapter,
|
|
115
121
|
createNEARIntentsAdapter: () => createNEARIntentsAdapter,
|
|
122
|
+
createNEARIntentsBackend: () => createNEARIntentsBackend,
|
|
116
123
|
createOracleRegistry: () => createOracleRegistry,
|
|
117
124
|
createProductionSIP: () => createProductionSIP,
|
|
118
125
|
createSIP: () => createSIP,
|
|
119
126
|
createShieldedIntent: () => createShieldedIntent,
|
|
120
127
|
createShieldedPayment: () => createShieldedPayment,
|
|
128
|
+
createSmartRouter: () => createSmartRouter,
|
|
121
129
|
createSolanaAdapter: () => createSolanaAdapter,
|
|
122
130
|
createTrezorAdapter: () => createTrezorAdapter,
|
|
123
131
|
createWalletFactory: () => createWalletFactory,
|
|
124
132
|
createZcashClient: () => createZcashClient,
|
|
133
|
+
createZcashNativeBackend: () => createZcashNativeBackend,
|
|
125
134
|
createZcashShieldedService: () => createZcashShieldedService,
|
|
126
135
|
createZcashSwapService: () => createZcashSwapService,
|
|
127
136
|
decodeStealthMetaAddress: () => decodeStealthMetaAddress,
|
|
@@ -184,7 +193,7 @@ __export(index_exports, {
|
|
|
184
193
|
isExpired: () => isExpired,
|
|
185
194
|
isNonNegativeAmount: () => isNonNegativeAmount,
|
|
186
195
|
isPaymentExpired: () => isPaymentExpired,
|
|
187
|
-
isPrivate: () =>
|
|
196
|
+
isPrivate: () => import_types37.isPrivate,
|
|
188
197
|
isPrivateWalletAdapter: () => isPrivateWalletAdapter,
|
|
189
198
|
isSIPError: () => isSIPError,
|
|
190
199
|
isStablecoin: () => isStablecoin,
|
|
@@ -220,7 +229,7 @@ __export(index_exports, {
|
|
|
220
229
|
subtractBlindings: () => subtractBlindings,
|
|
221
230
|
subtractCommitments: () => subtractCommitments,
|
|
222
231
|
supportsSharedArrayBuffer: () => supportsSharedArrayBuffer,
|
|
223
|
-
supportsViewingKey: () =>
|
|
232
|
+
supportsViewingKey: () => import_types37.supportsViewingKey,
|
|
224
233
|
supportsWebBluetooth: () => supportsWebBluetooth,
|
|
225
234
|
supportsWebHID: () => supportsWebHID,
|
|
226
235
|
supportsWebUSB: () => supportsWebUSB,
|
|
@@ -3774,10 +3783,10 @@ function hasEnoughOracles(registry) {
|
|
|
3774
3783
|
}
|
|
3775
3784
|
|
|
3776
3785
|
// src/index.ts
|
|
3777
|
-
var import_types34 = require("@sip-protocol/types");
|
|
3778
|
-
var import_types35 = require("@sip-protocol/types");
|
|
3779
|
-
var import_types36 = require("@sip-protocol/types");
|
|
3780
3786
|
var import_types37 = require("@sip-protocol/types");
|
|
3787
|
+
var import_types38 = require("@sip-protocol/types");
|
|
3788
|
+
var import_types39 = require("@sip-protocol/types");
|
|
3789
|
+
var import_types40 = require("@sip-protocol/types");
|
|
3781
3790
|
|
|
3782
3791
|
// src/solver/mock-solver.ts
|
|
3783
3792
|
var import_types7 = require("@sip-protocol/types");
|
|
@@ -3962,10 +3971,1127 @@ function createMockSolver(config) {
|
|
|
3962
3971
|
}
|
|
3963
3972
|
|
|
3964
3973
|
// src/index.ts
|
|
3965
|
-
var
|
|
3974
|
+
var import_types41 = require("@sip-protocol/types");
|
|
3966
3975
|
|
|
3967
|
-
// src/
|
|
3976
|
+
// src/settlement/interface.ts
|
|
3977
|
+
var SwapStatus = /* @__PURE__ */ ((SwapStatus2) => {
|
|
3978
|
+
SwapStatus2["PENDING_DEPOSIT"] = "pending_deposit";
|
|
3979
|
+
SwapStatus2["DEPOSIT_CONFIRMED"] = "deposit_confirmed";
|
|
3980
|
+
SwapStatus2["IN_PROGRESS"] = "in_progress";
|
|
3981
|
+
SwapStatus2["SUCCESS"] = "success";
|
|
3982
|
+
SwapStatus2["FAILED"] = "failed";
|
|
3983
|
+
SwapStatus2["CANCELLED"] = "cancelled";
|
|
3984
|
+
SwapStatus2["REFUNDING"] = "refunding";
|
|
3985
|
+
SwapStatus2["REFUNDED"] = "refunded";
|
|
3986
|
+
return SwapStatus2;
|
|
3987
|
+
})(SwapStatus || {});
|
|
3988
|
+
|
|
3989
|
+
// src/settlement/registry.ts
|
|
3990
|
+
var SettlementRegistryError = class extends Error {
|
|
3991
|
+
constructor(message) {
|
|
3992
|
+
super(message);
|
|
3993
|
+
this.name = "SettlementRegistryError";
|
|
3994
|
+
}
|
|
3995
|
+
};
|
|
3996
|
+
var SettlementRegistry = class {
|
|
3997
|
+
backends = /* @__PURE__ */ new Map();
|
|
3998
|
+
/**
|
|
3999
|
+
* Register a settlement backend
|
|
4000
|
+
*
|
|
4001
|
+
* @param backend - Settlement backend to register
|
|
4002
|
+
* @throws {SettlementRegistryError} If backend with same name already exists
|
|
4003
|
+
*
|
|
4004
|
+
* @example
|
|
4005
|
+
* ```typescript
|
|
4006
|
+
* registry.register(nearIntentsBackend)
|
|
4007
|
+
* ```
|
|
4008
|
+
*/
|
|
4009
|
+
register(backend) {
|
|
4010
|
+
if (this.backends.has(backend.name)) {
|
|
4011
|
+
throw new SettlementRegistryError(
|
|
4012
|
+
`Backend '${backend.name}' is already registered`
|
|
4013
|
+
);
|
|
4014
|
+
}
|
|
4015
|
+
this.backends.set(backend.name, backend);
|
|
4016
|
+
}
|
|
4017
|
+
/**
|
|
4018
|
+
* Get a settlement backend by name
|
|
4019
|
+
*
|
|
4020
|
+
* @param name - Backend name
|
|
4021
|
+
* @returns Settlement backend
|
|
4022
|
+
* @throws {SettlementRegistryError} If backend is not found
|
|
4023
|
+
*
|
|
4024
|
+
* @example
|
|
4025
|
+
* ```typescript
|
|
4026
|
+
* const backend = registry.get('near-intents')
|
|
4027
|
+
* ```
|
|
4028
|
+
*/
|
|
4029
|
+
get(name) {
|
|
4030
|
+
const backend = this.backends.get(name);
|
|
4031
|
+
if (!backend) {
|
|
4032
|
+
throw new SettlementRegistryError(`Backend '${name}' not found`);
|
|
4033
|
+
}
|
|
4034
|
+
return backend;
|
|
4035
|
+
}
|
|
4036
|
+
/**
|
|
4037
|
+
* List all registered backend names
|
|
4038
|
+
*
|
|
4039
|
+
* @returns Array of backend names
|
|
4040
|
+
*
|
|
4041
|
+
* @example
|
|
4042
|
+
* ```typescript
|
|
4043
|
+
* const names = registry.list()
|
|
4044
|
+
* // ['near-intents', 'zcash', 'thorchain']
|
|
4045
|
+
* ```
|
|
4046
|
+
*/
|
|
4047
|
+
list() {
|
|
4048
|
+
return Array.from(this.backends.keys());
|
|
4049
|
+
}
|
|
4050
|
+
/**
|
|
4051
|
+
* Get the best backend for a specific route
|
|
4052
|
+
*
|
|
4053
|
+
* Selection criteria (in order of priority):
|
|
4054
|
+
* 1. Backends that support both source and destination chains
|
|
4055
|
+
* 2. Backends with faster average execution time
|
|
4056
|
+
* 3. First registered backend (if no execution time info)
|
|
4057
|
+
*
|
|
4058
|
+
* @param fromChain - Source chain
|
|
4059
|
+
* @param toChain - Destination chain
|
|
4060
|
+
* @returns Best settlement backend for the route
|
|
4061
|
+
* @throws {SettlementRegistryError} If no backend supports the route
|
|
4062
|
+
*
|
|
4063
|
+
* @example
|
|
4064
|
+
* ```typescript
|
|
4065
|
+
* const backend = registry.getBestForRoute('ethereum', 'solana')
|
|
4066
|
+
* const quote = await backend.getQuote({ ... })
|
|
4067
|
+
* ```
|
|
4068
|
+
*/
|
|
4069
|
+
getBestForRoute(fromChain, toChain) {
|
|
4070
|
+
const supportedBackends = [];
|
|
4071
|
+
for (const backend of Array.from(this.backends.values())) {
|
|
4072
|
+
const { supportedSourceChains, supportedDestinationChains } = backend.capabilities;
|
|
4073
|
+
const supportsSource = supportedSourceChains.includes(fromChain);
|
|
4074
|
+
const supportsDestination = supportedDestinationChains.includes(toChain);
|
|
4075
|
+
if (supportsSource && supportsDestination) {
|
|
4076
|
+
supportedBackends.push(backend);
|
|
4077
|
+
}
|
|
4078
|
+
}
|
|
4079
|
+
if (supportedBackends.length === 0) {
|
|
4080
|
+
throw new SettlementRegistryError(
|
|
4081
|
+
`No backend supports route from '${fromChain}' to '${toChain}'`
|
|
4082
|
+
);
|
|
4083
|
+
}
|
|
4084
|
+
if (supportedBackends.length === 1) {
|
|
4085
|
+
return supportedBackends[0];
|
|
4086
|
+
}
|
|
4087
|
+
supportedBackends.sort((a, b) => {
|
|
4088
|
+
const timeA = a.capabilities.averageExecutionTime ?? Infinity;
|
|
4089
|
+
const timeB = b.capabilities.averageExecutionTime ?? Infinity;
|
|
4090
|
+
return timeA - timeB;
|
|
4091
|
+
});
|
|
4092
|
+
return supportedBackends[0];
|
|
4093
|
+
}
|
|
4094
|
+
/**
|
|
4095
|
+
* Get all supported routes across all registered backends
|
|
4096
|
+
*
|
|
4097
|
+
* @returns Array of supported routes
|
|
4098
|
+
*
|
|
4099
|
+
* @example
|
|
4100
|
+
* ```typescript
|
|
4101
|
+
* const routes = registry.getSupportedRoutes()
|
|
4102
|
+
* // [
|
|
4103
|
+
* // { fromChain: 'ethereum', toChain: 'solana', backend: 'near-intents' },
|
|
4104
|
+
* // { fromChain: 'solana', toChain: 'ethereum', backend: 'near-intents' },
|
|
4105
|
+
* // { fromChain: 'ethereum', toChain: 'zcash', backend: 'zcash' },
|
|
4106
|
+
* // ...
|
|
4107
|
+
* // ]
|
|
4108
|
+
* ```
|
|
4109
|
+
*/
|
|
4110
|
+
getSupportedRoutes() {
|
|
4111
|
+
const routes = [];
|
|
4112
|
+
for (const backend of Array.from(this.backends.values())) {
|
|
4113
|
+
const { supportedSourceChains, supportedDestinationChains } = backend.capabilities;
|
|
4114
|
+
for (const fromChain of supportedSourceChains) {
|
|
4115
|
+
for (const toChain of supportedDestinationChains) {
|
|
4116
|
+
routes.push({
|
|
4117
|
+
fromChain,
|
|
4118
|
+
toChain,
|
|
4119
|
+
backend: backend.name
|
|
4120
|
+
});
|
|
4121
|
+
}
|
|
4122
|
+
}
|
|
4123
|
+
}
|
|
4124
|
+
return routes;
|
|
4125
|
+
}
|
|
4126
|
+
/**
|
|
4127
|
+
* Check if a backend is registered
|
|
4128
|
+
*
|
|
4129
|
+
* @param name - Backend name
|
|
4130
|
+
* @returns True if backend is registered
|
|
4131
|
+
*
|
|
4132
|
+
* @example
|
|
4133
|
+
* ```typescript
|
|
4134
|
+
* if (registry.has('near-intents')) {
|
|
4135
|
+
* const backend = registry.get('near-intents')
|
|
4136
|
+
* }
|
|
4137
|
+
* ```
|
|
4138
|
+
*/
|
|
4139
|
+
has(name) {
|
|
4140
|
+
return this.backends.has(name);
|
|
4141
|
+
}
|
|
4142
|
+
/**
|
|
4143
|
+
* Unregister a settlement backend
|
|
4144
|
+
*
|
|
4145
|
+
* @param name - Backend name to unregister
|
|
4146
|
+
* @returns True if backend was unregistered, false if not found
|
|
4147
|
+
*
|
|
4148
|
+
* @example
|
|
4149
|
+
* ```typescript
|
|
4150
|
+
* registry.unregister('near-intents')
|
|
4151
|
+
* ```
|
|
4152
|
+
*/
|
|
4153
|
+
unregister(name) {
|
|
4154
|
+
return this.backends.delete(name);
|
|
4155
|
+
}
|
|
4156
|
+
/**
|
|
4157
|
+
* Clear all registered backends
|
|
4158
|
+
*
|
|
4159
|
+
* @example
|
|
4160
|
+
* ```typescript
|
|
4161
|
+
* registry.clear()
|
|
4162
|
+
* ```
|
|
4163
|
+
*/
|
|
4164
|
+
clear() {
|
|
4165
|
+
this.backends.clear();
|
|
4166
|
+
}
|
|
4167
|
+
/**
|
|
4168
|
+
* Get number of registered backends
|
|
4169
|
+
*
|
|
4170
|
+
* @returns Number of registered backends
|
|
4171
|
+
*
|
|
4172
|
+
* @example
|
|
4173
|
+
* ```typescript
|
|
4174
|
+
* const count = registry.size()
|
|
4175
|
+
* ```
|
|
4176
|
+
*/
|
|
4177
|
+
size() {
|
|
4178
|
+
return this.backends.size;
|
|
4179
|
+
}
|
|
4180
|
+
};
|
|
4181
|
+
|
|
4182
|
+
// src/settlement/router.ts
|
|
4183
|
+
var SmartRouter = class {
|
|
4184
|
+
constructor(registry) {
|
|
4185
|
+
this.registry = registry;
|
|
4186
|
+
}
|
|
4187
|
+
/**
|
|
4188
|
+
* Find best routes for a swap
|
|
4189
|
+
*
|
|
4190
|
+
* Queries all compatible backends in parallel and returns sorted routes.
|
|
4191
|
+
*
|
|
4192
|
+
* @param params - Route finding parameters
|
|
4193
|
+
* @returns Sorted routes (best first)
|
|
4194
|
+
* @throws {ValidationError} If no backends support the route
|
|
4195
|
+
*/
|
|
4196
|
+
async findBestRoute(params) {
|
|
4197
|
+
const {
|
|
4198
|
+
from,
|
|
4199
|
+
to,
|
|
4200
|
+
amount,
|
|
4201
|
+
privacyLevel,
|
|
4202
|
+
preferSpeed = false,
|
|
4203
|
+
preferLowFees = true,
|
|
4204
|
+
recipientMetaAddress,
|
|
4205
|
+
senderAddress,
|
|
4206
|
+
slippageTolerance,
|
|
4207
|
+
deadline
|
|
4208
|
+
} = params;
|
|
4209
|
+
if (amount <= 0n) {
|
|
4210
|
+
throw new ValidationError("Amount must be greater than zero");
|
|
4211
|
+
}
|
|
4212
|
+
const allBackends = this.registry.list().map((name) => this.registry.get(name));
|
|
4213
|
+
const compatibleBackends = allBackends.filter((backend) => {
|
|
4214
|
+
const { supportedSourceChains, supportedDestinationChains, supportedPrivacyLevels } = backend.capabilities;
|
|
4215
|
+
const supportsRoute = supportedSourceChains.includes(from.chain) && supportedDestinationChains.includes(to.chain);
|
|
4216
|
+
const supportsPrivacy = supportedPrivacyLevels.includes(privacyLevel);
|
|
4217
|
+
return supportsRoute && supportsPrivacy;
|
|
4218
|
+
});
|
|
4219
|
+
if (compatibleBackends.length === 0) {
|
|
4220
|
+
throw new ValidationError(
|
|
4221
|
+
`No backend supports route from ${from.chain} to ${to.chain} with privacy level ${privacyLevel}`
|
|
4222
|
+
);
|
|
4223
|
+
}
|
|
4224
|
+
const quoteParams = {
|
|
4225
|
+
fromChain: from.chain,
|
|
4226
|
+
toChain: to.chain,
|
|
4227
|
+
fromToken: from.token,
|
|
4228
|
+
toToken: to.token,
|
|
4229
|
+
amount,
|
|
4230
|
+
privacyLevel,
|
|
4231
|
+
recipientMetaAddress,
|
|
4232
|
+
senderAddress,
|
|
4233
|
+
slippageTolerance,
|
|
4234
|
+
deadline
|
|
4235
|
+
};
|
|
4236
|
+
const quotePromises = compatibleBackends.map(async (backend) => {
|
|
4237
|
+
try {
|
|
4238
|
+
const quote = await backend.getQuote(quoteParams);
|
|
4239
|
+
return {
|
|
4240
|
+
backend: backend.name,
|
|
4241
|
+
quote,
|
|
4242
|
+
backendInstance: backend,
|
|
4243
|
+
success: true
|
|
4244
|
+
};
|
|
4245
|
+
} catch (error) {
|
|
4246
|
+
return {
|
|
4247
|
+
backend: backend.name,
|
|
4248
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
4249
|
+
success: false
|
|
4250
|
+
};
|
|
4251
|
+
}
|
|
4252
|
+
});
|
|
4253
|
+
const results = await Promise.all(quotePromises);
|
|
4254
|
+
const successfulRoutes = results.filter((r) => r.success).map((r) => ({
|
|
4255
|
+
backend: r.backend,
|
|
4256
|
+
quote: r.quote,
|
|
4257
|
+
backendInstance: r.backendInstance,
|
|
4258
|
+
score: 0
|
|
4259
|
+
// Will be calculated below
|
|
4260
|
+
}));
|
|
4261
|
+
if (successfulRoutes.length === 0) {
|
|
4262
|
+
const errors = results.filter((r) => !r.success).map((r) => `${r.backend}: ${r.error}`).join(", ");
|
|
4263
|
+
throw new NetworkError(
|
|
4264
|
+
`All backends failed to provide quotes: ${errors}`
|
|
4265
|
+
);
|
|
4266
|
+
}
|
|
4267
|
+
this.rankRoutes(successfulRoutes, { preferSpeed, preferLowFees });
|
|
4268
|
+
successfulRoutes.sort((a, b) => b.score - a.score);
|
|
4269
|
+
return successfulRoutes;
|
|
4270
|
+
}
|
|
4271
|
+
/**
|
|
4272
|
+
* Compare quotes from multiple routes side-by-side
|
|
4273
|
+
*
|
|
4274
|
+
* @param routes - Routes to compare (from findBestRoute)
|
|
4275
|
+
* @returns Comparison with best routes by different criteria
|
|
4276
|
+
*/
|
|
4277
|
+
compareQuotes(routes) {
|
|
4278
|
+
if (routes.length === 0) {
|
|
4279
|
+
return {
|
|
4280
|
+
routes: [],
|
|
4281
|
+
bestByCost: null,
|
|
4282
|
+
bestBySpeed: null,
|
|
4283
|
+
bestByPrivacy: null,
|
|
4284
|
+
metadata: {
|
|
4285
|
+
totalQueried: 0,
|
|
4286
|
+
failures: [],
|
|
4287
|
+
queriedAt: Date.now()
|
|
4288
|
+
}
|
|
4289
|
+
};
|
|
4290
|
+
}
|
|
4291
|
+
const bestByCost = [...routes].sort((a, b) => {
|
|
4292
|
+
const costA = this.calculateTotalCost(a.quote);
|
|
4293
|
+
const costB = this.calculateTotalCost(b.quote);
|
|
4294
|
+
return costA - costB;
|
|
4295
|
+
})[0];
|
|
4296
|
+
const bestBySpeed = [...routes].sort((a, b) => {
|
|
4297
|
+
const timeA = a.quote.estimatedTime ?? Infinity;
|
|
4298
|
+
const timeB = b.quote.estimatedTime ?? Infinity;
|
|
4299
|
+
return timeA - timeB;
|
|
4300
|
+
})[0];
|
|
4301
|
+
const bestByPrivacy = [...routes].find((route) => {
|
|
4302
|
+
const { supportedPrivacyLevels } = route.backendInstance.capabilities;
|
|
4303
|
+
return supportedPrivacyLevels.includes("shielded") || supportedPrivacyLevels.includes("compliant");
|
|
4304
|
+
}) || routes[0];
|
|
4305
|
+
return {
|
|
4306
|
+
routes,
|
|
4307
|
+
bestByCost,
|
|
4308
|
+
bestBySpeed,
|
|
4309
|
+
bestByPrivacy,
|
|
4310
|
+
metadata: {
|
|
4311
|
+
totalQueried: routes.length,
|
|
4312
|
+
failures: [],
|
|
4313
|
+
// Could track from findBestRoute
|
|
4314
|
+
queriedAt: Date.now()
|
|
4315
|
+
}
|
|
4316
|
+
};
|
|
4317
|
+
}
|
|
4318
|
+
/**
|
|
4319
|
+
* Rank routes by score
|
|
4320
|
+
*
|
|
4321
|
+
* Scoring algorithm:
|
|
4322
|
+
* - Base score: 100
|
|
4323
|
+
* - Cost: Lower fees = higher score (up to +50)
|
|
4324
|
+
* - Speed: Faster execution = higher score (up to +30)
|
|
4325
|
+
* - Privacy: Better privacy support = higher score (up to +20)
|
|
4326
|
+
*
|
|
4327
|
+
* @private
|
|
4328
|
+
*/
|
|
4329
|
+
rankRoutes(routes, preferences) {
|
|
4330
|
+
const { preferSpeed, preferLowFees } = preferences;
|
|
4331
|
+
const costs = routes.map((r) => this.calculateTotalCost(r.quote));
|
|
4332
|
+
const times = routes.map((r) => r.quote.estimatedTime ?? Infinity);
|
|
4333
|
+
const minCost = Math.min(...costs);
|
|
4334
|
+
const maxCost = Math.max(...costs);
|
|
4335
|
+
const minTime = Math.min(...times.filter((t) => t !== Infinity));
|
|
4336
|
+
const maxTime = Math.max(...times.filter((t) => t !== Infinity));
|
|
4337
|
+
routes.forEach((route, index) => {
|
|
4338
|
+
let score = 100;
|
|
4339
|
+
if (maxCost > minCost) {
|
|
4340
|
+
const costNormalized = 1 - (costs[index] - minCost) / (maxCost - minCost);
|
|
4341
|
+
const costWeight = preferLowFees ? 50 : 30;
|
|
4342
|
+
score += costNormalized * costWeight;
|
|
4343
|
+
}
|
|
4344
|
+
const time = times[index];
|
|
4345
|
+
if (time !== Infinity && maxTime > minTime) {
|
|
4346
|
+
const speedNormalized = 1 - (time - minTime) / (maxTime - minTime);
|
|
4347
|
+
const speedWeight = preferSpeed ? 50 : 30;
|
|
4348
|
+
score += speedNormalized * speedWeight;
|
|
4349
|
+
}
|
|
4350
|
+
const { supportedPrivacyLevels } = route.backendInstance.capabilities;
|
|
4351
|
+
if (supportedPrivacyLevels.includes("shielded")) {
|
|
4352
|
+
score += 20;
|
|
4353
|
+
} else if (supportedPrivacyLevels.includes("compliant")) {
|
|
4354
|
+
score += 10;
|
|
4355
|
+
}
|
|
4356
|
+
route.score = score;
|
|
4357
|
+
});
|
|
4358
|
+
}
|
|
4359
|
+
/**
|
|
4360
|
+
* Calculate total cost from quote
|
|
4361
|
+
*
|
|
4362
|
+
* Returns total fee in USD if available, otherwise estimates from fees
|
|
4363
|
+
*
|
|
4364
|
+
* @private
|
|
4365
|
+
*/
|
|
4366
|
+
calculateTotalCost(quote) {
|
|
4367
|
+
if (quote.fees.totalFeeUSD) {
|
|
4368
|
+
return parseFloat(quote.fees.totalFeeUSD);
|
|
4369
|
+
}
|
|
4370
|
+
const networkFee = parseFloat(quote.fees.networkFee) || 0;
|
|
4371
|
+
const protocolFee = parseFloat(quote.fees.protocolFee) || 0;
|
|
4372
|
+
return networkFee + protocolFee;
|
|
4373
|
+
}
|
|
4374
|
+
};
|
|
4375
|
+
function createSmartRouter(registry) {
|
|
4376
|
+
return new SmartRouter(registry);
|
|
4377
|
+
}
|
|
4378
|
+
|
|
4379
|
+
// src/settlement/backends/near-intents.ts
|
|
3968
4380
|
var import_types8 = require("@sip-protocol/types");
|
|
4381
|
+
function mapOneClickStatus(status) {
|
|
4382
|
+
switch (status) {
|
|
4383
|
+
case import_types8.OneClickSwapStatus.PENDING_DEPOSIT:
|
|
4384
|
+
return "pending_deposit" /* PENDING_DEPOSIT */;
|
|
4385
|
+
case import_types8.OneClickSwapStatus.PROCESSING:
|
|
4386
|
+
return "in_progress" /* IN_PROGRESS */;
|
|
4387
|
+
case import_types8.OneClickSwapStatus.SUCCESS:
|
|
4388
|
+
return "success" /* SUCCESS */;
|
|
4389
|
+
case import_types8.OneClickSwapStatus.FAILED:
|
|
4390
|
+
return "failed" /* FAILED */;
|
|
4391
|
+
case import_types8.OneClickSwapStatus.INCOMPLETE_DEPOSIT:
|
|
4392
|
+
return "failed" /* FAILED */;
|
|
4393
|
+
case import_types8.OneClickSwapStatus.REFUNDED:
|
|
4394
|
+
return "refunded" /* REFUNDED */;
|
|
4395
|
+
default:
|
|
4396
|
+
return "pending_deposit" /* PENDING_DEPOSIT */;
|
|
4397
|
+
}
|
|
4398
|
+
}
|
|
4399
|
+
var NEARIntentsBackend = class {
|
|
4400
|
+
name = "near-intents";
|
|
4401
|
+
capabilities;
|
|
4402
|
+
adapter;
|
|
4403
|
+
quoteCache;
|
|
4404
|
+
constructor(config = {}) {
|
|
4405
|
+
this.adapter = new NEARIntentsAdapter(config);
|
|
4406
|
+
this.quoteCache = /* @__PURE__ */ new Map();
|
|
4407
|
+
this.capabilities = {
|
|
4408
|
+
supportedSourceChains: [
|
|
4409
|
+
"near",
|
|
4410
|
+
"ethereum",
|
|
4411
|
+
"solana",
|
|
4412
|
+
"polygon",
|
|
4413
|
+
"arbitrum",
|
|
4414
|
+
"optimism",
|
|
4415
|
+
"base",
|
|
4416
|
+
"bitcoin",
|
|
4417
|
+
"zcash"
|
|
4418
|
+
],
|
|
4419
|
+
supportedDestinationChains: [
|
|
4420
|
+
"near",
|
|
4421
|
+
"ethereum",
|
|
4422
|
+
"solana",
|
|
4423
|
+
"polygon",
|
|
4424
|
+
"arbitrum",
|
|
4425
|
+
"optimism",
|
|
4426
|
+
"base",
|
|
4427
|
+
"bitcoin",
|
|
4428
|
+
"zcash"
|
|
4429
|
+
],
|
|
4430
|
+
supportedPrivacyLevels: [
|
|
4431
|
+
import_types8.PrivacyLevel.TRANSPARENT,
|
|
4432
|
+
import_types8.PrivacyLevel.SHIELDED,
|
|
4433
|
+
import_types8.PrivacyLevel.COMPLIANT
|
|
4434
|
+
],
|
|
4435
|
+
supportsCancellation: false,
|
|
4436
|
+
supportsRefunds: true,
|
|
4437
|
+
averageExecutionTime: 300,
|
|
4438
|
+
// 5 minutes
|
|
4439
|
+
features: ["stealth-addresses", "cross-chain", "near-intents"]
|
|
4440
|
+
};
|
|
4441
|
+
}
|
|
4442
|
+
/**
|
|
4443
|
+
* Get quote for a cross-chain swap
|
|
4444
|
+
*/
|
|
4445
|
+
async getQuote(params) {
|
|
4446
|
+
this.validateQuoteParams(params);
|
|
4447
|
+
const swapRequest = {
|
|
4448
|
+
requestId: this.generateRequestId(),
|
|
4449
|
+
privacyLevel: params.privacyLevel,
|
|
4450
|
+
inputAsset: {
|
|
4451
|
+
chain: params.fromChain,
|
|
4452
|
+
symbol: params.fromToken,
|
|
4453
|
+
decimals: 0
|
|
4454
|
+
// Will be inferred by adapter
|
|
4455
|
+
},
|
|
4456
|
+
outputAsset: {
|
|
4457
|
+
chain: params.toChain,
|
|
4458
|
+
symbol: params.toToken,
|
|
4459
|
+
decimals: 0
|
|
4460
|
+
// Will be inferred by adapter
|
|
4461
|
+
},
|
|
4462
|
+
inputAmount: params.amount,
|
|
4463
|
+
minOutputAmount: params.slippageTolerance ? params.amount - params.amount * BigInt(params.slippageTolerance) / BigInt(1e4) : void 0
|
|
4464
|
+
};
|
|
4465
|
+
const prepared = await this.adapter.prepareSwap(
|
|
4466
|
+
swapRequest,
|
|
4467
|
+
params.recipientMetaAddress,
|
|
4468
|
+
params.senderAddress
|
|
4469
|
+
);
|
|
4470
|
+
const oneClickQuote = await this.adapter.getQuote(prepared);
|
|
4471
|
+
this.quoteCache.set(oneClickQuote.quoteId, params);
|
|
4472
|
+
const quote = {
|
|
4473
|
+
quoteId: oneClickQuote.quoteId,
|
|
4474
|
+
amountIn: oneClickQuote.amountIn,
|
|
4475
|
+
amountOut: oneClickQuote.amountOut,
|
|
4476
|
+
minAmountOut: oneClickQuote.amountOut,
|
|
4477
|
+
// 1Click doesn't provide separate minAmount
|
|
4478
|
+
fees: {
|
|
4479
|
+
networkFee: "0",
|
|
4480
|
+
// 1Click doesn't provide separate fee breakdown
|
|
4481
|
+
protocolFee: "0",
|
|
4482
|
+
totalFeeUSD: oneClickQuote.amountOutUsd
|
|
4483
|
+
},
|
|
4484
|
+
depositAddress: oneClickQuote.depositAddress,
|
|
4485
|
+
recipientAddress: prepared.stealthAddress?.address ?? params.senderAddress ?? "",
|
|
4486
|
+
refundAddress: params.senderAddress,
|
|
4487
|
+
expiresAt: new Date(oneClickQuote.deadline).getTime() / 1e3,
|
|
4488
|
+
estimatedTime: oneClickQuote.timeEstimate,
|
|
4489
|
+
metadata: {
|
|
4490
|
+
prepared,
|
|
4491
|
+
oneClickQuote,
|
|
4492
|
+
stealthAddress: prepared.stealthAddress,
|
|
4493
|
+
ephemeralPublicKey: prepared.stealthAddress?.ephemeralPublicKey,
|
|
4494
|
+
curve: prepared.curve
|
|
4495
|
+
}
|
|
4496
|
+
};
|
|
4497
|
+
return quote;
|
|
4498
|
+
}
|
|
4499
|
+
/**
|
|
4500
|
+
* Execute swap using a quote
|
|
4501
|
+
*/
|
|
4502
|
+
async executeSwap(params) {
|
|
4503
|
+
if (!params.quoteId) {
|
|
4504
|
+
throw new ValidationError("quoteId is required", "quoteId");
|
|
4505
|
+
}
|
|
4506
|
+
const quoteParams = this.quoteCache.get(params.quoteId);
|
|
4507
|
+
if (!quoteParams) {
|
|
4508
|
+
throw new ValidationError(
|
|
4509
|
+
"Quote not found. Please call getQuote() before executeSwap()",
|
|
4510
|
+
"quoteId"
|
|
4511
|
+
);
|
|
4512
|
+
}
|
|
4513
|
+
const swapRequest = {
|
|
4514
|
+
requestId: this.generateRequestId(),
|
|
4515
|
+
privacyLevel: quoteParams.privacyLevel,
|
|
4516
|
+
inputAsset: {
|
|
4517
|
+
chain: quoteParams.fromChain,
|
|
4518
|
+
symbol: quoteParams.fromToken,
|
|
4519
|
+
decimals: 0
|
|
4520
|
+
},
|
|
4521
|
+
outputAsset: {
|
|
4522
|
+
chain: quoteParams.toChain,
|
|
4523
|
+
symbol: quoteParams.toToken,
|
|
4524
|
+
decimals: 0
|
|
4525
|
+
},
|
|
4526
|
+
inputAmount: quoteParams.amount
|
|
4527
|
+
};
|
|
4528
|
+
const adapterResult = await this.adapter.initiateSwap(
|
|
4529
|
+
swapRequest,
|
|
4530
|
+
quoteParams.recipientMetaAddress,
|
|
4531
|
+
quoteParams.senderAddress
|
|
4532
|
+
);
|
|
4533
|
+
if (params.depositTxHash) {
|
|
4534
|
+
await this.adapter.notifyDeposit(
|
|
4535
|
+
adapterResult.depositAddress,
|
|
4536
|
+
params.depositTxHash,
|
|
4537
|
+
params.nearAccount
|
|
4538
|
+
);
|
|
4539
|
+
}
|
|
4540
|
+
const result = {
|
|
4541
|
+
swapId: adapterResult.depositAddress,
|
|
4542
|
+
// Use deposit address as swap ID
|
|
4543
|
+
status: mapOneClickStatus(adapterResult.status),
|
|
4544
|
+
quoteId: params.quoteId,
|
|
4545
|
+
depositAddress: adapterResult.depositAddress,
|
|
4546
|
+
depositTxHash: params.depositTxHash,
|
|
4547
|
+
settlementTxHash: adapterResult.settlementTxHash,
|
|
4548
|
+
actualAmountOut: adapterResult.amountOut,
|
|
4549
|
+
metadata: {
|
|
4550
|
+
adapterResult,
|
|
4551
|
+
stealthRecipient: adapterResult.stealthRecipient,
|
|
4552
|
+
ephemeralPublicKey: adapterResult.ephemeralPublicKey
|
|
4553
|
+
}
|
|
4554
|
+
};
|
|
4555
|
+
return result;
|
|
4556
|
+
}
|
|
4557
|
+
/**
|
|
4558
|
+
* Get current swap status
|
|
4559
|
+
*/
|
|
4560
|
+
async getStatus(swapId) {
|
|
4561
|
+
const oneClickStatus = await this.adapter.getStatus(swapId);
|
|
4562
|
+
const status = {
|
|
4563
|
+
swapId,
|
|
4564
|
+
status: mapOneClickStatus(oneClickStatus.status),
|
|
4565
|
+
quoteId: "",
|
|
4566
|
+
// 1Click status doesn't include quoteId
|
|
4567
|
+
depositAddress: swapId,
|
|
4568
|
+
amountIn: oneClickStatus.amountIn ?? "0",
|
|
4569
|
+
amountOut: oneClickStatus.amountOut ?? "0",
|
|
4570
|
+
depositTxHash: oneClickStatus.depositTxHash,
|
|
4571
|
+
settlementTxHash: oneClickStatus.settlementTxHash,
|
|
4572
|
+
errorMessage: oneClickStatus.error,
|
|
4573
|
+
updatedAt: Date.now() / 1e3,
|
|
4574
|
+
// 1Click doesn't provide updatedAt
|
|
4575
|
+
metadata: {
|
|
4576
|
+
oneClickStatus
|
|
4577
|
+
}
|
|
4578
|
+
};
|
|
4579
|
+
return status;
|
|
4580
|
+
}
|
|
4581
|
+
/**
|
|
4582
|
+
* Wait for swap completion (optional)
|
|
4583
|
+
*/
|
|
4584
|
+
async waitForCompletion(swapId, options) {
|
|
4585
|
+
await this.adapter.waitForCompletion(swapId, {
|
|
4586
|
+
interval: options?.interval,
|
|
4587
|
+
timeout: options?.timeout,
|
|
4588
|
+
onStatus: options?.onStatusChange ? (oneClickStatus) => {
|
|
4589
|
+
const status = {
|
|
4590
|
+
swapId,
|
|
4591
|
+
status: mapOneClickStatus(oneClickStatus.status),
|
|
4592
|
+
quoteId: "",
|
|
4593
|
+
depositAddress: swapId,
|
|
4594
|
+
amountIn: oneClickStatus.amountIn ?? "0",
|
|
4595
|
+
amountOut: oneClickStatus.amountOut ?? "0",
|
|
4596
|
+
depositTxHash: oneClickStatus.depositTxHash,
|
|
4597
|
+
settlementTxHash: oneClickStatus.settlementTxHash,
|
|
4598
|
+
errorMessage: oneClickStatus.error,
|
|
4599
|
+
updatedAt: Date.now() / 1e3,
|
|
4600
|
+
metadata: { oneClickStatus }
|
|
4601
|
+
};
|
|
4602
|
+
options.onStatusChange?.(status);
|
|
4603
|
+
} : void 0
|
|
4604
|
+
});
|
|
4605
|
+
return this.getStatus(swapId);
|
|
4606
|
+
}
|
|
4607
|
+
/**
|
|
4608
|
+
* Get dry quote (preview without creating deposit address)
|
|
4609
|
+
*/
|
|
4610
|
+
async getDryQuote(params) {
|
|
4611
|
+
this.validateQuoteParams(params);
|
|
4612
|
+
const swapRequest = {
|
|
4613
|
+
requestId: this.generateRequestId(),
|
|
4614
|
+
privacyLevel: params.privacyLevel,
|
|
4615
|
+
inputAsset: {
|
|
4616
|
+
chain: params.fromChain,
|
|
4617
|
+
symbol: params.fromToken,
|
|
4618
|
+
decimals: 0
|
|
4619
|
+
},
|
|
4620
|
+
outputAsset: {
|
|
4621
|
+
chain: params.toChain,
|
|
4622
|
+
symbol: params.toToken,
|
|
4623
|
+
decimals: 0
|
|
4624
|
+
},
|
|
4625
|
+
inputAmount: params.amount
|
|
4626
|
+
};
|
|
4627
|
+
const prepared = await this.adapter.prepareSwap(
|
|
4628
|
+
swapRequest,
|
|
4629
|
+
params.recipientMetaAddress,
|
|
4630
|
+
params.senderAddress
|
|
4631
|
+
);
|
|
4632
|
+
const oneClickQuote = await this.adapter.getDryQuote(prepared);
|
|
4633
|
+
const quote = {
|
|
4634
|
+
quoteId: oneClickQuote.quoteId,
|
|
4635
|
+
amountIn: oneClickQuote.amountIn,
|
|
4636
|
+
amountOut: oneClickQuote.amountOut,
|
|
4637
|
+
minAmountOut: oneClickQuote.amountOut,
|
|
4638
|
+
fees: {
|
|
4639
|
+
networkFee: "0",
|
|
4640
|
+
protocolFee: "0",
|
|
4641
|
+
totalFeeUSD: oneClickQuote.amountOutUsd
|
|
4642
|
+
},
|
|
4643
|
+
depositAddress: oneClickQuote.depositAddress,
|
|
4644
|
+
recipientAddress: prepared.stealthAddress?.address ?? params.senderAddress ?? "",
|
|
4645
|
+
refundAddress: params.senderAddress,
|
|
4646
|
+
expiresAt: new Date(oneClickQuote.deadline).getTime() / 1e3,
|
|
4647
|
+
estimatedTime: oneClickQuote.timeEstimate,
|
|
4648
|
+
metadata: {
|
|
4649
|
+
prepared,
|
|
4650
|
+
oneClickQuote,
|
|
4651
|
+
stealthAddress: prepared.stealthAddress,
|
|
4652
|
+
ephemeralPublicKey: prepared.stealthAddress?.ephemeralPublicKey,
|
|
4653
|
+
curve: prepared.curve,
|
|
4654
|
+
isDryQuote: true
|
|
4655
|
+
}
|
|
4656
|
+
};
|
|
4657
|
+
return quote;
|
|
4658
|
+
}
|
|
4659
|
+
/**
|
|
4660
|
+
* Notify backend of deposit transaction
|
|
4661
|
+
*/
|
|
4662
|
+
async notifyDeposit(swapId, txHash, metadata) {
|
|
4663
|
+
await this.adapter.notifyDeposit(
|
|
4664
|
+
swapId,
|
|
4665
|
+
// swapId is deposit address
|
|
4666
|
+
txHash,
|
|
4667
|
+
metadata?.nearAccount
|
|
4668
|
+
);
|
|
4669
|
+
}
|
|
4670
|
+
// ─── Private Methods ──────────────────────────────────────────────────────────
|
|
4671
|
+
validateQuoteParams(params) {
|
|
4672
|
+
if (!params.fromChain) {
|
|
4673
|
+
throw new ValidationError("fromChain is required", "fromChain");
|
|
4674
|
+
}
|
|
4675
|
+
if (!params.toChain) {
|
|
4676
|
+
throw new ValidationError("toChain is required", "toChain");
|
|
4677
|
+
}
|
|
4678
|
+
if (!params.fromToken) {
|
|
4679
|
+
throw new ValidationError("fromToken is required", "fromToken");
|
|
4680
|
+
}
|
|
4681
|
+
if (!params.toToken) {
|
|
4682
|
+
throw new ValidationError("toToken is required", "toToken");
|
|
4683
|
+
}
|
|
4684
|
+
if (!params.amount || params.amount <= BigInt(0)) {
|
|
4685
|
+
throw new ValidationError("amount must be greater than 0", "amount");
|
|
4686
|
+
}
|
|
4687
|
+
if (!params.privacyLevel) {
|
|
4688
|
+
throw new ValidationError("privacyLevel is required", "privacyLevel");
|
|
4689
|
+
}
|
|
4690
|
+
if (params.privacyLevel !== import_types8.PrivacyLevel.TRANSPARENT && !params.recipientMetaAddress) {
|
|
4691
|
+
throw new ValidationError(
|
|
4692
|
+
"recipientMetaAddress is required for shielded/compliant privacy modes",
|
|
4693
|
+
"recipientMetaAddress"
|
|
4694
|
+
);
|
|
4695
|
+
}
|
|
4696
|
+
if (params.privacyLevel === import_types8.PrivacyLevel.TRANSPARENT && !params.senderAddress) {
|
|
4697
|
+
throw new ValidationError(
|
|
4698
|
+
"senderAddress is required for transparent mode",
|
|
4699
|
+
"senderAddress"
|
|
4700
|
+
);
|
|
4701
|
+
}
|
|
4702
|
+
if (!this.capabilities.supportedSourceChains.includes(params.fromChain)) {
|
|
4703
|
+
throw new ValidationError(
|
|
4704
|
+
`Source chain ${params.fromChain} is not supported`,
|
|
4705
|
+
"fromChain",
|
|
4706
|
+
{ supportedChains: this.capabilities.supportedSourceChains }
|
|
4707
|
+
);
|
|
4708
|
+
}
|
|
4709
|
+
if (!this.capabilities.supportedDestinationChains.includes(params.toChain)) {
|
|
4710
|
+
throw new ValidationError(
|
|
4711
|
+
`Destination chain ${params.toChain} is not supported`,
|
|
4712
|
+
"toChain",
|
|
4713
|
+
{ supportedChains: this.capabilities.supportedDestinationChains }
|
|
4714
|
+
);
|
|
4715
|
+
}
|
|
4716
|
+
}
|
|
4717
|
+
generateRequestId() {
|
|
4718
|
+
return `req_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
|
|
4719
|
+
}
|
|
4720
|
+
};
|
|
4721
|
+
function createNEARIntentsBackend(config) {
|
|
4722
|
+
return new NEARIntentsBackend(config);
|
|
4723
|
+
}
|
|
4724
|
+
|
|
4725
|
+
// src/settlement/backends/zcash-native.ts
|
|
4726
|
+
var import_types9 = require("@sip-protocol/types");
|
|
4727
|
+
var ZcashNativeBackend = class {
|
|
4728
|
+
name = "zcash-native";
|
|
4729
|
+
capabilities;
|
|
4730
|
+
swapService;
|
|
4731
|
+
config;
|
|
4732
|
+
quotes = /* @__PURE__ */ new Map();
|
|
4733
|
+
swaps = /* @__PURE__ */ new Map();
|
|
4734
|
+
constructor(config) {
|
|
4735
|
+
this.swapService = config.swapService;
|
|
4736
|
+
this.config = {
|
|
4737
|
+
quoteValiditySeconds: config.quoteValiditySeconds ?? 300,
|
|
4738
|
+
networkFeeZatoshis: config.networkFeeZatoshis ?? 1e4
|
|
4739
|
+
};
|
|
4740
|
+
this.capabilities = {
|
|
4741
|
+
supportedSourceChains: ["zcash"],
|
|
4742
|
+
supportedDestinationChains: ["zcash"],
|
|
4743
|
+
supportedPrivacyLevels: [
|
|
4744
|
+
import_types9.PrivacyLevel.TRANSPARENT,
|
|
4745
|
+
import_types9.PrivacyLevel.SHIELDED,
|
|
4746
|
+
import_types9.PrivacyLevel.COMPLIANT
|
|
4747
|
+
],
|
|
4748
|
+
supportsCancellation: false,
|
|
4749
|
+
supportsRefunds: false,
|
|
4750
|
+
averageExecutionTime: 75,
|
|
4751
|
+
// ~75 seconds for Zcash block confirmation
|
|
4752
|
+
features: [
|
|
4753
|
+
"native-zcash",
|
|
4754
|
+
"shielded-addresses",
|
|
4755
|
+
"transparent-addresses",
|
|
4756
|
+
"instant-quotes"
|
|
4757
|
+
]
|
|
4758
|
+
};
|
|
4759
|
+
}
|
|
4760
|
+
// ─── Quote Methods ─────────────────────────────────────────────────────────
|
|
4761
|
+
/**
|
|
4762
|
+
* Get a quote for ZEC → ZEC transfer
|
|
4763
|
+
*/
|
|
4764
|
+
async getQuote(params) {
|
|
4765
|
+
this.validateQuoteParams(params);
|
|
4766
|
+
const { amount, recipientMetaAddress, senderAddress, privacyLevel } = params;
|
|
4767
|
+
const quoteId = this.generateQuoteId();
|
|
4768
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
4769
|
+
const expiresAt = now + this.config.quoteValiditySeconds;
|
|
4770
|
+
const networkFee = BigInt(this.config.networkFeeZatoshis);
|
|
4771
|
+
const protocolFee = BigInt(0);
|
|
4772
|
+
const totalFee = networkFee;
|
|
4773
|
+
const amountOut = amount - totalFee;
|
|
4774
|
+
if (amountOut <= BigInt(0)) {
|
|
4775
|
+
throw new ValidationError(
|
|
4776
|
+
"Amount too small to cover network fees",
|
|
4777
|
+
"amount",
|
|
4778
|
+
{ amount: amount.toString(), networkFee: networkFee.toString() },
|
|
4779
|
+
"SIP_2004" /* INVALID_AMOUNT */
|
|
4780
|
+
);
|
|
4781
|
+
}
|
|
4782
|
+
const minAmountOut = amountOut * BigInt(99) / BigInt(100);
|
|
4783
|
+
let depositAddress;
|
|
4784
|
+
let recipientAddress;
|
|
4785
|
+
if (privacyLevel === import_types9.PrivacyLevel.SHIELDED || privacyLevel === import_types9.PrivacyLevel.COMPLIANT) {
|
|
4786
|
+
if (typeof recipientMetaAddress === "string") {
|
|
4787
|
+
recipientAddress = recipientMetaAddress;
|
|
4788
|
+
} else if (recipientMetaAddress) {
|
|
4789
|
+
recipientAddress = `zs1${this.randomHex(72)}`;
|
|
4790
|
+
} else {
|
|
4791
|
+
throw new ValidationError(
|
|
4792
|
+
"Recipient address required for shielded transfers",
|
|
4793
|
+
"recipientMetaAddress",
|
|
4794
|
+
void 0,
|
|
4795
|
+
"SIP_2000" /* VALIDATION_FAILED */
|
|
4796
|
+
);
|
|
4797
|
+
}
|
|
4798
|
+
depositAddress = `zs1${this.randomHex(72)}`;
|
|
4799
|
+
} else {
|
|
4800
|
+
if (senderAddress) {
|
|
4801
|
+
depositAddress = senderAddress;
|
|
4802
|
+
} else {
|
|
4803
|
+
depositAddress = `t1${this.randomBase58(33)}`;
|
|
4804
|
+
}
|
|
4805
|
+
if (typeof recipientMetaAddress === "string") {
|
|
4806
|
+
recipientAddress = recipientMetaAddress;
|
|
4807
|
+
} else {
|
|
4808
|
+
throw new ValidationError(
|
|
4809
|
+
"Recipient address required",
|
|
4810
|
+
"recipientMetaAddress",
|
|
4811
|
+
void 0,
|
|
4812
|
+
"SIP_2000" /* VALIDATION_FAILED */
|
|
4813
|
+
);
|
|
4814
|
+
}
|
|
4815
|
+
}
|
|
4816
|
+
const quote = {
|
|
4817
|
+
quoteId,
|
|
4818
|
+
amountIn: amount.toString(),
|
|
4819
|
+
amountOut: amountOut.toString(),
|
|
4820
|
+
minAmountOut: minAmountOut.toString(),
|
|
4821
|
+
fees: {
|
|
4822
|
+
networkFee: networkFee.toString(),
|
|
4823
|
+
protocolFee: protocolFee.toString()
|
|
4824
|
+
},
|
|
4825
|
+
depositAddress,
|
|
4826
|
+
recipientAddress,
|
|
4827
|
+
expiresAt,
|
|
4828
|
+
estimatedTime: this.capabilities.averageExecutionTime,
|
|
4829
|
+
metadata: {
|
|
4830
|
+
backend: this.name,
|
|
4831
|
+
privacyLevel,
|
|
4832
|
+
zcashNetwork: "mainnet"
|
|
4833
|
+
}
|
|
4834
|
+
};
|
|
4835
|
+
this.quotes.set(quoteId, quote);
|
|
4836
|
+
return quote;
|
|
4837
|
+
}
|
|
4838
|
+
/**
|
|
4839
|
+
* Get a dry quote (preview without creating deposit address)
|
|
4840
|
+
*/
|
|
4841
|
+
async getDryQuote(params) {
|
|
4842
|
+
return this.getQuote(params);
|
|
4843
|
+
}
|
|
4844
|
+
// ─── Swap Execution ────────────────────────────────────────────────────────
|
|
4845
|
+
/**
|
|
4846
|
+
* Execute a ZEC → ZEC swap/transfer
|
|
4847
|
+
*/
|
|
4848
|
+
async executeSwap(params) {
|
|
4849
|
+
const { quoteId, depositTxHash } = params;
|
|
4850
|
+
const quote = this.quotes.get(quoteId);
|
|
4851
|
+
if (!quote) {
|
|
4852
|
+
throw new ValidationError(
|
|
4853
|
+
"Quote not found or expired",
|
|
4854
|
+
"quoteId",
|
|
4855
|
+
{ quoteId },
|
|
4856
|
+
"SIP_2000" /* VALIDATION_FAILED */
|
|
4857
|
+
);
|
|
4858
|
+
}
|
|
4859
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
4860
|
+
if (now > quote.expiresAt) {
|
|
4861
|
+
throw new ValidationError(
|
|
4862
|
+
"Quote has expired",
|
|
4863
|
+
"quoteId",
|
|
4864
|
+
{ quoteId, expiresAt: quote.expiresAt, now },
|
|
4865
|
+
"SIP_2000" /* VALIDATION_FAILED */
|
|
4866
|
+
);
|
|
4867
|
+
}
|
|
4868
|
+
const swapId = this.generateSwapId();
|
|
4869
|
+
const result = {
|
|
4870
|
+
swapId,
|
|
4871
|
+
status: depositTxHash ? "deposit_confirmed" /* DEPOSIT_CONFIRMED */ : "pending_deposit" /* PENDING_DEPOSIT */,
|
|
4872
|
+
quoteId,
|
|
4873
|
+
depositAddress: quote.depositAddress,
|
|
4874
|
+
depositTxHash,
|
|
4875
|
+
metadata: {
|
|
4876
|
+
backend: this.name,
|
|
4877
|
+
recipientAddress: quote.recipientAddress
|
|
4878
|
+
}
|
|
4879
|
+
};
|
|
4880
|
+
this.swaps.set(swapId, result);
|
|
4881
|
+
if (depositTxHash) {
|
|
4882
|
+
this.simulateSwapExecution(swapId, quote);
|
|
4883
|
+
}
|
|
4884
|
+
return result;
|
|
4885
|
+
}
|
|
4886
|
+
// ─── Status Methods ────────────────────────────────────────────────────────
|
|
4887
|
+
/**
|
|
4888
|
+
* Get swap status
|
|
4889
|
+
*/
|
|
4890
|
+
async getStatus(swapId) {
|
|
4891
|
+
const swap = this.swaps.get(swapId);
|
|
4892
|
+
if (!swap) {
|
|
4893
|
+
throw new ValidationError(
|
|
4894
|
+
"Swap not found",
|
|
4895
|
+
"swapId",
|
|
4896
|
+
{ swapId },
|
|
4897
|
+
"SIP_2000" /* VALIDATION_FAILED */
|
|
4898
|
+
);
|
|
4899
|
+
}
|
|
4900
|
+
const quote = this.quotes.get(swap.quoteId);
|
|
4901
|
+
if (!quote) {
|
|
4902
|
+
throw new ValidationError(
|
|
4903
|
+
"Quote not found for swap",
|
|
4904
|
+
"quoteId",
|
|
4905
|
+
{ quoteId: swap.quoteId },
|
|
4906
|
+
"SIP_2000" /* VALIDATION_FAILED */
|
|
4907
|
+
);
|
|
4908
|
+
}
|
|
4909
|
+
const status = {
|
|
4910
|
+
swapId: swap.swapId,
|
|
4911
|
+
status: swap.status,
|
|
4912
|
+
quoteId: swap.quoteId,
|
|
4913
|
+
depositAddress: swap.depositAddress,
|
|
4914
|
+
amountIn: quote.amountIn,
|
|
4915
|
+
amountOut: quote.amountOut,
|
|
4916
|
+
depositTxHash: swap.depositTxHash,
|
|
4917
|
+
settlementTxHash: swap.settlementTxHash,
|
|
4918
|
+
actualAmountOut: swap.actualAmountOut,
|
|
4919
|
+
errorMessage: swap.errorMessage,
|
|
4920
|
+
updatedAt: Math.floor(Date.now() / 1e3),
|
|
4921
|
+
metadata: swap.metadata
|
|
4922
|
+
};
|
|
4923
|
+
return status;
|
|
4924
|
+
}
|
|
4925
|
+
/**
|
|
4926
|
+
* Wait for swap completion
|
|
4927
|
+
*/
|
|
4928
|
+
async waitForCompletion(swapId, options) {
|
|
4929
|
+
const interval = options?.interval ?? 5e3;
|
|
4930
|
+
const timeout = options?.timeout ?? 6e5;
|
|
4931
|
+
const startTime = Date.now();
|
|
4932
|
+
while (Date.now() - startTime < timeout) {
|
|
4933
|
+
const status2 = await this.getStatus(swapId);
|
|
4934
|
+
if (options?.onStatusChange) {
|
|
4935
|
+
options.onStatusChange(status2);
|
|
4936
|
+
}
|
|
4937
|
+
if (status2.status === "success" /* SUCCESS */) {
|
|
4938
|
+
return status2;
|
|
4939
|
+
}
|
|
4940
|
+
if (status2.status === "failed" /* FAILED */ || status2.status === "cancelled" /* CANCELLED */ || status2.status === "refunded" /* REFUNDED */) {
|
|
4941
|
+
return status2;
|
|
4942
|
+
}
|
|
4943
|
+
await this.delay(interval);
|
|
4944
|
+
}
|
|
4945
|
+
const status = await this.getStatus(swapId);
|
|
4946
|
+
return status;
|
|
4947
|
+
}
|
|
4948
|
+
/**
|
|
4949
|
+
* Notify backend of deposit
|
|
4950
|
+
*/
|
|
4951
|
+
async notifyDeposit(swapId, txHash, metadata) {
|
|
4952
|
+
const swap = this.swaps.get(swapId);
|
|
4953
|
+
if (!swap) {
|
|
4954
|
+
throw new ValidationError(
|
|
4955
|
+
"Swap not found",
|
|
4956
|
+
"swapId",
|
|
4957
|
+
{ swapId },
|
|
4958
|
+
"SIP_2000" /* VALIDATION_FAILED */
|
|
4959
|
+
);
|
|
4960
|
+
}
|
|
4961
|
+
swap.depositTxHash = txHash;
|
|
4962
|
+
swap.status = "deposit_confirmed" /* DEPOSIT_CONFIRMED */;
|
|
4963
|
+
if (metadata) {
|
|
4964
|
+
swap.metadata = { ...swap.metadata, ...metadata };
|
|
4965
|
+
}
|
|
4966
|
+
this.swaps.set(swapId, swap);
|
|
4967
|
+
const quote = this.quotes.get(swap.quoteId);
|
|
4968
|
+
if (quote) {
|
|
4969
|
+
this.simulateSwapExecution(swapId, quote);
|
|
4970
|
+
}
|
|
4971
|
+
}
|
|
4972
|
+
// ─── Private Helpers ───────────────────────────────────────────────────────
|
|
4973
|
+
validateQuoteParams(params) {
|
|
4974
|
+
if (params.fromChain !== "zcash") {
|
|
4975
|
+
throw new ValidationError(
|
|
4976
|
+
"Source chain must be zcash",
|
|
4977
|
+
"fromChain",
|
|
4978
|
+
{ received: params.fromChain, expected: "zcash" },
|
|
4979
|
+
"SIP_2000" /* VALIDATION_FAILED */
|
|
4980
|
+
);
|
|
4981
|
+
}
|
|
4982
|
+
if (params.toChain !== "zcash") {
|
|
4983
|
+
throw new ValidationError(
|
|
4984
|
+
"Destination chain must be zcash",
|
|
4985
|
+
"toChain",
|
|
4986
|
+
{ received: params.toChain, expected: "zcash" },
|
|
4987
|
+
"SIP_2000" /* VALIDATION_FAILED */
|
|
4988
|
+
);
|
|
4989
|
+
}
|
|
4990
|
+
if (params.fromToken !== "ZEC") {
|
|
4991
|
+
throw new ValidationError(
|
|
4992
|
+
"Source token must be ZEC",
|
|
4993
|
+
"fromToken",
|
|
4994
|
+
{ received: params.fromToken, expected: "ZEC" },
|
|
4995
|
+
"SIP_2000" /* VALIDATION_FAILED */
|
|
4996
|
+
);
|
|
4997
|
+
}
|
|
4998
|
+
if (params.toToken !== "ZEC") {
|
|
4999
|
+
throw new ValidationError(
|
|
5000
|
+
"Destination token must be ZEC",
|
|
5001
|
+
"toToken",
|
|
5002
|
+
{ received: params.toToken, expected: "ZEC" },
|
|
5003
|
+
"SIP_2000" /* VALIDATION_FAILED */
|
|
5004
|
+
);
|
|
5005
|
+
}
|
|
5006
|
+
if (!params.amount || params.amount <= BigInt(0)) {
|
|
5007
|
+
throw new ValidationError(
|
|
5008
|
+
"Amount must be positive",
|
|
5009
|
+
"amount",
|
|
5010
|
+
{ received: params.amount },
|
|
5011
|
+
"SIP_2004" /* INVALID_AMOUNT */
|
|
5012
|
+
);
|
|
5013
|
+
}
|
|
5014
|
+
if (!this.capabilities.supportedPrivacyLevels.includes(params.privacyLevel)) {
|
|
5015
|
+
throw new ValidationError(
|
|
5016
|
+
"Unsupported privacy level",
|
|
5017
|
+
"privacyLevel",
|
|
5018
|
+
{ received: params.privacyLevel, supported: this.capabilities.supportedPrivacyLevels },
|
|
5019
|
+
"SIP_2000" /* VALIDATION_FAILED */
|
|
5020
|
+
);
|
|
5021
|
+
}
|
|
5022
|
+
}
|
|
5023
|
+
simulateSwapExecution(swapId, quote) {
|
|
5024
|
+
setTimeout(() => {
|
|
5025
|
+
const swap = this.swaps.get(swapId);
|
|
5026
|
+
if (!swap) return;
|
|
5027
|
+
swap.status = "in_progress" /* IN_PROGRESS */;
|
|
5028
|
+
this.swaps.set(swapId, swap);
|
|
5029
|
+
setTimeout(() => {
|
|
5030
|
+
const finalSwap = this.swaps.get(swapId);
|
|
5031
|
+
if (!finalSwap) return;
|
|
5032
|
+
finalSwap.status = "success" /* SUCCESS */;
|
|
5033
|
+
finalSwap.settlementTxHash = this.randomHex(64);
|
|
5034
|
+
finalSwap.actualAmountOut = quote.amountOut;
|
|
5035
|
+
this.swaps.set(swapId, finalSwap);
|
|
5036
|
+
}, 2e3);
|
|
5037
|
+
}, 1e3);
|
|
5038
|
+
}
|
|
5039
|
+
generateQuoteId() {
|
|
5040
|
+
return `zec_native_quote_${Date.now()}_${this.randomHex(8)}`;
|
|
5041
|
+
}
|
|
5042
|
+
generateSwapId() {
|
|
5043
|
+
return `zec_native_swap_${Date.now()}_${this.randomHex(8)}`;
|
|
5044
|
+
}
|
|
5045
|
+
randomHex(length) {
|
|
5046
|
+
const chars = "0123456789abcdef";
|
|
5047
|
+
let result = "";
|
|
5048
|
+
for (let i = 0; i < length; i++) {
|
|
5049
|
+
result += chars[Math.floor(Math.random() * chars.length)];
|
|
5050
|
+
}
|
|
5051
|
+
return result;
|
|
5052
|
+
}
|
|
5053
|
+
randomBase58(length) {
|
|
5054
|
+
const chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
5055
|
+
let result = "";
|
|
5056
|
+
for (let i = 0; i < length; i++) {
|
|
5057
|
+
result += chars[Math.floor(Math.random() * chars.length)];
|
|
5058
|
+
}
|
|
5059
|
+
return result;
|
|
5060
|
+
}
|
|
5061
|
+
delay(ms) {
|
|
5062
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
5063
|
+
}
|
|
5064
|
+
};
|
|
5065
|
+
function createZcashNativeBackend(config) {
|
|
5066
|
+
return new ZcashNativeBackend(config);
|
|
5067
|
+
}
|
|
5068
|
+
|
|
5069
|
+
// src/settlement/backends/direct-chain.ts
|
|
5070
|
+
var import_types10 = require("@sip-protocol/types");
|
|
5071
|
+
var import_utils11 = require("@noble/hashes/utils");
|
|
5072
|
+
var DEFAULT_GAS_FEES = {
|
|
5073
|
+
ethereum: 21000n * 50n * 1000000000n,
|
|
5074
|
+
// 21k gas * 50 gwei = 0.00105 ETH
|
|
5075
|
+
solana: 5000n,
|
|
5076
|
+
// 5000 lamports = 0.000005 SOL
|
|
5077
|
+
near: 300000000000000000000n,
|
|
5078
|
+
// 0.3 NEAR in yoctoNEAR
|
|
5079
|
+
zcash: 10000n,
|
|
5080
|
+
// 0.0001 ZEC in zatoshi
|
|
5081
|
+
polygon: 21000n * 30n * 1000000000n,
|
|
5082
|
+
// 21k gas * 30 gwei POL
|
|
5083
|
+
arbitrum: 2100000000n,
|
|
5084
|
+
// 21k gas * 0.1 gwei ETH = 2100 gwei = 2.1e9 wei
|
|
5085
|
+
optimism: 21000000n,
|
|
5086
|
+
// 21k gas * 0.001 gwei ETH = 21 gwei = 21e6 wei
|
|
5087
|
+
base: 2100000000n,
|
|
5088
|
+
// 21k gas * 0.1 gwei ETH = 2100 gwei = 2.1e9 wei
|
|
5089
|
+
bitcoin: 10000n
|
|
5090
|
+
// 10000 sats = 0.0001 BTC (estimate for 1 input, 2 outputs)
|
|
5091
|
+
};
|
|
5092
|
+
|
|
5093
|
+
// src/zcash/rpc-client.ts
|
|
5094
|
+
var import_types11 = require("@sip-protocol/types");
|
|
3969
5095
|
var DEFAULT_CONFIG = {
|
|
3970
5096
|
host: "127.0.0.1",
|
|
3971
5097
|
port: 8232,
|
|
@@ -3985,19 +5111,19 @@ var ZcashRPCError = class extends Error {
|
|
|
3985
5111
|
* Check if error is due to insufficient funds
|
|
3986
5112
|
*/
|
|
3987
5113
|
isInsufficientFunds() {
|
|
3988
|
-
return this.code ===
|
|
5114
|
+
return this.code === import_types11.ZcashErrorCode.WALLET_INSUFFICIENT_FUNDS;
|
|
3989
5115
|
}
|
|
3990
5116
|
/**
|
|
3991
5117
|
* Check if error is due to invalid address
|
|
3992
5118
|
*/
|
|
3993
5119
|
isInvalidAddress() {
|
|
3994
|
-
return this.code ===
|
|
5120
|
+
return this.code === import_types11.ZcashErrorCode.INVALID_ADDRESS_OR_KEY;
|
|
3995
5121
|
}
|
|
3996
5122
|
/**
|
|
3997
5123
|
* Check if error is due to wallet being locked
|
|
3998
5124
|
*/
|
|
3999
5125
|
isWalletLocked() {
|
|
4000
|
-
return this.code ===
|
|
5126
|
+
return this.code === import_types11.ZcashErrorCode.WALLET_UNLOCK_NEEDED;
|
|
4001
5127
|
}
|
|
4002
5128
|
};
|
|
4003
5129
|
var ZcashRPCClient = class {
|
|
@@ -4384,7 +5510,7 @@ function createZcashClient(config) {
|
|
|
4384
5510
|
}
|
|
4385
5511
|
|
|
4386
5512
|
// src/zcash/shielded-service.ts
|
|
4387
|
-
var
|
|
5513
|
+
var import_types12 = require("@sip-protocol/types");
|
|
4388
5514
|
var ZcashShieldedService = class _ZcashShieldedService {
|
|
4389
5515
|
client;
|
|
4390
5516
|
config;
|
|
@@ -4570,7 +5696,7 @@ var ZcashShieldedService = class _ZcashShieldedService {
|
|
|
4570
5696
|
* Higher-level method that handles privacy level mapping.
|
|
4571
5697
|
*/
|
|
4572
5698
|
async sendWithPrivacy(to, amount, privacyLevel, memo) {
|
|
4573
|
-
if (privacyLevel ===
|
|
5699
|
+
if (privacyLevel === import_types12.PrivacyLevel.TRANSPARENT) {
|
|
4574
5700
|
throw new ValidationError(
|
|
4575
5701
|
"Transparent mode not supported for Zcash shielded service. Use standard RPC client.",
|
|
4576
5702
|
"privacyLevel",
|
|
@@ -4664,7 +5790,7 @@ var ZcashShieldedService = class _ZcashShieldedService {
|
|
|
4664
5790
|
const viewingKey = await this.exportViewingKey();
|
|
4665
5791
|
return {
|
|
4666
5792
|
viewingKey,
|
|
4667
|
-
privacyLevel:
|
|
5793
|
+
privacyLevel: import_types12.PrivacyLevel.COMPLIANT,
|
|
4668
5794
|
disclaimer: "This viewing key provides read-only access to transaction history. It cannot be used to spend funds. Share only with authorized auditors."
|
|
4669
5795
|
};
|
|
4670
5796
|
}
|
|
@@ -4750,11 +5876,11 @@ var ZcashShieldedService = class _ZcashShieldedService {
|
|
|
4750
5876
|
*/
|
|
4751
5877
|
mapPrivacyLevelToPolicy(level) {
|
|
4752
5878
|
switch (level) {
|
|
4753
|
-
case
|
|
5879
|
+
case import_types12.PrivacyLevel.TRANSPARENT:
|
|
4754
5880
|
return "NoPrivacy";
|
|
4755
|
-
case
|
|
5881
|
+
case import_types12.PrivacyLevel.SHIELDED:
|
|
4756
5882
|
return "FullPrivacy";
|
|
4757
|
-
case
|
|
5883
|
+
case import_types12.PrivacyLevel.COMPLIANT:
|
|
4758
5884
|
return "FullPrivacy";
|
|
4759
5885
|
default:
|
|
4760
5886
|
return "FullPrivacy";
|
|
@@ -4807,7 +5933,7 @@ function createZcashShieldedService(config) {
|
|
|
4807
5933
|
}
|
|
4808
5934
|
|
|
4809
5935
|
// src/zcash/swap-service.ts
|
|
4810
|
-
var
|
|
5936
|
+
var import_types13 = require("@sip-protocol/types");
|
|
4811
5937
|
var MOCK_PRICES = {
|
|
4812
5938
|
ETH: 2500,
|
|
4813
5939
|
SOL: 120,
|
|
@@ -4835,6 +5961,12 @@ var ZcashSwapService = class {
|
|
|
4835
5961
|
quotes = /* @__PURE__ */ new Map();
|
|
4836
5962
|
swaps = /* @__PURE__ */ new Map();
|
|
4837
5963
|
constructor(config) {
|
|
5964
|
+
if (config.mode === "production" && !config.bridgeProvider) {
|
|
5965
|
+
throw new IntentError(
|
|
5966
|
+
"Bridge provider required for production mode",
|
|
5967
|
+
"SIP_5004" /* INTENT_INVALID_STATE */
|
|
5968
|
+
);
|
|
5969
|
+
}
|
|
4838
5970
|
this.config = {
|
|
4839
5971
|
mode: config.mode,
|
|
4840
5972
|
defaultSlippage: config.defaultSlippage ?? 100,
|
|
@@ -4914,7 +6046,7 @@ var ZcashSwapService = class {
|
|
|
4914
6046
|
validUntil,
|
|
4915
6047
|
depositAddress: this.generateMockDepositAddress(sourceChain),
|
|
4916
6048
|
estimatedTime: this.getEstimatedTime(sourceChain),
|
|
4917
|
-
privacyLevel:
|
|
6049
|
+
privacyLevel: import_types13.PrivacyLevel.SHIELDED
|
|
4918
6050
|
};
|
|
4919
6051
|
this.quotes.set(quoteId, quote);
|
|
4920
6052
|
return quote;
|
|
@@ -4957,7 +6089,7 @@ var ZcashSwapService = class {
|
|
|
4957
6089
|
depositAddress: "",
|
|
4958
6090
|
// Will be set by bridge
|
|
4959
6091
|
estimatedTime: this.getEstimatedTime(params.sourceChain),
|
|
4960
|
-
privacyLevel:
|
|
6092
|
+
privacyLevel: import_types13.PrivacyLevel.SHIELDED
|
|
4961
6093
|
};
|
|
4962
6094
|
this.quotes.set(quote.quoteId, quote);
|
|
4963
6095
|
return quote;
|
|
@@ -5237,15 +6369,15 @@ function createZcashSwapService(config) {
|
|
|
5237
6369
|
}
|
|
5238
6370
|
|
|
5239
6371
|
// src/zcash/index.ts
|
|
5240
|
-
var
|
|
6372
|
+
var import_types14 = require("@sip-protocol/types");
|
|
5241
6373
|
|
|
5242
6374
|
// src/index.ts
|
|
5243
|
-
var
|
|
6375
|
+
var import_types42 = require("@sip-protocol/types");
|
|
5244
6376
|
|
|
5245
6377
|
// src/payment/payment.ts
|
|
5246
|
-
var
|
|
6378
|
+
var import_types15 = require("@sip-protocol/types");
|
|
5247
6379
|
var import_sha2569 = require("@noble/hashes/sha256");
|
|
5248
|
-
var
|
|
6380
|
+
var import_utils12 = require("@noble/hashes/utils");
|
|
5249
6381
|
var import_chacha2 = require("@noble/ciphers/chacha.js");
|
|
5250
6382
|
var import_hkdf2 = require("@noble/hashes/hkdf");
|
|
5251
6383
|
|
|
@@ -5430,7 +6562,7 @@ var PaymentBuilder = class {
|
|
|
5430
6562
|
_amount;
|
|
5431
6563
|
_recipientMetaAddress;
|
|
5432
6564
|
_recipientAddress;
|
|
5433
|
-
_privacy =
|
|
6565
|
+
_privacy = import_types15.PrivacyLevel.SHIELDED;
|
|
5434
6566
|
_viewingKey;
|
|
5435
6567
|
_sourceChain;
|
|
5436
6568
|
_destinationChain;
|
|
@@ -5713,7 +6845,7 @@ async function createShieldedPayment(params, options) {
|
|
|
5713
6845
|
} else {
|
|
5714
6846
|
resolvedToken = token;
|
|
5715
6847
|
}
|
|
5716
|
-
if (privacy !==
|
|
6848
|
+
if (privacy !== import_types15.PrivacyLevel.TRANSPARENT && !recipientMetaAddress) {
|
|
5717
6849
|
throw new ValidationError(
|
|
5718
6850
|
"recipientMetaAddress is required for shielded/compliant privacy modes",
|
|
5719
6851
|
"recipientMetaAddress",
|
|
@@ -5721,7 +6853,7 @@ async function createShieldedPayment(params, options) {
|
|
|
5721
6853
|
"SIP_2008" /* MISSING_REQUIRED */
|
|
5722
6854
|
);
|
|
5723
6855
|
}
|
|
5724
|
-
if (privacy ===
|
|
6856
|
+
if (privacy === import_types15.PrivacyLevel.TRANSPARENT && !recipientAddress) {
|
|
5725
6857
|
throw new ValidationError(
|
|
5726
6858
|
"recipientAddress is required for transparent mode",
|
|
5727
6859
|
"recipientAddress",
|
|
@@ -5729,7 +6861,7 @@ async function createShieldedPayment(params, options) {
|
|
|
5729
6861
|
"SIP_2008" /* MISSING_REQUIRED */
|
|
5730
6862
|
);
|
|
5731
6863
|
}
|
|
5732
|
-
if (privacy ===
|
|
6864
|
+
if (privacy === import_types15.PrivacyLevel.COMPLIANT && !viewingKey) {
|
|
5733
6865
|
throw new ValidationError(
|
|
5734
6866
|
"viewingKey is required for compliant mode",
|
|
5735
6867
|
"viewingKey",
|
|
@@ -5741,8 +6873,8 @@ async function createShieldedPayment(params, options) {
|
|
|
5741
6873
|
let viewingKeyHash;
|
|
5742
6874
|
if (viewingKey) {
|
|
5743
6875
|
const keyHex = viewingKey.startsWith("0x") ? viewingKey.slice(2) : viewingKey;
|
|
5744
|
-
const keyBytes = (0,
|
|
5745
|
-
viewingKeyHash = `0x${(0,
|
|
6876
|
+
const keyBytes = (0, import_utils12.hexToBytes)(keyHex);
|
|
6877
|
+
viewingKeyHash = `0x${(0, import_utils12.bytesToHex)((0, import_sha2569.sha256)(keyBytes))}`;
|
|
5746
6878
|
}
|
|
5747
6879
|
const privacyConfig = getPrivacyConfig(
|
|
5748
6880
|
privacy,
|
|
@@ -5751,7 +6883,7 @@ async function createShieldedPayment(params, options) {
|
|
|
5751
6883
|
const now = Math.floor(Date.now() / 1e3);
|
|
5752
6884
|
const payment = {
|
|
5753
6885
|
paymentId,
|
|
5754
|
-
version:
|
|
6886
|
+
version: import_types15.SIP_VERSION,
|
|
5755
6887
|
privacyLevel: privacy,
|
|
5756
6888
|
createdAt: now,
|
|
5757
6889
|
expiry: now + ttl,
|
|
@@ -5762,7 +6894,7 @@ async function createShieldedPayment(params, options) {
|
|
|
5762
6894
|
purpose,
|
|
5763
6895
|
viewingKeyHash
|
|
5764
6896
|
};
|
|
5765
|
-
if (privacy !==
|
|
6897
|
+
if (privacy !== import_types15.PrivacyLevel.TRANSPARENT && recipientMetaAddress) {
|
|
5766
6898
|
const metaAddress = decodeStealthMetaAddress(recipientMetaAddress);
|
|
5767
6899
|
const { stealthAddress } = generateStealthAddress(metaAddress);
|
|
5768
6900
|
payment.recipientStealth = stealthAddress;
|
|
@@ -5779,10 +6911,10 @@ async function createShieldedPayment(params, options) {
|
|
|
5779
6911
|
payment.recipientAddress = recipientAddress;
|
|
5780
6912
|
payment.memo = memo;
|
|
5781
6913
|
}
|
|
5782
|
-
if (privacy !==
|
|
6914
|
+
if (privacy !== import_types15.PrivacyLevel.TRANSPARENT && proofProvider?.isReady) {
|
|
5783
6915
|
const hexToUint8 = (hex) => {
|
|
5784
6916
|
const cleanHex = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
5785
|
-
return (0,
|
|
6917
|
+
return (0, import_utils12.hexToBytes)(cleanHex);
|
|
5786
6918
|
};
|
|
5787
6919
|
const fundingResult = await proofProvider.generateFundingProof({
|
|
5788
6920
|
balance: amount,
|
|
@@ -5809,17 +6941,17 @@ async function createShieldedPayment(params, options) {
|
|
|
5809
6941
|
}
|
|
5810
6942
|
function encryptMemo(memo, viewingKey) {
|
|
5811
6943
|
const keyHex = viewingKey.startsWith("0x") ? viewingKey.slice(2) : viewingKey;
|
|
5812
|
-
const keyBytes = (0,
|
|
6944
|
+
const keyBytes = (0, import_utils12.hexToBytes)(keyHex);
|
|
5813
6945
|
const encKey = (0, import_hkdf2.hkdf)(import_sha2569.sha256, keyBytes, new Uint8Array(0), new Uint8Array(0), 32);
|
|
5814
6946
|
try {
|
|
5815
|
-
const nonce = (0,
|
|
6947
|
+
const nonce = (0, import_utils12.randomBytes)(24);
|
|
5816
6948
|
const cipher = (0, import_chacha2.xchacha20poly1305)(encKey, nonce);
|
|
5817
6949
|
const plaintext = new TextEncoder().encode(memo);
|
|
5818
6950
|
const ciphertext = cipher.encrypt(plaintext);
|
|
5819
6951
|
const result = new Uint8Array(nonce.length + ciphertext.length);
|
|
5820
6952
|
result.set(nonce);
|
|
5821
6953
|
result.set(ciphertext, nonce.length);
|
|
5822
|
-
return `0x${(0,
|
|
6954
|
+
return `0x${(0, import_utils12.bytesToHex)(result)}`;
|
|
5823
6955
|
} finally {
|
|
5824
6956
|
secureWipe(keyBytes);
|
|
5825
6957
|
secureWipe(encKey);
|
|
@@ -5827,11 +6959,11 @@ function encryptMemo(memo, viewingKey) {
|
|
|
5827
6959
|
}
|
|
5828
6960
|
function decryptMemo(encryptedMemo, viewingKey) {
|
|
5829
6961
|
const keyHex = viewingKey.startsWith("0x") ? viewingKey.slice(2) : viewingKey;
|
|
5830
|
-
const keyBytes = (0,
|
|
6962
|
+
const keyBytes = (0, import_utils12.hexToBytes)(keyHex);
|
|
5831
6963
|
const encKey = (0, import_hkdf2.hkdf)(import_sha2569.sha256, keyBytes, new Uint8Array(0), new Uint8Array(0), 32);
|
|
5832
6964
|
try {
|
|
5833
6965
|
const dataHex = encryptedMemo.startsWith("0x") ? encryptedMemo.slice(2) : encryptedMemo;
|
|
5834
|
-
const data = (0,
|
|
6966
|
+
const data = (0, import_utils12.hexToBytes)(dataHex);
|
|
5835
6967
|
const nonce = data.slice(0, 24);
|
|
5836
6968
|
const ciphertext = data.slice(24);
|
|
5837
6969
|
const cipher = (0, import_chacha2.xchacha20poly1305)(encKey, nonce);
|
|
@@ -5845,7 +6977,7 @@ function decryptMemo(encryptedMemo, viewingKey) {
|
|
|
5845
6977
|
function trackPayment(payment) {
|
|
5846
6978
|
return {
|
|
5847
6979
|
...payment,
|
|
5848
|
-
status:
|
|
6980
|
+
status: import_types15.PaymentStatus.DRAFT
|
|
5849
6981
|
};
|
|
5850
6982
|
}
|
|
5851
6983
|
function isPaymentExpired(payment) {
|
|
@@ -5878,10 +7010,10 @@ function getPaymentSummary(payment) {
|
|
|
5878
7010
|
}
|
|
5879
7011
|
|
|
5880
7012
|
// src/treasury/treasury.ts
|
|
5881
|
-
var
|
|
7013
|
+
var import_types16 = require("@sip-protocol/types");
|
|
5882
7014
|
var import_secp256k13 = require("@noble/curves/secp256k1");
|
|
5883
7015
|
var import_sha25610 = require("@noble/hashes/sha256");
|
|
5884
|
-
var
|
|
7016
|
+
var import_utils13 = require("@noble/hashes/utils");
|
|
5885
7017
|
var DEFAULT_PROPOSAL_TTL = 7 * 24 * 60 * 60;
|
|
5886
7018
|
var Treasury = class _Treasury {
|
|
5887
7019
|
config;
|
|
@@ -5911,7 +7043,7 @@ var Treasury = class _Treasury {
|
|
|
5911
7043
|
...m,
|
|
5912
7044
|
addedAt: now
|
|
5913
7045
|
})),
|
|
5914
|
-
defaultPrivacy: params.defaultPrivacy ??
|
|
7046
|
+
defaultPrivacy: params.defaultPrivacy ?? import_types16.PrivacyLevel.SHIELDED,
|
|
5915
7047
|
masterViewingKey,
|
|
5916
7048
|
dailyLimit: params.dailyLimit,
|
|
5917
7049
|
transactionLimit: params.transactionLimit,
|
|
@@ -5990,7 +7122,7 @@ var Treasury = class _Treasury {
|
|
|
5990
7122
|
proposalId,
|
|
5991
7123
|
treasuryId: this.config.treasuryId,
|
|
5992
7124
|
type: "payment",
|
|
5993
|
-
status:
|
|
7125
|
+
status: import_types16.ProposalStatus.PENDING,
|
|
5994
7126
|
proposer: "",
|
|
5995
7127
|
// Should be set by caller
|
|
5996
7128
|
title: params.title,
|
|
@@ -6023,7 +7155,7 @@ var Treasury = class _Treasury {
|
|
|
6023
7155
|
proposalId,
|
|
6024
7156
|
treasuryId: this.config.treasuryId,
|
|
6025
7157
|
type: "batch_payment",
|
|
6026
|
-
status:
|
|
7158
|
+
status: import_types16.ProposalStatus.PENDING,
|
|
6027
7159
|
proposer: "",
|
|
6028
7160
|
title: params.title,
|
|
6029
7161
|
description: params.description,
|
|
@@ -6057,7 +7189,7 @@ var Treasury = class _Treasury {
|
|
|
6057
7189
|
* Get pending proposals
|
|
6058
7190
|
*/
|
|
6059
7191
|
getPendingProposals() {
|
|
6060
|
-
return this.getAllProposals().filter((p) => p.status ===
|
|
7192
|
+
return this.getAllProposals().filter((p) => p.status === import_types16.ProposalStatus.PENDING);
|
|
6061
7193
|
}
|
|
6062
7194
|
/**
|
|
6063
7195
|
* Sign a proposal
|
|
@@ -6088,7 +7220,7 @@ var Treasury = class _Treasury {
|
|
|
6088
7220
|
"SIP_2001" /* INVALID_INPUT */
|
|
6089
7221
|
);
|
|
6090
7222
|
}
|
|
6091
|
-
if (proposal.status !==
|
|
7223
|
+
if (proposal.status !== import_types16.ProposalStatus.PENDING) {
|
|
6092
7224
|
throw new ValidationError(
|
|
6093
7225
|
`proposal is not pending: ${proposal.status}`,
|
|
6094
7226
|
"proposalId",
|
|
@@ -6098,7 +7230,7 @@ var Treasury = class _Treasury {
|
|
|
6098
7230
|
}
|
|
6099
7231
|
const now = Math.floor(Date.now() / 1e3);
|
|
6100
7232
|
if (now > proposal.expiresAt) {
|
|
6101
|
-
proposal.status =
|
|
7233
|
+
proposal.status = import_types16.ProposalStatus.EXPIRED;
|
|
6102
7234
|
throw new ValidationError(
|
|
6103
7235
|
"proposal has expired",
|
|
6104
7236
|
"proposalId",
|
|
@@ -6130,9 +7262,9 @@ var Treasury = class _Treasury {
|
|
|
6130
7262
|
const approvals = proposal.signatures.filter((s) => s.approved).length;
|
|
6131
7263
|
const rejections = proposal.signatures.filter((s) => !s.approved).length;
|
|
6132
7264
|
if (approvals >= proposal.requiredSignatures) {
|
|
6133
|
-
proposal.status =
|
|
7265
|
+
proposal.status = import_types16.ProposalStatus.APPROVED;
|
|
6134
7266
|
} else if (rejections > this.config.totalSigners - proposal.requiredSignatures) {
|
|
6135
|
-
proposal.status =
|
|
7267
|
+
proposal.status = import_types16.ProposalStatus.REJECTED;
|
|
6136
7268
|
}
|
|
6137
7269
|
return proposal;
|
|
6138
7270
|
}
|
|
@@ -6149,7 +7281,7 @@ var Treasury = class _Treasury {
|
|
|
6149
7281
|
"SIP_2001" /* INVALID_INPUT */
|
|
6150
7282
|
);
|
|
6151
7283
|
}
|
|
6152
|
-
if (proposal.status !==
|
|
7284
|
+
if (proposal.status !== import_types16.ProposalStatus.APPROVED) {
|
|
6153
7285
|
throw new ValidationError(
|
|
6154
7286
|
`proposal is not approved: ${proposal.status}`,
|
|
6155
7287
|
"proposalId",
|
|
@@ -6162,8 +7294,8 @@ var Treasury = class _Treasury {
|
|
|
6162
7294
|
const payment = await createShieldedPayment({
|
|
6163
7295
|
token: proposal.payment.token,
|
|
6164
7296
|
amount: proposal.payment.amount,
|
|
6165
|
-
recipientMetaAddress: proposal.payment.privacy !==
|
|
6166
|
-
recipientAddress: proposal.payment.privacy ===
|
|
7297
|
+
recipientMetaAddress: proposal.payment.privacy !== import_types16.PrivacyLevel.TRANSPARENT ? proposal.payment.recipient : void 0,
|
|
7298
|
+
recipientAddress: proposal.payment.privacy === import_types16.PrivacyLevel.TRANSPARENT ? proposal.payment.recipient : void 0,
|
|
6167
7299
|
privacy: proposal.payment.privacy,
|
|
6168
7300
|
viewingKey: this.config.masterViewingKey?.key,
|
|
6169
7301
|
sourceChain: this.config.chain,
|
|
@@ -6176,8 +7308,8 @@ var Treasury = class _Treasury {
|
|
|
6176
7308
|
const payment = await createShieldedPayment({
|
|
6177
7309
|
token: proposal.batchPayment.token,
|
|
6178
7310
|
amount: recipient.amount,
|
|
6179
|
-
recipientMetaAddress: proposal.batchPayment.privacy !==
|
|
6180
|
-
recipientAddress: proposal.batchPayment.privacy ===
|
|
7311
|
+
recipientMetaAddress: proposal.batchPayment.privacy !== import_types16.PrivacyLevel.TRANSPARENT ? recipient.address : void 0,
|
|
7312
|
+
recipientAddress: proposal.batchPayment.privacy === import_types16.PrivacyLevel.TRANSPARENT ? recipient.address : void 0,
|
|
6181
7313
|
privacy: proposal.batchPayment.privacy,
|
|
6182
7314
|
viewingKey: this.config.masterViewingKey?.key,
|
|
6183
7315
|
sourceChain: this.config.chain,
|
|
@@ -6187,7 +7319,7 @@ var Treasury = class _Treasury {
|
|
|
6187
7319
|
payments.push(payment);
|
|
6188
7320
|
}
|
|
6189
7321
|
}
|
|
6190
|
-
proposal.status =
|
|
7322
|
+
proposal.status = import_types16.ProposalStatus.EXECUTED;
|
|
6191
7323
|
proposal.executedAt = Math.floor(Date.now() / 1e3);
|
|
6192
7324
|
proposal.resultPayments = payments;
|
|
6193
7325
|
return payments;
|
|
@@ -6216,7 +7348,7 @@ var Treasury = class _Treasury {
|
|
|
6216
7348
|
"SIP_2001" /* INVALID_INPUT */
|
|
6217
7349
|
);
|
|
6218
7350
|
}
|
|
6219
|
-
if (proposal.status !==
|
|
7351
|
+
if (proposal.status !== import_types16.ProposalStatus.PENDING) {
|
|
6220
7352
|
throw new ValidationError(
|
|
6221
7353
|
`proposal is not pending: ${proposal.status}`,
|
|
6222
7354
|
"proposalId",
|
|
@@ -6224,7 +7356,7 @@ var Treasury = class _Treasury {
|
|
|
6224
7356
|
"SIP_2001" /* INVALID_INPUT */
|
|
6225
7357
|
);
|
|
6226
7358
|
}
|
|
6227
|
-
proposal.status =
|
|
7359
|
+
proposal.status = import_types16.ProposalStatus.CANCELLED;
|
|
6228
7360
|
return proposal;
|
|
6229
7361
|
}
|
|
6230
7362
|
// ─── Auditor Access ──────────────────────────────────────────────────────────
|
|
@@ -6321,7 +7453,7 @@ var Treasury = class _Treasury {
|
|
|
6321
7453
|
getCommittedAmount(token) {
|
|
6322
7454
|
let committed = 0n;
|
|
6323
7455
|
for (const proposal of this.proposals.values()) {
|
|
6324
|
-
if (proposal.status !==
|
|
7456
|
+
if (proposal.status !== import_types16.ProposalStatus.PENDING) continue;
|
|
6325
7457
|
if (proposal.type === "payment" && proposal.payment) {
|
|
6326
7458
|
if (proposal.payment.token.symbol === token.symbol && proposal.payment.token.chain === token.chain) {
|
|
6327
7459
|
committed += proposal.payment.amount;
|
|
@@ -6372,12 +7504,12 @@ var Treasury = class _Treasury {
|
|
|
6372
7504
|
}
|
|
6373
7505
|
};
|
|
6374
7506
|
function generateTreasuryId() {
|
|
6375
|
-
const bytes = (0,
|
|
6376
|
-
return `treasury_${(0,
|
|
7507
|
+
const bytes = (0, import_utils13.randomBytes)(16);
|
|
7508
|
+
return `treasury_${(0, import_utils13.bytesToHex)(bytes)}`;
|
|
6377
7509
|
}
|
|
6378
7510
|
function generateProposalId() {
|
|
6379
|
-
const bytes = (0,
|
|
6380
|
-
return `prop_${(0,
|
|
7511
|
+
const bytes = (0, import_utils13.randomBytes)(16);
|
|
7512
|
+
return `prop_${(0, import_utils13.bytesToHex)(bytes)}`;
|
|
6381
7513
|
}
|
|
6382
7514
|
function computeProposalHash(proposal) {
|
|
6383
7515
|
const data = JSON.stringify({
|
|
@@ -6393,7 +7525,7 @@ function computeProposalHash(proposal) {
|
|
|
6393
7525
|
}
|
|
6394
7526
|
function signMessage(messageHash, privateKey) {
|
|
6395
7527
|
const keyHex = privateKey.startsWith("0x") ? privateKey.slice(2) : privateKey;
|
|
6396
|
-
const keyBytes = (0,
|
|
7528
|
+
const keyBytes = (0, import_utils13.hexToBytes)(keyHex);
|
|
6397
7529
|
try {
|
|
6398
7530
|
const signature = import_secp256k13.secp256k1.sign(messageHash, keyBytes);
|
|
6399
7531
|
return `0x${signature.toCompactHex()}`;
|
|
@@ -6405,8 +7537,8 @@ function verifySignature(messageHash, signature, publicKey) {
|
|
|
6405
7537
|
const sigHex = signature.startsWith("0x") ? signature.slice(2) : signature;
|
|
6406
7538
|
const pubKeyHex = publicKey.startsWith("0x") ? publicKey.slice(2) : publicKey;
|
|
6407
7539
|
try {
|
|
6408
|
-
const sigBytes = (0,
|
|
6409
|
-
const pubKeyBytes = (0,
|
|
7540
|
+
const sigBytes = (0, import_utils13.hexToBytes)(sigHex);
|
|
7541
|
+
const pubKeyBytes = (0, import_utils13.hexToBytes)(pubKeyHex);
|
|
6410
7542
|
return import_secp256k13.secp256k1.verify(sigBytes, messageHash, pubKeyBytes);
|
|
6411
7543
|
} catch {
|
|
6412
7544
|
return false;
|
|
@@ -6564,8 +7696,8 @@ function validateBatchProposalParams(params, config) {
|
|
|
6564
7696
|
}
|
|
6565
7697
|
|
|
6566
7698
|
// src/compliance/compliance-manager.ts
|
|
6567
|
-
var
|
|
6568
|
-
var
|
|
7699
|
+
var import_types17 = require("@sip-protocol/types");
|
|
7700
|
+
var import_utils14 = require("@noble/hashes/utils");
|
|
6569
7701
|
var DEFAULTS2 = {
|
|
6570
7702
|
riskThreshold: 70,
|
|
6571
7703
|
highValueThreshold: 10000000000n,
|
|
@@ -6932,7 +8064,7 @@ var ComplianceManager = class _ComplianceManager {
|
|
|
6932
8064
|
title: params.title,
|
|
6933
8065
|
description: params.description,
|
|
6934
8066
|
format: params.format,
|
|
6935
|
-
status:
|
|
8067
|
+
status: import_types17.ReportStatus.GENERATING,
|
|
6936
8068
|
requestedBy,
|
|
6937
8069
|
requestedAt: now,
|
|
6938
8070
|
startDate: params.startDate,
|
|
@@ -6961,10 +8093,10 @@ var ComplianceManager = class _ComplianceManager {
|
|
|
6961
8093
|
} else if (params.format === "csv") {
|
|
6962
8094
|
report.content = this.generateCSV(transactions);
|
|
6963
8095
|
}
|
|
6964
|
-
report.status =
|
|
8096
|
+
report.status = import_types17.ReportStatus.COMPLETED;
|
|
6965
8097
|
report.generatedAt = Math.floor(Date.now() / 1e3);
|
|
6966
8098
|
} catch (error) {
|
|
6967
|
-
report.status =
|
|
8099
|
+
report.status = import_types17.ReportStatus.FAILED;
|
|
6968
8100
|
report.error = error instanceof Error ? error.message : "Unknown error";
|
|
6969
8101
|
}
|
|
6970
8102
|
this.addAuditLog(requestedBy, "report_generated", {
|
|
@@ -7239,7 +8371,7 @@ var ComplianceManager = class _ComplianceManager {
|
|
|
7239
8371
|
}
|
|
7240
8372
|
};
|
|
7241
8373
|
function generateId(prefix) {
|
|
7242
|
-
return `${prefix}_${(0,
|
|
8374
|
+
return `${prefix}_${(0, import_utils14.bytesToHex)((0, import_utils14.randomBytes)(12))}`;
|
|
7243
8375
|
}
|
|
7244
8376
|
function validateRegisterAuditorParams(params) {
|
|
7245
8377
|
if (!params.organization?.trim()) {
|
|
@@ -7327,10 +8459,10 @@ function validateReportParams(params) {
|
|
|
7327
8459
|
}
|
|
7328
8460
|
|
|
7329
8461
|
// src/wallet/errors.ts
|
|
7330
|
-
var
|
|
8462
|
+
var import_types18 = require("@sip-protocol/types");
|
|
7331
8463
|
var WalletError = class extends SIPError {
|
|
7332
8464
|
walletCode;
|
|
7333
|
-
constructor(message, walletCode =
|
|
8465
|
+
constructor(message, walletCode = import_types18.WalletErrorCode.UNKNOWN, options) {
|
|
7334
8466
|
super(message, "SIP_7000" /* WALLET_ERROR */, options);
|
|
7335
8467
|
this.walletCode = walletCode;
|
|
7336
8468
|
this.name = "WalletError";
|
|
@@ -7340,10 +8472,10 @@ var WalletError = class extends SIPError {
|
|
|
7340
8472
|
*/
|
|
7341
8473
|
isConnectionError() {
|
|
7342
8474
|
const codes = [
|
|
7343
|
-
|
|
7344
|
-
|
|
7345
|
-
|
|
7346
|
-
|
|
8475
|
+
import_types18.WalletErrorCode.NOT_INSTALLED,
|
|
8476
|
+
import_types18.WalletErrorCode.CONNECTION_REJECTED,
|
|
8477
|
+
import_types18.WalletErrorCode.CONNECTION_FAILED,
|
|
8478
|
+
import_types18.WalletErrorCode.NOT_CONNECTED
|
|
7347
8479
|
];
|
|
7348
8480
|
return codes.includes(this.walletCode);
|
|
7349
8481
|
}
|
|
@@ -7352,9 +8484,9 @@ var WalletError = class extends SIPError {
|
|
|
7352
8484
|
*/
|
|
7353
8485
|
isSigningError() {
|
|
7354
8486
|
const codes = [
|
|
7355
|
-
|
|
7356
|
-
|
|
7357
|
-
|
|
8487
|
+
import_types18.WalletErrorCode.SIGNING_REJECTED,
|
|
8488
|
+
import_types18.WalletErrorCode.SIGNING_FAILED,
|
|
8489
|
+
import_types18.WalletErrorCode.INVALID_MESSAGE
|
|
7358
8490
|
];
|
|
7359
8491
|
return codes.includes(this.walletCode);
|
|
7360
8492
|
}
|
|
@@ -7363,10 +8495,10 @@ var WalletError = class extends SIPError {
|
|
|
7363
8495
|
*/
|
|
7364
8496
|
isTransactionError() {
|
|
7365
8497
|
const codes = [
|
|
7366
|
-
|
|
7367
|
-
|
|
7368
|
-
|
|
7369
|
-
|
|
8498
|
+
import_types18.WalletErrorCode.INSUFFICIENT_FUNDS,
|
|
8499
|
+
import_types18.WalletErrorCode.TRANSACTION_REJECTED,
|
|
8500
|
+
import_types18.WalletErrorCode.TRANSACTION_FAILED,
|
|
8501
|
+
import_types18.WalletErrorCode.INVALID_TRANSACTION
|
|
7370
8502
|
];
|
|
7371
8503
|
return codes.includes(this.walletCode);
|
|
7372
8504
|
}
|
|
@@ -7375,9 +8507,9 @@ var WalletError = class extends SIPError {
|
|
|
7375
8507
|
*/
|
|
7376
8508
|
isPrivacyError() {
|
|
7377
8509
|
const codes = [
|
|
7378
|
-
|
|
7379
|
-
|
|
7380
|
-
|
|
8510
|
+
import_types18.WalletErrorCode.STEALTH_NOT_SUPPORTED,
|
|
8511
|
+
import_types18.WalletErrorCode.VIEWING_KEY_NOT_SUPPORTED,
|
|
8512
|
+
import_types18.WalletErrorCode.SHIELDED_NOT_SUPPORTED
|
|
7381
8513
|
];
|
|
7382
8514
|
return codes.includes(this.walletCode);
|
|
7383
8515
|
}
|
|
@@ -7386,10 +8518,10 @@ var WalletError = class extends SIPError {
|
|
|
7386
8518
|
*/
|
|
7387
8519
|
isUserRejection() {
|
|
7388
8520
|
const codes = [
|
|
7389
|
-
|
|
7390
|
-
|
|
7391
|
-
|
|
7392
|
-
|
|
8521
|
+
import_types18.WalletErrorCode.CONNECTION_REJECTED,
|
|
8522
|
+
import_types18.WalletErrorCode.SIGNING_REJECTED,
|
|
8523
|
+
import_types18.WalletErrorCode.TRANSACTION_REJECTED,
|
|
8524
|
+
import_types18.WalletErrorCode.CHAIN_SWITCH_REJECTED
|
|
7393
8525
|
];
|
|
7394
8526
|
return codes.includes(this.walletCode);
|
|
7395
8527
|
}
|
|
@@ -7397,15 +8529,15 @@ var WalletError = class extends SIPError {
|
|
|
7397
8529
|
function notConnectedError() {
|
|
7398
8530
|
return new WalletError(
|
|
7399
8531
|
"Wallet not connected. Call connect() first.",
|
|
7400
|
-
|
|
8532
|
+
import_types18.WalletErrorCode.NOT_CONNECTED
|
|
7401
8533
|
);
|
|
7402
8534
|
}
|
|
7403
|
-
function featureNotSupportedError(feature, code =
|
|
8535
|
+
function featureNotSupportedError(feature, code = import_types18.WalletErrorCode.UNKNOWN) {
|
|
7404
8536
|
return new WalletError(`${feature} is not supported by this wallet`, code);
|
|
7405
8537
|
}
|
|
7406
8538
|
|
|
7407
8539
|
// src/wallet/base-adapter.ts
|
|
7408
|
-
var
|
|
8540
|
+
var import_types19 = require("@sip-protocol/types");
|
|
7409
8541
|
var BaseWalletAdapter = class {
|
|
7410
8542
|
_address = "";
|
|
7411
8543
|
_publicKey = "";
|
|
@@ -7568,12 +8700,12 @@ var MockWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7568
8700
|
this._connectionState = "connecting";
|
|
7569
8701
|
if (this.shouldFailConnect) {
|
|
7570
8702
|
this.setError(
|
|
7571
|
-
|
|
8703
|
+
import_types19.WalletErrorCode.CONNECTION_FAILED,
|
|
7572
8704
|
"Mock connection failure"
|
|
7573
8705
|
);
|
|
7574
8706
|
throw new WalletError(
|
|
7575
8707
|
"Mock connection failure",
|
|
7576
|
-
|
|
8708
|
+
import_types19.WalletErrorCode.CONNECTION_FAILED
|
|
7577
8709
|
);
|
|
7578
8710
|
}
|
|
7579
8711
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
@@ -7585,7 +8717,7 @@ var MockWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7585
8717
|
async signMessage(message) {
|
|
7586
8718
|
this.requireConnected();
|
|
7587
8719
|
if (this.shouldFailSign) {
|
|
7588
|
-
throw new WalletError("Mock signing failure",
|
|
8720
|
+
throw new WalletError("Mock signing failure", import_types19.WalletErrorCode.SIGNING_FAILED);
|
|
7589
8721
|
}
|
|
7590
8722
|
const mockSig = new Uint8Array(64);
|
|
7591
8723
|
for (let i = 0; i < 64; i++) {
|
|
@@ -7600,7 +8732,7 @@ var MockWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7600
8732
|
async signTransaction(tx) {
|
|
7601
8733
|
this.requireConnected();
|
|
7602
8734
|
if (this.shouldFailSign) {
|
|
7603
|
-
throw new WalletError("Mock signing failure",
|
|
8735
|
+
throw new WalletError("Mock signing failure", import_types19.WalletErrorCode.SIGNING_FAILED);
|
|
7604
8736
|
}
|
|
7605
8737
|
const signature = await this.signMessage(
|
|
7606
8738
|
new TextEncoder().encode(JSON.stringify(tx.data))
|
|
@@ -7782,7 +8914,7 @@ function isPrivateWalletAdapter(adapter) {
|
|
|
7782
8914
|
}
|
|
7783
8915
|
|
|
7784
8916
|
// src/wallet/solana/adapter.ts
|
|
7785
|
-
var
|
|
8917
|
+
var import_types20 = require("@sip-protocol/types");
|
|
7786
8918
|
|
|
7787
8919
|
// src/wallet/solana/types.ts
|
|
7788
8920
|
function getSolanaProvider(wallet = "phantom") {
|
|
@@ -7903,19 +9035,19 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7903
9035
|
}
|
|
7904
9036
|
if (!this.provider) {
|
|
7905
9037
|
this.setError(
|
|
7906
|
-
|
|
9038
|
+
import_types20.WalletErrorCode.NOT_INSTALLED,
|
|
7907
9039
|
`${this.walletName} wallet is not installed`
|
|
7908
9040
|
);
|
|
7909
9041
|
throw new WalletError(
|
|
7910
9042
|
`${this.walletName} wallet is not installed`,
|
|
7911
|
-
|
|
9043
|
+
import_types20.WalletErrorCode.NOT_INSTALLED
|
|
7912
9044
|
);
|
|
7913
9045
|
}
|
|
7914
9046
|
const { publicKey } = await this.provider.connect();
|
|
7915
9047
|
if (!publicKey) {
|
|
7916
9048
|
throw new WalletError(
|
|
7917
9049
|
"No public key returned from wallet",
|
|
7918
|
-
|
|
9050
|
+
import_types20.WalletErrorCode.CONNECTION_FAILED
|
|
7919
9051
|
);
|
|
7920
9052
|
}
|
|
7921
9053
|
this.setupEventHandlers();
|
|
@@ -7925,11 +9057,11 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7925
9057
|
} catch (error) {
|
|
7926
9058
|
const message = error instanceof Error ? error.message : "Connection failed";
|
|
7927
9059
|
if (message.includes("User rejected") || message.includes("rejected")) {
|
|
7928
|
-
this.setError(
|
|
7929
|
-
throw new WalletError(message,
|
|
9060
|
+
this.setError(import_types20.WalletErrorCode.CONNECTION_REJECTED, message);
|
|
9061
|
+
throw new WalletError(message, import_types20.WalletErrorCode.CONNECTION_REJECTED);
|
|
7930
9062
|
}
|
|
7931
|
-
this.setError(
|
|
7932
|
-
throw error instanceof WalletError ? error : new WalletError(message,
|
|
9063
|
+
this.setError(import_types20.WalletErrorCode.CONNECTION_FAILED, message);
|
|
9064
|
+
throw error instanceof WalletError ? error : new WalletError(message, import_types20.WalletErrorCode.CONNECTION_FAILED, { cause: error });
|
|
7933
9065
|
}
|
|
7934
9066
|
}
|
|
7935
9067
|
/**
|
|
@@ -7952,7 +9084,7 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7952
9084
|
async signMessage(message) {
|
|
7953
9085
|
this.requireConnected();
|
|
7954
9086
|
if (!this.provider) {
|
|
7955
|
-
throw new WalletError("Provider not available",
|
|
9087
|
+
throw new WalletError("Provider not available", import_types20.WalletErrorCode.NOT_CONNECTED);
|
|
7956
9088
|
}
|
|
7957
9089
|
try {
|
|
7958
9090
|
const { signature } = await this.provider.signMessage(message);
|
|
@@ -7963,9 +9095,9 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7963
9095
|
} catch (error) {
|
|
7964
9096
|
const message2 = error instanceof Error ? error.message : "Signing failed";
|
|
7965
9097
|
if (message2.includes("User rejected") || message2.includes("rejected")) {
|
|
7966
|
-
throw new WalletError(message2,
|
|
9098
|
+
throw new WalletError(message2, import_types20.WalletErrorCode.SIGNING_REJECTED);
|
|
7967
9099
|
}
|
|
7968
|
-
throw new WalletError(message2,
|
|
9100
|
+
throw new WalletError(message2, import_types20.WalletErrorCode.SIGNING_FAILED, {
|
|
7969
9101
|
cause: error
|
|
7970
9102
|
});
|
|
7971
9103
|
}
|
|
@@ -7978,7 +9110,7 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7978
9110
|
async signTransaction(tx) {
|
|
7979
9111
|
this.requireConnected();
|
|
7980
9112
|
if (!this.provider) {
|
|
7981
|
-
throw new WalletError("Provider not available",
|
|
9113
|
+
throw new WalletError("Provider not available", import_types20.WalletErrorCode.NOT_CONNECTED);
|
|
7982
9114
|
}
|
|
7983
9115
|
try {
|
|
7984
9116
|
const solTx = tx.data;
|
|
@@ -7997,9 +9129,9 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7997
9129
|
} catch (error) {
|
|
7998
9130
|
const message = error instanceof Error ? error.message : "Signing failed";
|
|
7999
9131
|
if (message.includes("User rejected") || message.includes("rejected")) {
|
|
8000
|
-
throw new WalletError(message,
|
|
9132
|
+
throw new WalletError(message, import_types20.WalletErrorCode.SIGNING_REJECTED);
|
|
8001
9133
|
}
|
|
8002
|
-
throw new WalletError(message,
|
|
9134
|
+
throw new WalletError(message, import_types20.WalletErrorCode.SIGNING_FAILED, {
|
|
8003
9135
|
cause: error
|
|
8004
9136
|
});
|
|
8005
9137
|
}
|
|
@@ -8010,7 +9142,7 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8010
9142
|
async signAndSendTransaction(tx) {
|
|
8011
9143
|
this.requireConnected();
|
|
8012
9144
|
if (!this.provider) {
|
|
8013
|
-
throw new WalletError("Provider not available",
|
|
9145
|
+
throw new WalletError("Provider not available", import_types20.WalletErrorCode.NOT_CONNECTED);
|
|
8014
9146
|
}
|
|
8015
9147
|
try {
|
|
8016
9148
|
const solTx = tx.data;
|
|
@@ -8025,12 +9157,12 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8025
9157
|
} catch (error) {
|
|
8026
9158
|
const message = error instanceof Error ? error.message : "Transaction failed";
|
|
8027
9159
|
if (message.includes("User rejected") || message.includes("rejected")) {
|
|
8028
|
-
throw new WalletError(message,
|
|
9160
|
+
throw new WalletError(message, import_types20.WalletErrorCode.TRANSACTION_REJECTED);
|
|
8029
9161
|
}
|
|
8030
9162
|
if (message.includes("insufficient") || message.includes("Insufficient")) {
|
|
8031
|
-
throw new WalletError(message,
|
|
9163
|
+
throw new WalletError(message, import_types20.WalletErrorCode.INSUFFICIENT_FUNDS);
|
|
8032
9164
|
}
|
|
8033
|
-
throw new WalletError(message,
|
|
9165
|
+
throw new WalletError(message, import_types20.WalletErrorCode.TRANSACTION_FAILED, {
|
|
8034
9166
|
cause: error
|
|
8035
9167
|
});
|
|
8036
9168
|
}
|
|
@@ -8043,16 +9175,16 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8043
9175
|
async signAllTransactions(transactions) {
|
|
8044
9176
|
this.requireConnected();
|
|
8045
9177
|
if (!this.provider) {
|
|
8046
|
-
throw new WalletError("Provider not available",
|
|
9178
|
+
throw new WalletError("Provider not available", import_types20.WalletErrorCode.NOT_CONNECTED);
|
|
8047
9179
|
}
|
|
8048
9180
|
try {
|
|
8049
9181
|
return await this.provider.signAllTransactions(transactions);
|
|
8050
9182
|
} catch (error) {
|
|
8051
9183
|
const message = error instanceof Error ? error.message : "Signing failed";
|
|
8052
9184
|
if (message.includes("User rejected") || message.includes("rejected")) {
|
|
8053
|
-
throw new WalletError(message,
|
|
9185
|
+
throw new WalletError(message, import_types20.WalletErrorCode.SIGNING_REJECTED);
|
|
8054
9186
|
}
|
|
8055
|
-
throw new WalletError(message,
|
|
9187
|
+
throw new WalletError(message, import_types20.WalletErrorCode.SIGNING_FAILED, {
|
|
8056
9188
|
cause: error
|
|
8057
9189
|
});
|
|
8058
9190
|
}
|
|
@@ -8073,7 +9205,7 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8073
9205
|
} catch (error) {
|
|
8074
9206
|
throw new WalletError(
|
|
8075
9207
|
"Failed to get balance",
|
|
8076
|
-
|
|
9208
|
+
import_types20.WalletErrorCode.UNKNOWN,
|
|
8077
9209
|
{ cause: error }
|
|
8078
9210
|
);
|
|
8079
9211
|
}
|
|
@@ -8086,7 +9218,7 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8086
9218
|
if (asset.chain !== "solana") {
|
|
8087
9219
|
throw new WalletError(
|
|
8088
9220
|
`Asset chain ${asset.chain} not supported by Solana adapter`,
|
|
8089
|
-
|
|
9221
|
+
import_types20.WalletErrorCode.UNSUPPORTED_CHAIN
|
|
8090
9222
|
);
|
|
8091
9223
|
}
|
|
8092
9224
|
if (!asset.address) {
|
|
@@ -8204,7 +9336,7 @@ function createSolanaAdapter(config = {}) {
|
|
|
8204
9336
|
}
|
|
8205
9337
|
|
|
8206
9338
|
// src/wallet/solana/mock.ts
|
|
8207
|
-
var
|
|
9339
|
+
var import_types22 = require("@sip-protocol/types");
|
|
8208
9340
|
var MockPublicKey = class {
|
|
8209
9341
|
base58;
|
|
8210
9342
|
bytes;
|
|
@@ -8270,8 +9402,8 @@ var MockSolanaAdapter = class extends BaseWalletAdapter {
|
|
|
8270
9402
|
this._connectionState = "connecting";
|
|
8271
9403
|
await this.simulateLatency();
|
|
8272
9404
|
if (this.shouldFailConnect) {
|
|
8273
|
-
this.setError(
|
|
8274
|
-
throw new WalletError("Mock connection failure",
|
|
9405
|
+
this.setError(import_types22.WalletErrorCode.CONNECTION_FAILED, "Mock connection failure");
|
|
9406
|
+
throw new WalletError("Mock connection failure", import_types22.WalletErrorCode.CONNECTION_FAILED);
|
|
8275
9407
|
}
|
|
8276
9408
|
const hexPubKey = "0x" + Buffer.from(this.mockPublicKey.toBytes()).toString("hex");
|
|
8277
9409
|
this.setConnected(this.mockAddress, hexPubKey);
|
|
@@ -8290,7 +9422,7 @@ var MockSolanaAdapter = class extends BaseWalletAdapter {
|
|
|
8290
9422
|
this.requireConnected();
|
|
8291
9423
|
await this.simulateLatency();
|
|
8292
9424
|
if (this.shouldFailSign) {
|
|
8293
|
-
throw new WalletError("Mock signing failure",
|
|
9425
|
+
throw new WalletError("Mock signing failure", import_types22.WalletErrorCode.SIGNING_REJECTED);
|
|
8294
9426
|
}
|
|
8295
9427
|
const mockSig = new Uint8Array(64);
|
|
8296
9428
|
for (let i = 0; i < 64; i++) {
|
|
@@ -8308,7 +9440,7 @@ var MockSolanaAdapter = class extends BaseWalletAdapter {
|
|
|
8308
9440
|
this.requireConnected();
|
|
8309
9441
|
await this.simulateLatency();
|
|
8310
9442
|
if (this.shouldFailSign) {
|
|
8311
|
-
throw new WalletError("Mock signing failure",
|
|
9443
|
+
throw new WalletError("Mock signing failure", import_types22.WalletErrorCode.SIGNING_REJECTED);
|
|
8312
9444
|
}
|
|
8313
9445
|
const solTx = tx.data;
|
|
8314
9446
|
this.signedTransactions.push(solTx);
|
|
@@ -8328,10 +9460,10 @@ var MockSolanaAdapter = class extends BaseWalletAdapter {
|
|
|
8328
9460
|
this.requireConnected();
|
|
8329
9461
|
await this.simulateLatency();
|
|
8330
9462
|
if (this.shouldFailSign) {
|
|
8331
|
-
throw new WalletError("Mock signing failure",
|
|
9463
|
+
throw new WalletError("Mock signing failure", import_types22.WalletErrorCode.SIGNING_REJECTED);
|
|
8332
9464
|
}
|
|
8333
9465
|
if (this.shouldFailTransaction) {
|
|
8334
|
-
throw new WalletError("Mock transaction failure",
|
|
9466
|
+
throw new WalletError("Mock transaction failure", import_types22.WalletErrorCode.TRANSACTION_FAILED);
|
|
8335
9467
|
}
|
|
8336
9468
|
const txSig = `mock_tx_${Date.now()}_${Math.random().toString(36).slice(2)}`;
|
|
8337
9469
|
this.sentTransactions.push(txSig);
|
|
@@ -8351,7 +9483,7 @@ var MockSolanaAdapter = class extends BaseWalletAdapter {
|
|
|
8351
9483
|
this.requireConnected();
|
|
8352
9484
|
await this.simulateLatency();
|
|
8353
9485
|
if (this.shouldFailSign) {
|
|
8354
|
-
throw new WalletError("Mock signing failure",
|
|
9486
|
+
throw new WalletError("Mock signing failure", import_types22.WalletErrorCode.SIGNING_REJECTED);
|
|
8355
9487
|
}
|
|
8356
9488
|
this.signedTransactions.push(...transactions);
|
|
8357
9489
|
return transactions.map((tx) => {
|
|
@@ -8378,7 +9510,7 @@ var MockSolanaAdapter = class extends BaseWalletAdapter {
|
|
|
8378
9510
|
if (asset.chain !== "solana") {
|
|
8379
9511
|
throw new WalletError(
|
|
8380
9512
|
`Asset chain ${asset.chain} not supported by Solana adapter`,
|
|
8381
|
-
|
|
9513
|
+
import_types22.WalletErrorCode.UNSUPPORTED_CHAIN
|
|
8382
9514
|
);
|
|
8383
9515
|
}
|
|
8384
9516
|
if (!asset.address) {
|
|
@@ -8547,7 +9679,7 @@ function createMockSolanaAdapter(config = {}) {
|
|
|
8547
9679
|
}
|
|
8548
9680
|
|
|
8549
9681
|
// src/wallet/ethereum/adapter.ts
|
|
8550
|
-
var
|
|
9682
|
+
var import_types24 = require("@sip-protocol/types");
|
|
8551
9683
|
|
|
8552
9684
|
// src/wallet/ethereum/types.ts
|
|
8553
9685
|
var EthereumChainId = {
|
|
@@ -8689,7 +9821,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8689
9821
|
this._connectionState = "error";
|
|
8690
9822
|
throw new WalletError(
|
|
8691
9823
|
`${this.walletType} wallet not found. Please install the extension.`,
|
|
8692
|
-
|
|
9824
|
+
import_types24.WalletErrorCode.NOT_INSTALLED
|
|
8693
9825
|
);
|
|
8694
9826
|
}
|
|
8695
9827
|
const accounts = await this.provider.request({
|
|
@@ -8699,7 +9831,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8699
9831
|
this._connectionState = "error";
|
|
8700
9832
|
throw new WalletError(
|
|
8701
9833
|
"No accounts returned from wallet",
|
|
8702
|
-
|
|
9834
|
+
import_types24.WalletErrorCode.CONNECTION_REJECTED
|
|
8703
9835
|
);
|
|
8704
9836
|
}
|
|
8705
9837
|
const address = normalizeAddress(accounts[0]);
|
|
@@ -8719,12 +9851,12 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8719
9851
|
if (rpcError.code === 4001) {
|
|
8720
9852
|
throw new WalletError(
|
|
8721
9853
|
"User rejected connection request",
|
|
8722
|
-
|
|
9854
|
+
import_types24.WalletErrorCode.CONNECTION_REJECTED
|
|
8723
9855
|
);
|
|
8724
9856
|
}
|
|
8725
9857
|
throw new WalletError(
|
|
8726
9858
|
`Failed to connect: ${rpcError.message || String(error)}`,
|
|
8727
|
-
|
|
9859
|
+
import_types24.WalletErrorCode.CONNECTION_FAILED
|
|
8728
9860
|
);
|
|
8729
9861
|
}
|
|
8730
9862
|
}
|
|
@@ -8744,7 +9876,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8744
9876
|
if (!this.provider) {
|
|
8745
9877
|
throw new WalletError(
|
|
8746
9878
|
"Provider not available",
|
|
8747
|
-
|
|
9879
|
+
import_types24.WalletErrorCode.NOT_CONNECTED
|
|
8748
9880
|
);
|
|
8749
9881
|
}
|
|
8750
9882
|
try {
|
|
@@ -8762,12 +9894,12 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8762
9894
|
if (rpcError.code === 4001) {
|
|
8763
9895
|
throw new WalletError(
|
|
8764
9896
|
"User rejected signing request",
|
|
8765
|
-
|
|
9897
|
+
import_types24.WalletErrorCode.SIGNING_REJECTED
|
|
8766
9898
|
);
|
|
8767
9899
|
}
|
|
8768
9900
|
throw new WalletError(
|
|
8769
9901
|
`Failed to sign message: ${rpcError.message || String(error)}`,
|
|
8770
|
-
|
|
9902
|
+
import_types24.WalletErrorCode.SIGNING_FAILED
|
|
8771
9903
|
);
|
|
8772
9904
|
}
|
|
8773
9905
|
}
|
|
@@ -8779,7 +9911,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8779
9911
|
if (!this.provider) {
|
|
8780
9912
|
throw new WalletError(
|
|
8781
9913
|
"Provider not available",
|
|
8782
|
-
|
|
9914
|
+
import_types24.WalletErrorCode.NOT_CONNECTED
|
|
8783
9915
|
);
|
|
8784
9916
|
}
|
|
8785
9917
|
try {
|
|
@@ -8796,12 +9928,12 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8796
9928
|
if (rpcError.code === 4001) {
|
|
8797
9929
|
throw new WalletError(
|
|
8798
9930
|
"User rejected signing request",
|
|
8799
|
-
|
|
9931
|
+
import_types24.WalletErrorCode.SIGNING_REJECTED
|
|
8800
9932
|
);
|
|
8801
9933
|
}
|
|
8802
9934
|
throw new WalletError(
|
|
8803
9935
|
`Failed to sign typed data: ${rpcError.message || String(error)}`,
|
|
8804
|
-
|
|
9936
|
+
import_types24.WalletErrorCode.SIGNING_FAILED
|
|
8805
9937
|
);
|
|
8806
9938
|
}
|
|
8807
9939
|
}
|
|
@@ -8813,7 +9945,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8813
9945
|
if (!this.provider) {
|
|
8814
9946
|
throw new WalletError(
|
|
8815
9947
|
"Provider not available",
|
|
8816
|
-
|
|
9948
|
+
import_types24.WalletErrorCode.NOT_CONNECTED
|
|
8817
9949
|
);
|
|
8818
9950
|
}
|
|
8819
9951
|
try {
|
|
@@ -8841,7 +9973,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8841
9973
|
if (rpcError.code === 4001) {
|
|
8842
9974
|
throw new WalletError(
|
|
8843
9975
|
"User rejected transaction signing",
|
|
8844
|
-
|
|
9976
|
+
import_types24.WalletErrorCode.SIGNING_REJECTED
|
|
8845
9977
|
);
|
|
8846
9978
|
}
|
|
8847
9979
|
if (rpcError.code === -32601 || rpcError.message?.includes("not supported")) {
|
|
@@ -8859,7 +9991,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8859
9991
|
}
|
|
8860
9992
|
throw new WalletError(
|
|
8861
9993
|
`Failed to sign transaction: ${rpcError.message || String(error)}`,
|
|
8862
|
-
|
|
9994
|
+
import_types24.WalletErrorCode.TRANSACTION_FAILED
|
|
8863
9995
|
);
|
|
8864
9996
|
}
|
|
8865
9997
|
}
|
|
@@ -8871,7 +10003,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8871
10003
|
if (!this.provider) {
|
|
8872
10004
|
throw new WalletError(
|
|
8873
10005
|
"Provider not available",
|
|
8874
|
-
|
|
10006
|
+
import_types24.WalletErrorCode.NOT_CONNECTED
|
|
8875
10007
|
);
|
|
8876
10008
|
}
|
|
8877
10009
|
try {
|
|
@@ -8893,12 +10025,12 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8893
10025
|
if (rpcError.code === 4001) {
|
|
8894
10026
|
throw new WalletError(
|
|
8895
10027
|
"User rejected transaction",
|
|
8896
|
-
|
|
10028
|
+
import_types24.WalletErrorCode.TRANSACTION_REJECTED
|
|
8897
10029
|
);
|
|
8898
10030
|
}
|
|
8899
10031
|
throw new WalletError(
|
|
8900
10032
|
`Failed to send transaction: ${rpcError.message || String(error)}`,
|
|
8901
|
-
|
|
10033
|
+
import_types24.WalletErrorCode.TRANSACTION_FAILED
|
|
8902
10034
|
);
|
|
8903
10035
|
}
|
|
8904
10036
|
}
|
|
@@ -8933,7 +10065,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8933
10065
|
} catch (error) {
|
|
8934
10066
|
throw new WalletError(
|
|
8935
10067
|
`Failed to fetch balance: ${String(error)}`,
|
|
8936
|
-
|
|
10068
|
+
import_types24.WalletErrorCode.UNKNOWN
|
|
8937
10069
|
);
|
|
8938
10070
|
}
|
|
8939
10071
|
}
|
|
@@ -8945,7 +10077,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8945
10077
|
if (asset.chain !== "ethereum") {
|
|
8946
10078
|
throw new WalletError(
|
|
8947
10079
|
`Asset chain ${asset.chain} not supported by Ethereum adapter`,
|
|
8948
|
-
|
|
10080
|
+
import_types24.WalletErrorCode.UNSUPPORTED_CHAIN
|
|
8949
10081
|
);
|
|
8950
10082
|
}
|
|
8951
10083
|
if (!asset.address) {
|
|
@@ -8970,7 +10102,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8970
10102
|
} catch (error) {
|
|
8971
10103
|
throw new WalletError(
|
|
8972
10104
|
`Failed to fetch token balance: ${String(error)}`,
|
|
8973
|
-
|
|
10105
|
+
import_types24.WalletErrorCode.UNKNOWN
|
|
8974
10106
|
);
|
|
8975
10107
|
}
|
|
8976
10108
|
}
|
|
@@ -8982,7 +10114,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8982
10114
|
if (!this.provider) {
|
|
8983
10115
|
throw new WalletError(
|
|
8984
10116
|
"Provider not available",
|
|
8985
|
-
|
|
10117
|
+
import_types24.WalletErrorCode.NOT_CONNECTED
|
|
8986
10118
|
);
|
|
8987
10119
|
}
|
|
8988
10120
|
try {
|
|
@@ -8997,18 +10129,18 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8997
10129
|
if (rpcError.code === 4001) {
|
|
8998
10130
|
throw new WalletError(
|
|
8999
10131
|
"User rejected chain switch",
|
|
9000
|
-
|
|
10132
|
+
import_types24.WalletErrorCode.CHAIN_SWITCH_REJECTED
|
|
9001
10133
|
);
|
|
9002
10134
|
}
|
|
9003
10135
|
if (rpcError.code === 4902) {
|
|
9004
10136
|
throw new WalletError(
|
|
9005
10137
|
`Chain ${chainId} not added to wallet`,
|
|
9006
|
-
|
|
10138
|
+
import_types24.WalletErrorCode.UNSUPPORTED_CHAIN
|
|
9007
10139
|
);
|
|
9008
10140
|
}
|
|
9009
10141
|
throw new WalletError(
|
|
9010
10142
|
`Failed to switch chain: ${rpcError.message || String(error)}`,
|
|
9011
|
-
|
|
10143
|
+
import_types24.WalletErrorCode.CHAIN_SWITCH_FAILED
|
|
9012
10144
|
);
|
|
9013
10145
|
}
|
|
9014
10146
|
}
|
|
@@ -9044,7 +10176,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
9044
10176
|
}
|
|
9045
10177
|
throw new WalletError(
|
|
9046
10178
|
`Transaction ${txHash} not confirmed after ${maxAttempts * 5} seconds`,
|
|
9047
|
-
|
|
10179
|
+
import_types24.WalletErrorCode.TRANSACTION_FAILED
|
|
9048
10180
|
);
|
|
9049
10181
|
}
|
|
9050
10182
|
/**
|
|
@@ -9118,7 +10250,7 @@ function createEthereumAdapter(config) {
|
|
|
9118
10250
|
}
|
|
9119
10251
|
|
|
9120
10252
|
// src/wallet/ethereum/mock.ts
|
|
9121
|
-
var
|
|
10253
|
+
var import_types26 = require("@sip-protocol/types");
|
|
9122
10254
|
var MockEthereumAdapter = class extends BaseWalletAdapter {
|
|
9123
10255
|
chain = "ethereum";
|
|
9124
10256
|
name = "mock-ethereum";
|
|
@@ -9159,7 +10291,7 @@ var MockEthereumAdapter = class extends BaseWalletAdapter {
|
|
|
9159
10291
|
this._connectionState = "error";
|
|
9160
10292
|
throw new WalletError(
|
|
9161
10293
|
"Mock connection rejected",
|
|
9162
|
-
|
|
10294
|
+
import_types26.WalletErrorCode.CONNECTION_REJECTED
|
|
9163
10295
|
);
|
|
9164
10296
|
}
|
|
9165
10297
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
@@ -9171,7 +10303,7 @@ var MockEthereumAdapter = class extends BaseWalletAdapter {
|
|
|
9171
10303
|
this._connectionState = "error";
|
|
9172
10304
|
throw new WalletError(
|
|
9173
10305
|
`Mock connection failed: ${String(error)}`,
|
|
9174
|
-
|
|
10306
|
+
import_types26.WalletErrorCode.CONNECTION_FAILED
|
|
9175
10307
|
);
|
|
9176
10308
|
}
|
|
9177
10309
|
}
|
|
@@ -9189,7 +10321,7 @@ var MockEthereumAdapter = class extends BaseWalletAdapter {
|
|
|
9189
10321
|
if (this._shouldFailSign) {
|
|
9190
10322
|
throw new WalletError(
|
|
9191
10323
|
"Mock signing rejected",
|
|
9192
|
-
|
|
10324
|
+
import_types26.WalletErrorCode.SIGNING_REJECTED
|
|
9193
10325
|
);
|
|
9194
10326
|
}
|
|
9195
10327
|
const msgHex = Buffer.from(message).toString("hex");
|
|
@@ -9207,7 +10339,7 @@ var MockEthereumAdapter = class extends BaseWalletAdapter {
|
|
|
9207
10339
|
if (this._shouldFailSign) {
|
|
9208
10340
|
throw new WalletError(
|
|
9209
10341
|
"Mock signing rejected",
|
|
9210
|
-
|
|
10342
|
+
import_types26.WalletErrorCode.SIGNING_REJECTED
|
|
9211
10343
|
);
|
|
9212
10344
|
}
|
|
9213
10345
|
const mockSig = `0x${"1".repeat(130)}`;
|
|
@@ -9224,7 +10356,7 @@ var MockEthereumAdapter = class extends BaseWalletAdapter {
|
|
|
9224
10356
|
if (this._shouldFailSign) {
|
|
9225
10357
|
throw new WalletError(
|
|
9226
10358
|
"Mock signing rejected",
|
|
9227
|
-
|
|
10359
|
+
import_types26.WalletErrorCode.SIGNING_REJECTED
|
|
9228
10360
|
);
|
|
9229
10361
|
}
|
|
9230
10362
|
this._signedTransactions.push(tx);
|
|
@@ -9249,7 +10381,7 @@ var MockEthereumAdapter = class extends BaseWalletAdapter {
|
|
|
9249
10381
|
if (this._shouldFailTransaction) {
|
|
9250
10382
|
throw new WalletError(
|
|
9251
10383
|
"Mock transaction failed",
|
|
9252
|
-
|
|
10384
|
+
import_types26.WalletErrorCode.TRANSACTION_FAILED
|
|
9253
10385
|
);
|
|
9254
10386
|
}
|
|
9255
10387
|
this._signedTransactions.push(tx);
|
|
@@ -9279,7 +10411,7 @@ var MockEthereumAdapter = class extends BaseWalletAdapter {
|
|
|
9279
10411
|
if (asset.chain !== "ethereum") {
|
|
9280
10412
|
throw new WalletError(
|
|
9281
10413
|
`Asset chain ${asset.chain} not supported by Ethereum adapter`,
|
|
9282
|
-
|
|
10414
|
+
import_types26.WalletErrorCode.UNSUPPORTED_CHAIN
|
|
9283
10415
|
);
|
|
9284
10416
|
}
|
|
9285
10417
|
if (!asset.address) {
|
|
@@ -9558,7 +10690,7 @@ function getAvailableTransports() {
|
|
|
9558
10690
|
}
|
|
9559
10691
|
|
|
9560
10692
|
// src/wallet/hardware/ledger.ts
|
|
9561
|
-
var
|
|
10693
|
+
var import_types29 = require("@sip-protocol/types");
|
|
9562
10694
|
var LedgerWalletAdapter = class extends BaseWalletAdapter {
|
|
9563
10695
|
chain;
|
|
9564
10696
|
name = "ledger";
|
|
@@ -9711,7 +10843,7 @@ var LedgerWalletAdapter = class extends BaseWalletAdapter {
|
|
|
9711
10843
|
async getBalance() {
|
|
9712
10844
|
throw new WalletError(
|
|
9713
10845
|
"Hardware wallets do not track balances. Use an RPC provider.",
|
|
9714
|
-
|
|
10846
|
+
import_types29.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
9715
10847
|
);
|
|
9716
10848
|
}
|
|
9717
10849
|
/**
|
|
@@ -9722,7 +10854,7 @@ var LedgerWalletAdapter = class extends BaseWalletAdapter {
|
|
|
9722
10854
|
async getTokenBalance(_asset) {
|
|
9723
10855
|
throw new WalletError(
|
|
9724
10856
|
"Hardware wallets do not track balances. Use an RPC provider.",
|
|
9725
|
-
|
|
10857
|
+
import_types29.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
9726
10858
|
);
|
|
9727
10859
|
}
|
|
9728
10860
|
// ─── Account Management ─────────────────────────────────────────────────────
|
|
@@ -10010,7 +11142,7 @@ function createLedgerAdapter(config) {
|
|
|
10010
11142
|
}
|
|
10011
11143
|
|
|
10012
11144
|
// src/wallet/hardware/trezor.ts
|
|
10013
|
-
var
|
|
11145
|
+
var import_types31 = require("@sip-protocol/types");
|
|
10014
11146
|
var TrezorWalletAdapter = class extends BaseWalletAdapter {
|
|
10015
11147
|
chain;
|
|
10016
11148
|
name = "trezor";
|
|
@@ -10156,7 +11288,7 @@ var TrezorWalletAdapter = class extends BaseWalletAdapter {
|
|
|
10156
11288
|
async getBalance() {
|
|
10157
11289
|
throw new WalletError(
|
|
10158
11290
|
"Hardware wallets do not track balances. Use an RPC provider.",
|
|
10159
|
-
|
|
11291
|
+
import_types31.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
10160
11292
|
);
|
|
10161
11293
|
}
|
|
10162
11294
|
/**
|
|
@@ -10167,7 +11299,7 @@ var TrezorWalletAdapter = class extends BaseWalletAdapter {
|
|
|
10167
11299
|
async getTokenBalance(_asset) {
|
|
10168
11300
|
throw new WalletError(
|
|
10169
11301
|
"Hardware wallets do not track balances. Use an RPC provider.",
|
|
10170
|
-
|
|
11302
|
+
import_types31.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
10171
11303
|
);
|
|
10172
11304
|
}
|
|
10173
11305
|
// ─── Account Management ─────────────────────────────────────────────────────
|
|
@@ -10448,8 +11580,8 @@ function createTrezorAdapter(config) {
|
|
|
10448
11580
|
}
|
|
10449
11581
|
|
|
10450
11582
|
// src/wallet/hardware/mock.ts
|
|
10451
|
-
var
|
|
10452
|
-
var
|
|
11583
|
+
var import_types33 = require("@sip-protocol/types");
|
|
11584
|
+
var import_utils15 = require("@noble/hashes/utils");
|
|
10453
11585
|
var MockLedgerAdapter = class extends BaseWalletAdapter {
|
|
10454
11586
|
chain;
|
|
10455
11587
|
name = "mock-ledger";
|
|
@@ -10596,7 +11728,7 @@ var MockLedgerAdapter = class extends BaseWalletAdapter {
|
|
|
10596
11728
|
async getBalance() {
|
|
10597
11729
|
throw new WalletError(
|
|
10598
11730
|
"Hardware wallets do not track balances",
|
|
10599
|
-
|
|
11731
|
+
import_types33.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
10600
11732
|
);
|
|
10601
11733
|
}
|
|
10602
11734
|
/**
|
|
@@ -10605,7 +11737,7 @@ var MockLedgerAdapter = class extends BaseWalletAdapter {
|
|
|
10605
11737
|
async getTokenBalance(_asset) {
|
|
10606
11738
|
throw new WalletError(
|
|
10607
11739
|
"Hardware wallets do not track balances",
|
|
10608
|
-
|
|
11740
|
+
import_types33.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
10609
11741
|
);
|
|
10610
11742
|
}
|
|
10611
11743
|
/**
|
|
@@ -10694,15 +11826,15 @@ var MockLedgerAdapter = class extends BaseWalletAdapter {
|
|
|
10694
11826
|
}
|
|
10695
11827
|
}
|
|
10696
11828
|
generateMockAddress(index) {
|
|
10697
|
-
const bytes = (0,
|
|
11829
|
+
const bytes = (0, import_utils15.randomBytes)(20);
|
|
10698
11830
|
bytes[0] = index;
|
|
10699
|
-
return `0x${(0,
|
|
11831
|
+
return `0x${(0, import_utils15.bytesToHex)(bytes)}`;
|
|
10700
11832
|
}
|
|
10701
11833
|
generateMockPublicKey(index) {
|
|
10702
|
-
const bytes = (0,
|
|
11834
|
+
const bytes = (0, import_utils15.randomBytes)(33);
|
|
10703
11835
|
bytes[0] = 2;
|
|
10704
11836
|
bytes[1] = index;
|
|
10705
|
-
return `0x${(0,
|
|
11837
|
+
return `0x${(0, import_utils15.bytesToHex)(bytes)}`;
|
|
10706
11838
|
}
|
|
10707
11839
|
generateMockSignature(data) {
|
|
10708
11840
|
const sig = new Uint8Array(65);
|
|
@@ -10711,7 +11843,7 @@ var MockLedgerAdapter = class extends BaseWalletAdapter {
|
|
|
10711
11843
|
sig[32 + i] = (data[i % data.length] ?? 0) ^ i * 11;
|
|
10712
11844
|
}
|
|
10713
11845
|
sig[64] = 27;
|
|
10714
|
-
return `0x${(0,
|
|
11846
|
+
return `0x${(0, import_utils15.bytesToHex)(sig)}`;
|
|
10715
11847
|
}
|
|
10716
11848
|
delay(ms) {
|
|
10717
11849
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -10835,13 +11967,13 @@ var MockTrezorAdapter = class extends BaseWalletAdapter {
|
|
|
10835
11967
|
async getBalance() {
|
|
10836
11968
|
throw new WalletError(
|
|
10837
11969
|
"Hardware wallets do not track balances",
|
|
10838
|
-
|
|
11970
|
+
import_types33.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
10839
11971
|
);
|
|
10840
11972
|
}
|
|
10841
11973
|
async getTokenBalance(_asset) {
|
|
10842
11974
|
throw new WalletError(
|
|
10843
11975
|
"Hardware wallets do not track balances",
|
|
10844
|
-
|
|
11976
|
+
import_types33.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
10845
11977
|
);
|
|
10846
11978
|
}
|
|
10847
11979
|
async getAccounts(startIndex = 0, count = 5) {
|
|
@@ -10900,15 +12032,15 @@ var MockTrezorAdapter = class extends BaseWalletAdapter {
|
|
|
10900
12032
|
}
|
|
10901
12033
|
}
|
|
10902
12034
|
generateMockAddress(index) {
|
|
10903
|
-
const bytes = (0,
|
|
12035
|
+
const bytes = (0, import_utils15.randomBytes)(20);
|
|
10904
12036
|
bytes[0] = index + 100;
|
|
10905
|
-
return `0x${(0,
|
|
12037
|
+
return `0x${(0, import_utils15.bytesToHex)(bytes)}`;
|
|
10906
12038
|
}
|
|
10907
12039
|
generateMockPublicKey(index) {
|
|
10908
|
-
const bytes = (0,
|
|
12040
|
+
const bytes = (0, import_utils15.randomBytes)(33);
|
|
10909
12041
|
bytes[0] = 3;
|
|
10910
12042
|
bytes[1] = index + 100;
|
|
10911
|
-
return `0x${(0,
|
|
12043
|
+
return `0x${(0, import_utils15.bytesToHex)(bytes)}`;
|
|
10912
12044
|
}
|
|
10913
12045
|
generateMockSignature(data) {
|
|
10914
12046
|
const sig = new Uint8Array(65);
|
|
@@ -10917,7 +12049,7 @@ var MockTrezorAdapter = class extends BaseWalletAdapter {
|
|
|
10917
12049
|
sig[32 + i] = (data[i % data.length] ?? 0) ^ i * 17;
|
|
10918
12050
|
}
|
|
10919
12051
|
sig[64] = 28;
|
|
10920
|
-
return `0x${(0,
|
|
12052
|
+
return `0x${(0, import_utils15.bytesToHex)(sig)}`;
|
|
10921
12053
|
}
|
|
10922
12054
|
delay(ms) {
|
|
10923
12055
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -10931,7 +12063,7 @@ function createMockTrezorAdapter(config) {
|
|
|
10931
12063
|
}
|
|
10932
12064
|
|
|
10933
12065
|
// src/wallet/index.ts
|
|
10934
|
-
var
|
|
12066
|
+
var import_types36 = require("@sip-protocol/types");
|
|
10935
12067
|
// Annotate the CommonJS export names for ESM import in node:
|
|
10936
12068
|
0 && (module.exports = {
|
|
10937
12069
|
ATTESTATION_VERSION,
|
|
@@ -10961,6 +12093,7 @@ var import_types33 = require("@sip-protocol/types");
|
|
|
10961
12093
|
MockWalletAdapter,
|
|
10962
12094
|
NATIVE_TOKENS,
|
|
10963
12095
|
NEARIntentsAdapter,
|
|
12096
|
+
NEARIntentsBackend,
|
|
10964
12097
|
NetworkError,
|
|
10965
12098
|
ORACLE_DOMAIN,
|
|
10966
12099
|
OneClickClient,
|
|
@@ -10982,13 +12115,18 @@ var import_types33 = require("@sip-protocol/types");
|
|
|
10982
12115
|
STABLECOIN_ADDRESSES,
|
|
10983
12116
|
STABLECOIN_DECIMALS,
|
|
10984
12117
|
STABLECOIN_INFO,
|
|
12118
|
+
SettlementRegistry,
|
|
12119
|
+
SettlementRegistryError,
|
|
12120
|
+
SmartRouter,
|
|
10985
12121
|
SolanaWalletAdapter,
|
|
12122
|
+
SwapStatus,
|
|
10986
12123
|
Treasury,
|
|
10987
12124
|
TrezorWalletAdapter,
|
|
10988
12125
|
ValidationError,
|
|
10989
12126
|
WalletError,
|
|
10990
12127
|
WalletErrorCode,
|
|
10991
12128
|
ZcashErrorCode,
|
|
12129
|
+
ZcashNativeBackend,
|
|
10992
12130
|
ZcashRPCClient,
|
|
10993
12131
|
ZcashRPCError,
|
|
10994
12132
|
ZcashShieldedService,
|
|
@@ -11017,15 +12155,18 @@ var import_types33 = require("@sip-protocol/types");
|
|
|
11017
12155
|
createMockSolver,
|
|
11018
12156
|
createMockTrezorAdapter,
|
|
11019
12157
|
createNEARIntentsAdapter,
|
|
12158
|
+
createNEARIntentsBackend,
|
|
11020
12159
|
createOracleRegistry,
|
|
11021
12160
|
createProductionSIP,
|
|
11022
12161
|
createSIP,
|
|
11023
12162
|
createShieldedIntent,
|
|
11024
12163
|
createShieldedPayment,
|
|
12164
|
+
createSmartRouter,
|
|
11025
12165
|
createSolanaAdapter,
|
|
11026
12166
|
createTrezorAdapter,
|
|
11027
12167
|
createWalletFactory,
|
|
11028
12168
|
createZcashClient,
|
|
12169
|
+
createZcashNativeBackend,
|
|
11029
12170
|
createZcashShieldedService,
|
|
11030
12171
|
createZcashSwapService,
|
|
11031
12172
|
decodeStealthMetaAddress,
|