@sip-protocol/sdk 0.2.10 → 0.3.0
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 +1334 -199
- package/dist/browser.mjs +19 -1
- 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/index-Ba7njCU3.d.ts +6925 -0
- package/dist/index-Co26-vbG.d.mts +6925 -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 +1334 -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/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/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,
|
|
@@ -4914,7 +6040,7 @@ var ZcashSwapService = class {
|
|
|
4914
6040
|
validUntil,
|
|
4915
6041
|
depositAddress: this.generateMockDepositAddress(sourceChain),
|
|
4916
6042
|
estimatedTime: this.getEstimatedTime(sourceChain),
|
|
4917
|
-
privacyLevel:
|
|
6043
|
+
privacyLevel: import_types13.PrivacyLevel.SHIELDED
|
|
4918
6044
|
};
|
|
4919
6045
|
this.quotes.set(quoteId, quote);
|
|
4920
6046
|
return quote;
|
|
@@ -4957,7 +6083,7 @@ var ZcashSwapService = class {
|
|
|
4957
6083
|
depositAddress: "",
|
|
4958
6084
|
// Will be set by bridge
|
|
4959
6085
|
estimatedTime: this.getEstimatedTime(params.sourceChain),
|
|
4960
|
-
privacyLevel:
|
|
6086
|
+
privacyLevel: import_types13.PrivacyLevel.SHIELDED
|
|
4961
6087
|
};
|
|
4962
6088
|
this.quotes.set(quote.quoteId, quote);
|
|
4963
6089
|
return quote;
|
|
@@ -5237,15 +6363,15 @@ function createZcashSwapService(config) {
|
|
|
5237
6363
|
}
|
|
5238
6364
|
|
|
5239
6365
|
// src/zcash/index.ts
|
|
5240
|
-
var
|
|
6366
|
+
var import_types14 = require("@sip-protocol/types");
|
|
5241
6367
|
|
|
5242
6368
|
// src/index.ts
|
|
5243
|
-
var
|
|
6369
|
+
var import_types42 = require("@sip-protocol/types");
|
|
5244
6370
|
|
|
5245
6371
|
// src/payment/payment.ts
|
|
5246
|
-
var
|
|
6372
|
+
var import_types15 = require("@sip-protocol/types");
|
|
5247
6373
|
var import_sha2569 = require("@noble/hashes/sha256");
|
|
5248
|
-
var
|
|
6374
|
+
var import_utils12 = require("@noble/hashes/utils");
|
|
5249
6375
|
var import_chacha2 = require("@noble/ciphers/chacha.js");
|
|
5250
6376
|
var import_hkdf2 = require("@noble/hashes/hkdf");
|
|
5251
6377
|
|
|
@@ -5430,7 +6556,7 @@ var PaymentBuilder = class {
|
|
|
5430
6556
|
_amount;
|
|
5431
6557
|
_recipientMetaAddress;
|
|
5432
6558
|
_recipientAddress;
|
|
5433
|
-
_privacy =
|
|
6559
|
+
_privacy = import_types15.PrivacyLevel.SHIELDED;
|
|
5434
6560
|
_viewingKey;
|
|
5435
6561
|
_sourceChain;
|
|
5436
6562
|
_destinationChain;
|
|
@@ -5713,7 +6839,7 @@ async function createShieldedPayment(params, options) {
|
|
|
5713
6839
|
} else {
|
|
5714
6840
|
resolvedToken = token;
|
|
5715
6841
|
}
|
|
5716
|
-
if (privacy !==
|
|
6842
|
+
if (privacy !== import_types15.PrivacyLevel.TRANSPARENT && !recipientMetaAddress) {
|
|
5717
6843
|
throw new ValidationError(
|
|
5718
6844
|
"recipientMetaAddress is required for shielded/compliant privacy modes",
|
|
5719
6845
|
"recipientMetaAddress",
|
|
@@ -5721,7 +6847,7 @@ async function createShieldedPayment(params, options) {
|
|
|
5721
6847
|
"SIP_2008" /* MISSING_REQUIRED */
|
|
5722
6848
|
);
|
|
5723
6849
|
}
|
|
5724
|
-
if (privacy ===
|
|
6850
|
+
if (privacy === import_types15.PrivacyLevel.TRANSPARENT && !recipientAddress) {
|
|
5725
6851
|
throw new ValidationError(
|
|
5726
6852
|
"recipientAddress is required for transparent mode",
|
|
5727
6853
|
"recipientAddress",
|
|
@@ -5729,7 +6855,7 @@ async function createShieldedPayment(params, options) {
|
|
|
5729
6855
|
"SIP_2008" /* MISSING_REQUIRED */
|
|
5730
6856
|
);
|
|
5731
6857
|
}
|
|
5732
|
-
if (privacy ===
|
|
6858
|
+
if (privacy === import_types15.PrivacyLevel.COMPLIANT && !viewingKey) {
|
|
5733
6859
|
throw new ValidationError(
|
|
5734
6860
|
"viewingKey is required for compliant mode",
|
|
5735
6861
|
"viewingKey",
|
|
@@ -5741,8 +6867,8 @@ async function createShieldedPayment(params, options) {
|
|
|
5741
6867
|
let viewingKeyHash;
|
|
5742
6868
|
if (viewingKey) {
|
|
5743
6869
|
const keyHex = viewingKey.startsWith("0x") ? viewingKey.slice(2) : viewingKey;
|
|
5744
|
-
const keyBytes = (0,
|
|
5745
|
-
viewingKeyHash = `0x${(0,
|
|
6870
|
+
const keyBytes = (0, import_utils12.hexToBytes)(keyHex);
|
|
6871
|
+
viewingKeyHash = `0x${(0, import_utils12.bytesToHex)((0, import_sha2569.sha256)(keyBytes))}`;
|
|
5746
6872
|
}
|
|
5747
6873
|
const privacyConfig = getPrivacyConfig(
|
|
5748
6874
|
privacy,
|
|
@@ -5751,7 +6877,7 @@ async function createShieldedPayment(params, options) {
|
|
|
5751
6877
|
const now = Math.floor(Date.now() / 1e3);
|
|
5752
6878
|
const payment = {
|
|
5753
6879
|
paymentId,
|
|
5754
|
-
version:
|
|
6880
|
+
version: import_types15.SIP_VERSION,
|
|
5755
6881
|
privacyLevel: privacy,
|
|
5756
6882
|
createdAt: now,
|
|
5757
6883
|
expiry: now + ttl,
|
|
@@ -5762,7 +6888,7 @@ async function createShieldedPayment(params, options) {
|
|
|
5762
6888
|
purpose,
|
|
5763
6889
|
viewingKeyHash
|
|
5764
6890
|
};
|
|
5765
|
-
if (privacy !==
|
|
6891
|
+
if (privacy !== import_types15.PrivacyLevel.TRANSPARENT && recipientMetaAddress) {
|
|
5766
6892
|
const metaAddress = decodeStealthMetaAddress(recipientMetaAddress);
|
|
5767
6893
|
const { stealthAddress } = generateStealthAddress(metaAddress);
|
|
5768
6894
|
payment.recipientStealth = stealthAddress;
|
|
@@ -5779,10 +6905,10 @@ async function createShieldedPayment(params, options) {
|
|
|
5779
6905
|
payment.recipientAddress = recipientAddress;
|
|
5780
6906
|
payment.memo = memo;
|
|
5781
6907
|
}
|
|
5782
|
-
if (privacy !==
|
|
6908
|
+
if (privacy !== import_types15.PrivacyLevel.TRANSPARENT && proofProvider?.isReady) {
|
|
5783
6909
|
const hexToUint8 = (hex) => {
|
|
5784
6910
|
const cleanHex = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
5785
|
-
return (0,
|
|
6911
|
+
return (0, import_utils12.hexToBytes)(cleanHex);
|
|
5786
6912
|
};
|
|
5787
6913
|
const fundingResult = await proofProvider.generateFundingProof({
|
|
5788
6914
|
balance: amount,
|
|
@@ -5809,17 +6935,17 @@ async function createShieldedPayment(params, options) {
|
|
|
5809
6935
|
}
|
|
5810
6936
|
function encryptMemo(memo, viewingKey) {
|
|
5811
6937
|
const keyHex = viewingKey.startsWith("0x") ? viewingKey.slice(2) : viewingKey;
|
|
5812
|
-
const keyBytes = (0,
|
|
6938
|
+
const keyBytes = (0, import_utils12.hexToBytes)(keyHex);
|
|
5813
6939
|
const encKey = (0, import_hkdf2.hkdf)(import_sha2569.sha256, keyBytes, new Uint8Array(0), new Uint8Array(0), 32);
|
|
5814
6940
|
try {
|
|
5815
|
-
const nonce = (0,
|
|
6941
|
+
const nonce = (0, import_utils12.randomBytes)(24);
|
|
5816
6942
|
const cipher = (0, import_chacha2.xchacha20poly1305)(encKey, nonce);
|
|
5817
6943
|
const plaintext = new TextEncoder().encode(memo);
|
|
5818
6944
|
const ciphertext = cipher.encrypt(plaintext);
|
|
5819
6945
|
const result = new Uint8Array(nonce.length + ciphertext.length);
|
|
5820
6946
|
result.set(nonce);
|
|
5821
6947
|
result.set(ciphertext, nonce.length);
|
|
5822
|
-
return `0x${(0,
|
|
6948
|
+
return `0x${(0, import_utils12.bytesToHex)(result)}`;
|
|
5823
6949
|
} finally {
|
|
5824
6950
|
secureWipe(keyBytes);
|
|
5825
6951
|
secureWipe(encKey);
|
|
@@ -5827,11 +6953,11 @@ function encryptMemo(memo, viewingKey) {
|
|
|
5827
6953
|
}
|
|
5828
6954
|
function decryptMemo(encryptedMemo, viewingKey) {
|
|
5829
6955
|
const keyHex = viewingKey.startsWith("0x") ? viewingKey.slice(2) : viewingKey;
|
|
5830
|
-
const keyBytes = (0,
|
|
6956
|
+
const keyBytes = (0, import_utils12.hexToBytes)(keyHex);
|
|
5831
6957
|
const encKey = (0, import_hkdf2.hkdf)(import_sha2569.sha256, keyBytes, new Uint8Array(0), new Uint8Array(0), 32);
|
|
5832
6958
|
try {
|
|
5833
6959
|
const dataHex = encryptedMemo.startsWith("0x") ? encryptedMemo.slice(2) : encryptedMemo;
|
|
5834
|
-
const data = (0,
|
|
6960
|
+
const data = (0, import_utils12.hexToBytes)(dataHex);
|
|
5835
6961
|
const nonce = data.slice(0, 24);
|
|
5836
6962
|
const ciphertext = data.slice(24);
|
|
5837
6963
|
const cipher = (0, import_chacha2.xchacha20poly1305)(encKey, nonce);
|
|
@@ -5845,7 +6971,7 @@ function decryptMemo(encryptedMemo, viewingKey) {
|
|
|
5845
6971
|
function trackPayment(payment) {
|
|
5846
6972
|
return {
|
|
5847
6973
|
...payment,
|
|
5848
|
-
status:
|
|
6974
|
+
status: import_types15.PaymentStatus.DRAFT
|
|
5849
6975
|
};
|
|
5850
6976
|
}
|
|
5851
6977
|
function isPaymentExpired(payment) {
|
|
@@ -5878,10 +7004,10 @@ function getPaymentSummary(payment) {
|
|
|
5878
7004
|
}
|
|
5879
7005
|
|
|
5880
7006
|
// src/treasury/treasury.ts
|
|
5881
|
-
var
|
|
7007
|
+
var import_types16 = require("@sip-protocol/types");
|
|
5882
7008
|
var import_secp256k13 = require("@noble/curves/secp256k1");
|
|
5883
7009
|
var import_sha25610 = require("@noble/hashes/sha256");
|
|
5884
|
-
var
|
|
7010
|
+
var import_utils13 = require("@noble/hashes/utils");
|
|
5885
7011
|
var DEFAULT_PROPOSAL_TTL = 7 * 24 * 60 * 60;
|
|
5886
7012
|
var Treasury = class _Treasury {
|
|
5887
7013
|
config;
|
|
@@ -5911,7 +7037,7 @@ var Treasury = class _Treasury {
|
|
|
5911
7037
|
...m,
|
|
5912
7038
|
addedAt: now
|
|
5913
7039
|
})),
|
|
5914
|
-
defaultPrivacy: params.defaultPrivacy ??
|
|
7040
|
+
defaultPrivacy: params.defaultPrivacy ?? import_types16.PrivacyLevel.SHIELDED,
|
|
5915
7041
|
masterViewingKey,
|
|
5916
7042
|
dailyLimit: params.dailyLimit,
|
|
5917
7043
|
transactionLimit: params.transactionLimit,
|
|
@@ -5990,7 +7116,7 @@ var Treasury = class _Treasury {
|
|
|
5990
7116
|
proposalId,
|
|
5991
7117
|
treasuryId: this.config.treasuryId,
|
|
5992
7118
|
type: "payment",
|
|
5993
|
-
status:
|
|
7119
|
+
status: import_types16.ProposalStatus.PENDING,
|
|
5994
7120
|
proposer: "",
|
|
5995
7121
|
// Should be set by caller
|
|
5996
7122
|
title: params.title,
|
|
@@ -6023,7 +7149,7 @@ var Treasury = class _Treasury {
|
|
|
6023
7149
|
proposalId,
|
|
6024
7150
|
treasuryId: this.config.treasuryId,
|
|
6025
7151
|
type: "batch_payment",
|
|
6026
|
-
status:
|
|
7152
|
+
status: import_types16.ProposalStatus.PENDING,
|
|
6027
7153
|
proposer: "",
|
|
6028
7154
|
title: params.title,
|
|
6029
7155
|
description: params.description,
|
|
@@ -6057,7 +7183,7 @@ var Treasury = class _Treasury {
|
|
|
6057
7183
|
* Get pending proposals
|
|
6058
7184
|
*/
|
|
6059
7185
|
getPendingProposals() {
|
|
6060
|
-
return this.getAllProposals().filter((p) => p.status ===
|
|
7186
|
+
return this.getAllProposals().filter((p) => p.status === import_types16.ProposalStatus.PENDING);
|
|
6061
7187
|
}
|
|
6062
7188
|
/**
|
|
6063
7189
|
* Sign a proposal
|
|
@@ -6088,7 +7214,7 @@ var Treasury = class _Treasury {
|
|
|
6088
7214
|
"SIP_2001" /* INVALID_INPUT */
|
|
6089
7215
|
);
|
|
6090
7216
|
}
|
|
6091
|
-
if (proposal.status !==
|
|
7217
|
+
if (proposal.status !== import_types16.ProposalStatus.PENDING) {
|
|
6092
7218
|
throw new ValidationError(
|
|
6093
7219
|
`proposal is not pending: ${proposal.status}`,
|
|
6094
7220
|
"proposalId",
|
|
@@ -6098,7 +7224,7 @@ var Treasury = class _Treasury {
|
|
|
6098
7224
|
}
|
|
6099
7225
|
const now = Math.floor(Date.now() / 1e3);
|
|
6100
7226
|
if (now > proposal.expiresAt) {
|
|
6101
|
-
proposal.status =
|
|
7227
|
+
proposal.status = import_types16.ProposalStatus.EXPIRED;
|
|
6102
7228
|
throw new ValidationError(
|
|
6103
7229
|
"proposal has expired",
|
|
6104
7230
|
"proposalId",
|
|
@@ -6130,9 +7256,9 @@ var Treasury = class _Treasury {
|
|
|
6130
7256
|
const approvals = proposal.signatures.filter((s) => s.approved).length;
|
|
6131
7257
|
const rejections = proposal.signatures.filter((s) => !s.approved).length;
|
|
6132
7258
|
if (approvals >= proposal.requiredSignatures) {
|
|
6133
|
-
proposal.status =
|
|
7259
|
+
proposal.status = import_types16.ProposalStatus.APPROVED;
|
|
6134
7260
|
} else if (rejections > this.config.totalSigners - proposal.requiredSignatures) {
|
|
6135
|
-
proposal.status =
|
|
7261
|
+
proposal.status = import_types16.ProposalStatus.REJECTED;
|
|
6136
7262
|
}
|
|
6137
7263
|
return proposal;
|
|
6138
7264
|
}
|
|
@@ -6149,7 +7275,7 @@ var Treasury = class _Treasury {
|
|
|
6149
7275
|
"SIP_2001" /* INVALID_INPUT */
|
|
6150
7276
|
);
|
|
6151
7277
|
}
|
|
6152
|
-
if (proposal.status !==
|
|
7278
|
+
if (proposal.status !== import_types16.ProposalStatus.APPROVED) {
|
|
6153
7279
|
throw new ValidationError(
|
|
6154
7280
|
`proposal is not approved: ${proposal.status}`,
|
|
6155
7281
|
"proposalId",
|
|
@@ -6162,8 +7288,8 @@ var Treasury = class _Treasury {
|
|
|
6162
7288
|
const payment = await createShieldedPayment({
|
|
6163
7289
|
token: proposal.payment.token,
|
|
6164
7290
|
amount: proposal.payment.amount,
|
|
6165
|
-
recipientMetaAddress: proposal.payment.privacy !==
|
|
6166
|
-
recipientAddress: proposal.payment.privacy ===
|
|
7291
|
+
recipientMetaAddress: proposal.payment.privacy !== import_types16.PrivacyLevel.TRANSPARENT ? proposal.payment.recipient : void 0,
|
|
7292
|
+
recipientAddress: proposal.payment.privacy === import_types16.PrivacyLevel.TRANSPARENT ? proposal.payment.recipient : void 0,
|
|
6167
7293
|
privacy: proposal.payment.privacy,
|
|
6168
7294
|
viewingKey: this.config.masterViewingKey?.key,
|
|
6169
7295
|
sourceChain: this.config.chain,
|
|
@@ -6176,8 +7302,8 @@ var Treasury = class _Treasury {
|
|
|
6176
7302
|
const payment = await createShieldedPayment({
|
|
6177
7303
|
token: proposal.batchPayment.token,
|
|
6178
7304
|
amount: recipient.amount,
|
|
6179
|
-
recipientMetaAddress: proposal.batchPayment.privacy !==
|
|
6180
|
-
recipientAddress: proposal.batchPayment.privacy ===
|
|
7305
|
+
recipientMetaAddress: proposal.batchPayment.privacy !== import_types16.PrivacyLevel.TRANSPARENT ? recipient.address : void 0,
|
|
7306
|
+
recipientAddress: proposal.batchPayment.privacy === import_types16.PrivacyLevel.TRANSPARENT ? recipient.address : void 0,
|
|
6181
7307
|
privacy: proposal.batchPayment.privacy,
|
|
6182
7308
|
viewingKey: this.config.masterViewingKey?.key,
|
|
6183
7309
|
sourceChain: this.config.chain,
|
|
@@ -6187,7 +7313,7 @@ var Treasury = class _Treasury {
|
|
|
6187
7313
|
payments.push(payment);
|
|
6188
7314
|
}
|
|
6189
7315
|
}
|
|
6190
|
-
proposal.status =
|
|
7316
|
+
proposal.status = import_types16.ProposalStatus.EXECUTED;
|
|
6191
7317
|
proposal.executedAt = Math.floor(Date.now() / 1e3);
|
|
6192
7318
|
proposal.resultPayments = payments;
|
|
6193
7319
|
return payments;
|
|
@@ -6216,7 +7342,7 @@ var Treasury = class _Treasury {
|
|
|
6216
7342
|
"SIP_2001" /* INVALID_INPUT */
|
|
6217
7343
|
);
|
|
6218
7344
|
}
|
|
6219
|
-
if (proposal.status !==
|
|
7345
|
+
if (proposal.status !== import_types16.ProposalStatus.PENDING) {
|
|
6220
7346
|
throw new ValidationError(
|
|
6221
7347
|
`proposal is not pending: ${proposal.status}`,
|
|
6222
7348
|
"proposalId",
|
|
@@ -6224,7 +7350,7 @@ var Treasury = class _Treasury {
|
|
|
6224
7350
|
"SIP_2001" /* INVALID_INPUT */
|
|
6225
7351
|
);
|
|
6226
7352
|
}
|
|
6227
|
-
proposal.status =
|
|
7353
|
+
proposal.status = import_types16.ProposalStatus.CANCELLED;
|
|
6228
7354
|
return proposal;
|
|
6229
7355
|
}
|
|
6230
7356
|
// ─── Auditor Access ──────────────────────────────────────────────────────────
|
|
@@ -6321,7 +7447,7 @@ var Treasury = class _Treasury {
|
|
|
6321
7447
|
getCommittedAmount(token) {
|
|
6322
7448
|
let committed = 0n;
|
|
6323
7449
|
for (const proposal of this.proposals.values()) {
|
|
6324
|
-
if (proposal.status !==
|
|
7450
|
+
if (proposal.status !== import_types16.ProposalStatus.PENDING) continue;
|
|
6325
7451
|
if (proposal.type === "payment" && proposal.payment) {
|
|
6326
7452
|
if (proposal.payment.token.symbol === token.symbol && proposal.payment.token.chain === token.chain) {
|
|
6327
7453
|
committed += proposal.payment.amount;
|
|
@@ -6372,12 +7498,12 @@ var Treasury = class _Treasury {
|
|
|
6372
7498
|
}
|
|
6373
7499
|
};
|
|
6374
7500
|
function generateTreasuryId() {
|
|
6375
|
-
const bytes = (0,
|
|
6376
|
-
return `treasury_${(0,
|
|
7501
|
+
const bytes = (0, import_utils13.randomBytes)(16);
|
|
7502
|
+
return `treasury_${(0, import_utils13.bytesToHex)(bytes)}`;
|
|
6377
7503
|
}
|
|
6378
7504
|
function generateProposalId() {
|
|
6379
|
-
const bytes = (0,
|
|
6380
|
-
return `prop_${(0,
|
|
7505
|
+
const bytes = (0, import_utils13.randomBytes)(16);
|
|
7506
|
+
return `prop_${(0, import_utils13.bytesToHex)(bytes)}`;
|
|
6381
7507
|
}
|
|
6382
7508
|
function computeProposalHash(proposal) {
|
|
6383
7509
|
const data = JSON.stringify({
|
|
@@ -6393,7 +7519,7 @@ function computeProposalHash(proposal) {
|
|
|
6393
7519
|
}
|
|
6394
7520
|
function signMessage(messageHash, privateKey) {
|
|
6395
7521
|
const keyHex = privateKey.startsWith("0x") ? privateKey.slice(2) : privateKey;
|
|
6396
|
-
const keyBytes = (0,
|
|
7522
|
+
const keyBytes = (0, import_utils13.hexToBytes)(keyHex);
|
|
6397
7523
|
try {
|
|
6398
7524
|
const signature = import_secp256k13.secp256k1.sign(messageHash, keyBytes);
|
|
6399
7525
|
return `0x${signature.toCompactHex()}`;
|
|
@@ -6405,8 +7531,8 @@ function verifySignature(messageHash, signature, publicKey) {
|
|
|
6405
7531
|
const sigHex = signature.startsWith("0x") ? signature.slice(2) : signature;
|
|
6406
7532
|
const pubKeyHex = publicKey.startsWith("0x") ? publicKey.slice(2) : publicKey;
|
|
6407
7533
|
try {
|
|
6408
|
-
const sigBytes = (0,
|
|
6409
|
-
const pubKeyBytes = (0,
|
|
7534
|
+
const sigBytes = (0, import_utils13.hexToBytes)(sigHex);
|
|
7535
|
+
const pubKeyBytes = (0, import_utils13.hexToBytes)(pubKeyHex);
|
|
6410
7536
|
return import_secp256k13.secp256k1.verify(sigBytes, messageHash, pubKeyBytes);
|
|
6411
7537
|
} catch {
|
|
6412
7538
|
return false;
|
|
@@ -6564,8 +7690,8 @@ function validateBatchProposalParams(params, config) {
|
|
|
6564
7690
|
}
|
|
6565
7691
|
|
|
6566
7692
|
// src/compliance/compliance-manager.ts
|
|
6567
|
-
var
|
|
6568
|
-
var
|
|
7693
|
+
var import_types17 = require("@sip-protocol/types");
|
|
7694
|
+
var import_utils14 = require("@noble/hashes/utils");
|
|
6569
7695
|
var DEFAULTS2 = {
|
|
6570
7696
|
riskThreshold: 70,
|
|
6571
7697
|
highValueThreshold: 10000000000n,
|
|
@@ -6932,7 +8058,7 @@ var ComplianceManager = class _ComplianceManager {
|
|
|
6932
8058
|
title: params.title,
|
|
6933
8059
|
description: params.description,
|
|
6934
8060
|
format: params.format,
|
|
6935
|
-
status:
|
|
8061
|
+
status: import_types17.ReportStatus.GENERATING,
|
|
6936
8062
|
requestedBy,
|
|
6937
8063
|
requestedAt: now,
|
|
6938
8064
|
startDate: params.startDate,
|
|
@@ -6961,10 +8087,10 @@ var ComplianceManager = class _ComplianceManager {
|
|
|
6961
8087
|
} else if (params.format === "csv") {
|
|
6962
8088
|
report.content = this.generateCSV(transactions);
|
|
6963
8089
|
}
|
|
6964
|
-
report.status =
|
|
8090
|
+
report.status = import_types17.ReportStatus.COMPLETED;
|
|
6965
8091
|
report.generatedAt = Math.floor(Date.now() / 1e3);
|
|
6966
8092
|
} catch (error) {
|
|
6967
|
-
report.status =
|
|
8093
|
+
report.status = import_types17.ReportStatus.FAILED;
|
|
6968
8094
|
report.error = error instanceof Error ? error.message : "Unknown error";
|
|
6969
8095
|
}
|
|
6970
8096
|
this.addAuditLog(requestedBy, "report_generated", {
|
|
@@ -7239,7 +8365,7 @@ var ComplianceManager = class _ComplianceManager {
|
|
|
7239
8365
|
}
|
|
7240
8366
|
};
|
|
7241
8367
|
function generateId(prefix) {
|
|
7242
|
-
return `${prefix}_${(0,
|
|
8368
|
+
return `${prefix}_${(0, import_utils14.bytesToHex)((0, import_utils14.randomBytes)(12))}`;
|
|
7243
8369
|
}
|
|
7244
8370
|
function validateRegisterAuditorParams(params) {
|
|
7245
8371
|
if (!params.organization?.trim()) {
|
|
@@ -7327,10 +8453,10 @@ function validateReportParams(params) {
|
|
|
7327
8453
|
}
|
|
7328
8454
|
|
|
7329
8455
|
// src/wallet/errors.ts
|
|
7330
|
-
var
|
|
8456
|
+
var import_types18 = require("@sip-protocol/types");
|
|
7331
8457
|
var WalletError = class extends SIPError {
|
|
7332
8458
|
walletCode;
|
|
7333
|
-
constructor(message, walletCode =
|
|
8459
|
+
constructor(message, walletCode = import_types18.WalletErrorCode.UNKNOWN, options) {
|
|
7334
8460
|
super(message, "SIP_7000" /* WALLET_ERROR */, options);
|
|
7335
8461
|
this.walletCode = walletCode;
|
|
7336
8462
|
this.name = "WalletError";
|
|
@@ -7340,10 +8466,10 @@ var WalletError = class extends SIPError {
|
|
|
7340
8466
|
*/
|
|
7341
8467
|
isConnectionError() {
|
|
7342
8468
|
const codes = [
|
|
7343
|
-
|
|
7344
|
-
|
|
7345
|
-
|
|
7346
|
-
|
|
8469
|
+
import_types18.WalletErrorCode.NOT_INSTALLED,
|
|
8470
|
+
import_types18.WalletErrorCode.CONNECTION_REJECTED,
|
|
8471
|
+
import_types18.WalletErrorCode.CONNECTION_FAILED,
|
|
8472
|
+
import_types18.WalletErrorCode.NOT_CONNECTED
|
|
7347
8473
|
];
|
|
7348
8474
|
return codes.includes(this.walletCode);
|
|
7349
8475
|
}
|
|
@@ -7352,9 +8478,9 @@ var WalletError = class extends SIPError {
|
|
|
7352
8478
|
*/
|
|
7353
8479
|
isSigningError() {
|
|
7354
8480
|
const codes = [
|
|
7355
|
-
|
|
7356
|
-
|
|
7357
|
-
|
|
8481
|
+
import_types18.WalletErrorCode.SIGNING_REJECTED,
|
|
8482
|
+
import_types18.WalletErrorCode.SIGNING_FAILED,
|
|
8483
|
+
import_types18.WalletErrorCode.INVALID_MESSAGE
|
|
7358
8484
|
];
|
|
7359
8485
|
return codes.includes(this.walletCode);
|
|
7360
8486
|
}
|
|
@@ -7363,10 +8489,10 @@ var WalletError = class extends SIPError {
|
|
|
7363
8489
|
*/
|
|
7364
8490
|
isTransactionError() {
|
|
7365
8491
|
const codes = [
|
|
7366
|
-
|
|
7367
|
-
|
|
7368
|
-
|
|
7369
|
-
|
|
8492
|
+
import_types18.WalletErrorCode.INSUFFICIENT_FUNDS,
|
|
8493
|
+
import_types18.WalletErrorCode.TRANSACTION_REJECTED,
|
|
8494
|
+
import_types18.WalletErrorCode.TRANSACTION_FAILED,
|
|
8495
|
+
import_types18.WalletErrorCode.INVALID_TRANSACTION
|
|
7370
8496
|
];
|
|
7371
8497
|
return codes.includes(this.walletCode);
|
|
7372
8498
|
}
|
|
@@ -7375,9 +8501,9 @@ var WalletError = class extends SIPError {
|
|
|
7375
8501
|
*/
|
|
7376
8502
|
isPrivacyError() {
|
|
7377
8503
|
const codes = [
|
|
7378
|
-
|
|
7379
|
-
|
|
7380
|
-
|
|
8504
|
+
import_types18.WalletErrorCode.STEALTH_NOT_SUPPORTED,
|
|
8505
|
+
import_types18.WalletErrorCode.VIEWING_KEY_NOT_SUPPORTED,
|
|
8506
|
+
import_types18.WalletErrorCode.SHIELDED_NOT_SUPPORTED
|
|
7381
8507
|
];
|
|
7382
8508
|
return codes.includes(this.walletCode);
|
|
7383
8509
|
}
|
|
@@ -7386,10 +8512,10 @@ var WalletError = class extends SIPError {
|
|
|
7386
8512
|
*/
|
|
7387
8513
|
isUserRejection() {
|
|
7388
8514
|
const codes = [
|
|
7389
|
-
|
|
7390
|
-
|
|
7391
|
-
|
|
7392
|
-
|
|
8515
|
+
import_types18.WalletErrorCode.CONNECTION_REJECTED,
|
|
8516
|
+
import_types18.WalletErrorCode.SIGNING_REJECTED,
|
|
8517
|
+
import_types18.WalletErrorCode.TRANSACTION_REJECTED,
|
|
8518
|
+
import_types18.WalletErrorCode.CHAIN_SWITCH_REJECTED
|
|
7393
8519
|
];
|
|
7394
8520
|
return codes.includes(this.walletCode);
|
|
7395
8521
|
}
|
|
@@ -7397,15 +8523,15 @@ var WalletError = class extends SIPError {
|
|
|
7397
8523
|
function notConnectedError() {
|
|
7398
8524
|
return new WalletError(
|
|
7399
8525
|
"Wallet not connected. Call connect() first.",
|
|
7400
|
-
|
|
8526
|
+
import_types18.WalletErrorCode.NOT_CONNECTED
|
|
7401
8527
|
);
|
|
7402
8528
|
}
|
|
7403
|
-
function featureNotSupportedError(feature, code =
|
|
8529
|
+
function featureNotSupportedError(feature, code = import_types18.WalletErrorCode.UNKNOWN) {
|
|
7404
8530
|
return new WalletError(`${feature} is not supported by this wallet`, code);
|
|
7405
8531
|
}
|
|
7406
8532
|
|
|
7407
8533
|
// src/wallet/base-adapter.ts
|
|
7408
|
-
var
|
|
8534
|
+
var import_types19 = require("@sip-protocol/types");
|
|
7409
8535
|
var BaseWalletAdapter = class {
|
|
7410
8536
|
_address = "";
|
|
7411
8537
|
_publicKey = "";
|
|
@@ -7568,12 +8694,12 @@ var MockWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7568
8694
|
this._connectionState = "connecting";
|
|
7569
8695
|
if (this.shouldFailConnect) {
|
|
7570
8696
|
this.setError(
|
|
7571
|
-
|
|
8697
|
+
import_types19.WalletErrorCode.CONNECTION_FAILED,
|
|
7572
8698
|
"Mock connection failure"
|
|
7573
8699
|
);
|
|
7574
8700
|
throw new WalletError(
|
|
7575
8701
|
"Mock connection failure",
|
|
7576
|
-
|
|
8702
|
+
import_types19.WalletErrorCode.CONNECTION_FAILED
|
|
7577
8703
|
);
|
|
7578
8704
|
}
|
|
7579
8705
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
@@ -7585,7 +8711,7 @@ var MockWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7585
8711
|
async signMessage(message) {
|
|
7586
8712
|
this.requireConnected();
|
|
7587
8713
|
if (this.shouldFailSign) {
|
|
7588
|
-
throw new WalletError("Mock signing failure",
|
|
8714
|
+
throw new WalletError("Mock signing failure", import_types19.WalletErrorCode.SIGNING_FAILED);
|
|
7589
8715
|
}
|
|
7590
8716
|
const mockSig = new Uint8Array(64);
|
|
7591
8717
|
for (let i = 0; i < 64; i++) {
|
|
@@ -7600,7 +8726,7 @@ var MockWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7600
8726
|
async signTransaction(tx) {
|
|
7601
8727
|
this.requireConnected();
|
|
7602
8728
|
if (this.shouldFailSign) {
|
|
7603
|
-
throw new WalletError("Mock signing failure",
|
|
8729
|
+
throw new WalletError("Mock signing failure", import_types19.WalletErrorCode.SIGNING_FAILED);
|
|
7604
8730
|
}
|
|
7605
8731
|
const signature = await this.signMessage(
|
|
7606
8732
|
new TextEncoder().encode(JSON.stringify(tx.data))
|
|
@@ -7782,7 +8908,7 @@ function isPrivateWalletAdapter(adapter) {
|
|
|
7782
8908
|
}
|
|
7783
8909
|
|
|
7784
8910
|
// src/wallet/solana/adapter.ts
|
|
7785
|
-
var
|
|
8911
|
+
var import_types20 = require("@sip-protocol/types");
|
|
7786
8912
|
|
|
7787
8913
|
// src/wallet/solana/types.ts
|
|
7788
8914
|
function getSolanaProvider(wallet = "phantom") {
|
|
@@ -7903,19 +9029,19 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7903
9029
|
}
|
|
7904
9030
|
if (!this.provider) {
|
|
7905
9031
|
this.setError(
|
|
7906
|
-
|
|
9032
|
+
import_types20.WalletErrorCode.NOT_INSTALLED,
|
|
7907
9033
|
`${this.walletName} wallet is not installed`
|
|
7908
9034
|
);
|
|
7909
9035
|
throw new WalletError(
|
|
7910
9036
|
`${this.walletName} wallet is not installed`,
|
|
7911
|
-
|
|
9037
|
+
import_types20.WalletErrorCode.NOT_INSTALLED
|
|
7912
9038
|
);
|
|
7913
9039
|
}
|
|
7914
9040
|
const { publicKey } = await this.provider.connect();
|
|
7915
9041
|
if (!publicKey) {
|
|
7916
9042
|
throw new WalletError(
|
|
7917
9043
|
"No public key returned from wallet",
|
|
7918
|
-
|
|
9044
|
+
import_types20.WalletErrorCode.CONNECTION_FAILED
|
|
7919
9045
|
);
|
|
7920
9046
|
}
|
|
7921
9047
|
this.setupEventHandlers();
|
|
@@ -7925,11 +9051,11 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7925
9051
|
} catch (error) {
|
|
7926
9052
|
const message = error instanceof Error ? error.message : "Connection failed";
|
|
7927
9053
|
if (message.includes("User rejected") || message.includes("rejected")) {
|
|
7928
|
-
this.setError(
|
|
7929
|
-
throw new WalletError(message,
|
|
9054
|
+
this.setError(import_types20.WalletErrorCode.CONNECTION_REJECTED, message);
|
|
9055
|
+
throw new WalletError(message, import_types20.WalletErrorCode.CONNECTION_REJECTED);
|
|
7930
9056
|
}
|
|
7931
|
-
this.setError(
|
|
7932
|
-
throw error instanceof WalletError ? error : new WalletError(message,
|
|
9057
|
+
this.setError(import_types20.WalletErrorCode.CONNECTION_FAILED, message);
|
|
9058
|
+
throw error instanceof WalletError ? error : new WalletError(message, import_types20.WalletErrorCode.CONNECTION_FAILED, { cause: error });
|
|
7933
9059
|
}
|
|
7934
9060
|
}
|
|
7935
9061
|
/**
|
|
@@ -7952,7 +9078,7 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7952
9078
|
async signMessage(message) {
|
|
7953
9079
|
this.requireConnected();
|
|
7954
9080
|
if (!this.provider) {
|
|
7955
|
-
throw new WalletError("Provider not available",
|
|
9081
|
+
throw new WalletError("Provider not available", import_types20.WalletErrorCode.NOT_CONNECTED);
|
|
7956
9082
|
}
|
|
7957
9083
|
try {
|
|
7958
9084
|
const { signature } = await this.provider.signMessage(message);
|
|
@@ -7963,9 +9089,9 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7963
9089
|
} catch (error) {
|
|
7964
9090
|
const message2 = error instanceof Error ? error.message : "Signing failed";
|
|
7965
9091
|
if (message2.includes("User rejected") || message2.includes("rejected")) {
|
|
7966
|
-
throw new WalletError(message2,
|
|
9092
|
+
throw new WalletError(message2, import_types20.WalletErrorCode.SIGNING_REJECTED);
|
|
7967
9093
|
}
|
|
7968
|
-
throw new WalletError(message2,
|
|
9094
|
+
throw new WalletError(message2, import_types20.WalletErrorCode.SIGNING_FAILED, {
|
|
7969
9095
|
cause: error
|
|
7970
9096
|
});
|
|
7971
9097
|
}
|
|
@@ -7978,7 +9104,7 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7978
9104
|
async signTransaction(tx) {
|
|
7979
9105
|
this.requireConnected();
|
|
7980
9106
|
if (!this.provider) {
|
|
7981
|
-
throw new WalletError("Provider not available",
|
|
9107
|
+
throw new WalletError("Provider not available", import_types20.WalletErrorCode.NOT_CONNECTED);
|
|
7982
9108
|
}
|
|
7983
9109
|
try {
|
|
7984
9110
|
const solTx = tx.data;
|
|
@@ -7997,9 +9123,9 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
7997
9123
|
} catch (error) {
|
|
7998
9124
|
const message = error instanceof Error ? error.message : "Signing failed";
|
|
7999
9125
|
if (message.includes("User rejected") || message.includes("rejected")) {
|
|
8000
|
-
throw new WalletError(message,
|
|
9126
|
+
throw new WalletError(message, import_types20.WalletErrorCode.SIGNING_REJECTED);
|
|
8001
9127
|
}
|
|
8002
|
-
throw new WalletError(message,
|
|
9128
|
+
throw new WalletError(message, import_types20.WalletErrorCode.SIGNING_FAILED, {
|
|
8003
9129
|
cause: error
|
|
8004
9130
|
});
|
|
8005
9131
|
}
|
|
@@ -8010,7 +9136,7 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8010
9136
|
async signAndSendTransaction(tx) {
|
|
8011
9137
|
this.requireConnected();
|
|
8012
9138
|
if (!this.provider) {
|
|
8013
|
-
throw new WalletError("Provider not available",
|
|
9139
|
+
throw new WalletError("Provider not available", import_types20.WalletErrorCode.NOT_CONNECTED);
|
|
8014
9140
|
}
|
|
8015
9141
|
try {
|
|
8016
9142
|
const solTx = tx.data;
|
|
@@ -8025,12 +9151,12 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8025
9151
|
} catch (error) {
|
|
8026
9152
|
const message = error instanceof Error ? error.message : "Transaction failed";
|
|
8027
9153
|
if (message.includes("User rejected") || message.includes("rejected")) {
|
|
8028
|
-
throw new WalletError(message,
|
|
9154
|
+
throw new WalletError(message, import_types20.WalletErrorCode.TRANSACTION_REJECTED);
|
|
8029
9155
|
}
|
|
8030
9156
|
if (message.includes("insufficient") || message.includes("Insufficient")) {
|
|
8031
|
-
throw new WalletError(message,
|
|
9157
|
+
throw new WalletError(message, import_types20.WalletErrorCode.INSUFFICIENT_FUNDS);
|
|
8032
9158
|
}
|
|
8033
|
-
throw new WalletError(message,
|
|
9159
|
+
throw new WalletError(message, import_types20.WalletErrorCode.TRANSACTION_FAILED, {
|
|
8034
9160
|
cause: error
|
|
8035
9161
|
});
|
|
8036
9162
|
}
|
|
@@ -8043,16 +9169,16 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8043
9169
|
async signAllTransactions(transactions) {
|
|
8044
9170
|
this.requireConnected();
|
|
8045
9171
|
if (!this.provider) {
|
|
8046
|
-
throw new WalletError("Provider not available",
|
|
9172
|
+
throw new WalletError("Provider not available", import_types20.WalletErrorCode.NOT_CONNECTED);
|
|
8047
9173
|
}
|
|
8048
9174
|
try {
|
|
8049
9175
|
return await this.provider.signAllTransactions(transactions);
|
|
8050
9176
|
} catch (error) {
|
|
8051
9177
|
const message = error instanceof Error ? error.message : "Signing failed";
|
|
8052
9178
|
if (message.includes("User rejected") || message.includes("rejected")) {
|
|
8053
|
-
throw new WalletError(message,
|
|
9179
|
+
throw new WalletError(message, import_types20.WalletErrorCode.SIGNING_REJECTED);
|
|
8054
9180
|
}
|
|
8055
|
-
throw new WalletError(message,
|
|
9181
|
+
throw new WalletError(message, import_types20.WalletErrorCode.SIGNING_FAILED, {
|
|
8056
9182
|
cause: error
|
|
8057
9183
|
});
|
|
8058
9184
|
}
|
|
@@ -8073,7 +9199,7 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8073
9199
|
} catch (error) {
|
|
8074
9200
|
throw new WalletError(
|
|
8075
9201
|
"Failed to get balance",
|
|
8076
|
-
|
|
9202
|
+
import_types20.WalletErrorCode.UNKNOWN,
|
|
8077
9203
|
{ cause: error }
|
|
8078
9204
|
);
|
|
8079
9205
|
}
|
|
@@ -8086,7 +9212,7 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8086
9212
|
if (asset.chain !== "solana") {
|
|
8087
9213
|
throw new WalletError(
|
|
8088
9214
|
`Asset chain ${asset.chain} not supported by Solana adapter`,
|
|
8089
|
-
|
|
9215
|
+
import_types20.WalletErrorCode.UNSUPPORTED_CHAIN
|
|
8090
9216
|
);
|
|
8091
9217
|
}
|
|
8092
9218
|
if (!asset.address) {
|
|
@@ -8204,7 +9330,7 @@ function createSolanaAdapter(config = {}) {
|
|
|
8204
9330
|
}
|
|
8205
9331
|
|
|
8206
9332
|
// src/wallet/solana/mock.ts
|
|
8207
|
-
var
|
|
9333
|
+
var import_types22 = require("@sip-protocol/types");
|
|
8208
9334
|
var MockPublicKey = class {
|
|
8209
9335
|
base58;
|
|
8210
9336
|
bytes;
|
|
@@ -8270,8 +9396,8 @@ var MockSolanaAdapter = class extends BaseWalletAdapter {
|
|
|
8270
9396
|
this._connectionState = "connecting";
|
|
8271
9397
|
await this.simulateLatency();
|
|
8272
9398
|
if (this.shouldFailConnect) {
|
|
8273
|
-
this.setError(
|
|
8274
|
-
throw new WalletError("Mock connection failure",
|
|
9399
|
+
this.setError(import_types22.WalletErrorCode.CONNECTION_FAILED, "Mock connection failure");
|
|
9400
|
+
throw new WalletError("Mock connection failure", import_types22.WalletErrorCode.CONNECTION_FAILED);
|
|
8275
9401
|
}
|
|
8276
9402
|
const hexPubKey = "0x" + Buffer.from(this.mockPublicKey.toBytes()).toString("hex");
|
|
8277
9403
|
this.setConnected(this.mockAddress, hexPubKey);
|
|
@@ -8290,7 +9416,7 @@ var MockSolanaAdapter = class extends BaseWalletAdapter {
|
|
|
8290
9416
|
this.requireConnected();
|
|
8291
9417
|
await this.simulateLatency();
|
|
8292
9418
|
if (this.shouldFailSign) {
|
|
8293
|
-
throw new WalletError("Mock signing failure",
|
|
9419
|
+
throw new WalletError("Mock signing failure", import_types22.WalletErrorCode.SIGNING_REJECTED);
|
|
8294
9420
|
}
|
|
8295
9421
|
const mockSig = new Uint8Array(64);
|
|
8296
9422
|
for (let i = 0; i < 64; i++) {
|
|
@@ -8308,7 +9434,7 @@ var MockSolanaAdapter = class extends BaseWalletAdapter {
|
|
|
8308
9434
|
this.requireConnected();
|
|
8309
9435
|
await this.simulateLatency();
|
|
8310
9436
|
if (this.shouldFailSign) {
|
|
8311
|
-
throw new WalletError("Mock signing failure",
|
|
9437
|
+
throw new WalletError("Mock signing failure", import_types22.WalletErrorCode.SIGNING_REJECTED);
|
|
8312
9438
|
}
|
|
8313
9439
|
const solTx = tx.data;
|
|
8314
9440
|
this.signedTransactions.push(solTx);
|
|
@@ -8328,10 +9454,10 @@ var MockSolanaAdapter = class extends BaseWalletAdapter {
|
|
|
8328
9454
|
this.requireConnected();
|
|
8329
9455
|
await this.simulateLatency();
|
|
8330
9456
|
if (this.shouldFailSign) {
|
|
8331
|
-
throw new WalletError("Mock signing failure",
|
|
9457
|
+
throw new WalletError("Mock signing failure", import_types22.WalletErrorCode.SIGNING_REJECTED);
|
|
8332
9458
|
}
|
|
8333
9459
|
if (this.shouldFailTransaction) {
|
|
8334
|
-
throw new WalletError("Mock transaction failure",
|
|
9460
|
+
throw new WalletError("Mock transaction failure", import_types22.WalletErrorCode.TRANSACTION_FAILED);
|
|
8335
9461
|
}
|
|
8336
9462
|
const txSig = `mock_tx_${Date.now()}_${Math.random().toString(36).slice(2)}`;
|
|
8337
9463
|
this.sentTransactions.push(txSig);
|
|
@@ -8351,7 +9477,7 @@ var MockSolanaAdapter = class extends BaseWalletAdapter {
|
|
|
8351
9477
|
this.requireConnected();
|
|
8352
9478
|
await this.simulateLatency();
|
|
8353
9479
|
if (this.shouldFailSign) {
|
|
8354
|
-
throw new WalletError("Mock signing failure",
|
|
9480
|
+
throw new WalletError("Mock signing failure", import_types22.WalletErrorCode.SIGNING_REJECTED);
|
|
8355
9481
|
}
|
|
8356
9482
|
this.signedTransactions.push(...transactions);
|
|
8357
9483
|
return transactions.map((tx) => {
|
|
@@ -8378,7 +9504,7 @@ var MockSolanaAdapter = class extends BaseWalletAdapter {
|
|
|
8378
9504
|
if (asset.chain !== "solana") {
|
|
8379
9505
|
throw new WalletError(
|
|
8380
9506
|
`Asset chain ${asset.chain} not supported by Solana adapter`,
|
|
8381
|
-
|
|
9507
|
+
import_types22.WalletErrorCode.UNSUPPORTED_CHAIN
|
|
8382
9508
|
);
|
|
8383
9509
|
}
|
|
8384
9510
|
if (!asset.address) {
|
|
@@ -8547,7 +9673,7 @@ function createMockSolanaAdapter(config = {}) {
|
|
|
8547
9673
|
}
|
|
8548
9674
|
|
|
8549
9675
|
// src/wallet/ethereum/adapter.ts
|
|
8550
|
-
var
|
|
9676
|
+
var import_types24 = require("@sip-protocol/types");
|
|
8551
9677
|
|
|
8552
9678
|
// src/wallet/ethereum/types.ts
|
|
8553
9679
|
var EthereumChainId = {
|
|
@@ -8689,7 +9815,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8689
9815
|
this._connectionState = "error";
|
|
8690
9816
|
throw new WalletError(
|
|
8691
9817
|
`${this.walletType} wallet not found. Please install the extension.`,
|
|
8692
|
-
|
|
9818
|
+
import_types24.WalletErrorCode.NOT_INSTALLED
|
|
8693
9819
|
);
|
|
8694
9820
|
}
|
|
8695
9821
|
const accounts = await this.provider.request({
|
|
@@ -8699,7 +9825,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8699
9825
|
this._connectionState = "error";
|
|
8700
9826
|
throw new WalletError(
|
|
8701
9827
|
"No accounts returned from wallet",
|
|
8702
|
-
|
|
9828
|
+
import_types24.WalletErrorCode.CONNECTION_REJECTED
|
|
8703
9829
|
);
|
|
8704
9830
|
}
|
|
8705
9831
|
const address = normalizeAddress(accounts[0]);
|
|
@@ -8719,12 +9845,12 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8719
9845
|
if (rpcError.code === 4001) {
|
|
8720
9846
|
throw new WalletError(
|
|
8721
9847
|
"User rejected connection request",
|
|
8722
|
-
|
|
9848
|
+
import_types24.WalletErrorCode.CONNECTION_REJECTED
|
|
8723
9849
|
);
|
|
8724
9850
|
}
|
|
8725
9851
|
throw new WalletError(
|
|
8726
9852
|
`Failed to connect: ${rpcError.message || String(error)}`,
|
|
8727
|
-
|
|
9853
|
+
import_types24.WalletErrorCode.CONNECTION_FAILED
|
|
8728
9854
|
);
|
|
8729
9855
|
}
|
|
8730
9856
|
}
|
|
@@ -8744,7 +9870,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8744
9870
|
if (!this.provider) {
|
|
8745
9871
|
throw new WalletError(
|
|
8746
9872
|
"Provider not available",
|
|
8747
|
-
|
|
9873
|
+
import_types24.WalletErrorCode.NOT_CONNECTED
|
|
8748
9874
|
);
|
|
8749
9875
|
}
|
|
8750
9876
|
try {
|
|
@@ -8762,12 +9888,12 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8762
9888
|
if (rpcError.code === 4001) {
|
|
8763
9889
|
throw new WalletError(
|
|
8764
9890
|
"User rejected signing request",
|
|
8765
|
-
|
|
9891
|
+
import_types24.WalletErrorCode.SIGNING_REJECTED
|
|
8766
9892
|
);
|
|
8767
9893
|
}
|
|
8768
9894
|
throw new WalletError(
|
|
8769
9895
|
`Failed to sign message: ${rpcError.message || String(error)}`,
|
|
8770
|
-
|
|
9896
|
+
import_types24.WalletErrorCode.SIGNING_FAILED
|
|
8771
9897
|
);
|
|
8772
9898
|
}
|
|
8773
9899
|
}
|
|
@@ -8779,7 +9905,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8779
9905
|
if (!this.provider) {
|
|
8780
9906
|
throw new WalletError(
|
|
8781
9907
|
"Provider not available",
|
|
8782
|
-
|
|
9908
|
+
import_types24.WalletErrorCode.NOT_CONNECTED
|
|
8783
9909
|
);
|
|
8784
9910
|
}
|
|
8785
9911
|
try {
|
|
@@ -8796,12 +9922,12 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8796
9922
|
if (rpcError.code === 4001) {
|
|
8797
9923
|
throw new WalletError(
|
|
8798
9924
|
"User rejected signing request",
|
|
8799
|
-
|
|
9925
|
+
import_types24.WalletErrorCode.SIGNING_REJECTED
|
|
8800
9926
|
);
|
|
8801
9927
|
}
|
|
8802
9928
|
throw new WalletError(
|
|
8803
9929
|
`Failed to sign typed data: ${rpcError.message || String(error)}`,
|
|
8804
|
-
|
|
9930
|
+
import_types24.WalletErrorCode.SIGNING_FAILED
|
|
8805
9931
|
);
|
|
8806
9932
|
}
|
|
8807
9933
|
}
|
|
@@ -8813,7 +9939,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8813
9939
|
if (!this.provider) {
|
|
8814
9940
|
throw new WalletError(
|
|
8815
9941
|
"Provider not available",
|
|
8816
|
-
|
|
9942
|
+
import_types24.WalletErrorCode.NOT_CONNECTED
|
|
8817
9943
|
);
|
|
8818
9944
|
}
|
|
8819
9945
|
try {
|
|
@@ -8841,7 +9967,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8841
9967
|
if (rpcError.code === 4001) {
|
|
8842
9968
|
throw new WalletError(
|
|
8843
9969
|
"User rejected transaction signing",
|
|
8844
|
-
|
|
9970
|
+
import_types24.WalletErrorCode.SIGNING_REJECTED
|
|
8845
9971
|
);
|
|
8846
9972
|
}
|
|
8847
9973
|
if (rpcError.code === -32601 || rpcError.message?.includes("not supported")) {
|
|
@@ -8859,7 +9985,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8859
9985
|
}
|
|
8860
9986
|
throw new WalletError(
|
|
8861
9987
|
`Failed to sign transaction: ${rpcError.message || String(error)}`,
|
|
8862
|
-
|
|
9988
|
+
import_types24.WalletErrorCode.TRANSACTION_FAILED
|
|
8863
9989
|
);
|
|
8864
9990
|
}
|
|
8865
9991
|
}
|
|
@@ -8871,7 +9997,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8871
9997
|
if (!this.provider) {
|
|
8872
9998
|
throw new WalletError(
|
|
8873
9999
|
"Provider not available",
|
|
8874
|
-
|
|
10000
|
+
import_types24.WalletErrorCode.NOT_CONNECTED
|
|
8875
10001
|
);
|
|
8876
10002
|
}
|
|
8877
10003
|
try {
|
|
@@ -8893,12 +10019,12 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8893
10019
|
if (rpcError.code === 4001) {
|
|
8894
10020
|
throw new WalletError(
|
|
8895
10021
|
"User rejected transaction",
|
|
8896
|
-
|
|
10022
|
+
import_types24.WalletErrorCode.TRANSACTION_REJECTED
|
|
8897
10023
|
);
|
|
8898
10024
|
}
|
|
8899
10025
|
throw new WalletError(
|
|
8900
10026
|
`Failed to send transaction: ${rpcError.message || String(error)}`,
|
|
8901
|
-
|
|
10027
|
+
import_types24.WalletErrorCode.TRANSACTION_FAILED
|
|
8902
10028
|
);
|
|
8903
10029
|
}
|
|
8904
10030
|
}
|
|
@@ -8933,7 +10059,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8933
10059
|
} catch (error) {
|
|
8934
10060
|
throw new WalletError(
|
|
8935
10061
|
`Failed to fetch balance: ${String(error)}`,
|
|
8936
|
-
|
|
10062
|
+
import_types24.WalletErrorCode.UNKNOWN
|
|
8937
10063
|
);
|
|
8938
10064
|
}
|
|
8939
10065
|
}
|
|
@@ -8945,7 +10071,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8945
10071
|
if (asset.chain !== "ethereum") {
|
|
8946
10072
|
throw new WalletError(
|
|
8947
10073
|
`Asset chain ${asset.chain} not supported by Ethereum adapter`,
|
|
8948
|
-
|
|
10074
|
+
import_types24.WalletErrorCode.UNSUPPORTED_CHAIN
|
|
8949
10075
|
);
|
|
8950
10076
|
}
|
|
8951
10077
|
if (!asset.address) {
|
|
@@ -8970,7 +10096,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8970
10096
|
} catch (error) {
|
|
8971
10097
|
throw new WalletError(
|
|
8972
10098
|
`Failed to fetch token balance: ${String(error)}`,
|
|
8973
|
-
|
|
10099
|
+
import_types24.WalletErrorCode.UNKNOWN
|
|
8974
10100
|
);
|
|
8975
10101
|
}
|
|
8976
10102
|
}
|
|
@@ -8982,7 +10108,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8982
10108
|
if (!this.provider) {
|
|
8983
10109
|
throw new WalletError(
|
|
8984
10110
|
"Provider not available",
|
|
8985
|
-
|
|
10111
|
+
import_types24.WalletErrorCode.NOT_CONNECTED
|
|
8986
10112
|
);
|
|
8987
10113
|
}
|
|
8988
10114
|
try {
|
|
@@ -8997,18 +10123,18 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
8997
10123
|
if (rpcError.code === 4001) {
|
|
8998
10124
|
throw new WalletError(
|
|
8999
10125
|
"User rejected chain switch",
|
|
9000
|
-
|
|
10126
|
+
import_types24.WalletErrorCode.CHAIN_SWITCH_REJECTED
|
|
9001
10127
|
);
|
|
9002
10128
|
}
|
|
9003
10129
|
if (rpcError.code === 4902) {
|
|
9004
10130
|
throw new WalletError(
|
|
9005
10131
|
`Chain ${chainId} not added to wallet`,
|
|
9006
|
-
|
|
10132
|
+
import_types24.WalletErrorCode.UNSUPPORTED_CHAIN
|
|
9007
10133
|
);
|
|
9008
10134
|
}
|
|
9009
10135
|
throw new WalletError(
|
|
9010
10136
|
`Failed to switch chain: ${rpcError.message || String(error)}`,
|
|
9011
|
-
|
|
10137
|
+
import_types24.WalletErrorCode.CHAIN_SWITCH_FAILED
|
|
9012
10138
|
);
|
|
9013
10139
|
}
|
|
9014
10140
|
}
|
|
@@ -9044,7 +10170,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
|
|
|
9044
10170
|
}
|
|
9045
10171
|
throw new WalletError(
|
|
9046
10172
|
`Transaction ${txHash} not confirmed after ${maxAttempts * 5} seconds`,
|
|
9047
|
-
|
|
10173
|
+
import_types24.WalletErrorCode.TRANSACTION_FAILED
|
|
9048
10174
|
);
|
|
9049
10175
|
}
|
|
9050
10176
|
/**
|
|
@@ -9118,7 +10244,7 @@ function createEthereumAdapter(config) {
|
|
|
9118
10244
|
}
|
|
9119
10245
|
|
|
9120
10246
|
// src/wallet/ethereum/mock.ts
|
|
9121
|
-
var
|
|
10247
|
+
var import_types26 = require("@sip-protocol/types");
|
|
9122
10248
|
var MockEthereumAdapter = class extends BaseWalletAdapter {
|
|
9123
10249
|
chain = "ethereum";
|
|
9124
10250
|
name = "mock-ethereum";
|
|
@@ -9159,7 +10285,7 @@ var MockEthereumAdapter = class extends BaseWalletAdapter {
|
|
|
9159
10285
|
this._connectionState = "error";
|
|
9160
10286
|
throw new WalletError(
|
|
9161
10287
|
"Mock connection rejected",
|
|
9162
|
-
|
|
10288
|
+
import_types26.WalletErrorCode.CONNECTION_REJECTED
|
|
9163
10289
|
);
|
|
9164
10290
|
}
|
|
9165
10291
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
@@ -9171,7 +10297,7 @@ var MockEthereumAdapter = class extends BaseWalletAdapter {
|
|
|
9171
10297
|
this._connectionState = "error";
|
|
9172
10298
|
throw new WalletError(
|
|
9173
10299
|
`Mock connection failed: ${String(error)}`,
|
|
9174
|
-
|
|
10300
|
+
import_types26.WalletErrorCode.CONNECTION_FAILED
|
|
9175
10301
|
);
|
|
9176
10302
|
}
|
|
9177
10303
|
}
|
|
@@ -9189,7 +10315,7 @@ var MockEthereumAdapter = class extends BaseWalletAdapter {
|
|
|
9189
10315
|
if (this._shouldFailSign) {
|
|
9190
10316
|
throw new WalletError(
|
|
9191
10317
|
"Mock signing rejected",
|
|
9192
|
-
|
|
10318
|
+
import_types26.WalletErrorCode.SIGNING_REJECTED
|
|
9193
10319
|
);
|
|
9194
10320
|
}
|
|
9195
10321
|
const msgHex = Buffer.from(message).toString("hex");
|
|
@@ -9207,7 +10333,7 @@ var MockEthereumAdapter = class extends BaseWalletAdapter {
|
|
|
9207
10333
|
if (this._shouldFailSign) {
|
|
9208
10334
|
throw new WalletError(
|
|
9209
10335
|
"Mock signing rejected",
|
|
9210
|
-
|
|
10336
|
+
import_types26.WalletErrorCode.SIGNING_REJECTED
|
|
9211
10337
|
);
|
|
9212
10338
|
}
|
|
9213
10339
|
const mockSig = `0x${"1".repeat(130)}`;
|
|
@@ -9224,7 +10350,7 @@ var MockEthereumAdapter = class extends BaseWalletAdapter {
|
|
|
9224
10350
|
if (this._shouldFailSign) {
|
|
9225
10351
|
throw new WalletError(
|
|
9226
10352
|
"Mock signing rejected",
|
|
9227
|
-
|
|
10353
|
+
import_types26.WalletErrorCode.SIGNING_REJECTED
|
|
9228
10354
|
);
|
|
9229
10355
|
}
|
|
9230
10356
|
this._signedTransactions.push(tx);
|
|
@@ -9249,7 +10375,7 @@ var MockEthereumAdapter = class extends BaseWalletAdapter {
|
|
|
9249
10375
|
if (this._shouldFailTransaction) {
|
|
9250
10376
|
throw new WalletError(
|
|
9251
10377
|
"Mock transaction failed",
|
|
9252
|
-
|
|
10378
|
+
import_types26.WalletErrorCode.TRANSACTION_FAILED
|
|
9253
10379
|
);
|
|
9254
10380
|
}
|
|
9255
10381
|
this._signedTransactions.push(tx);
|
|
@@ -9279,7 +10405,7 @@ var MockEthereumAdapter = class extends BaseWalletAdapter {
|
|
|
9279
10405
|
if (asset.chain !== "ethereum") {
|
|
9280
10406
|
throw new WalletError(
|
|
9281
10407
|
`Asset chain ${asset.chain} not supported by Ethereum adapter`,
|
|
9282
|
-
|
|
10408
|
+
import_types26.WalletErrorCode.UNSUPPORTED_CHAIN
|
|
9283
10409
|
);
|
|
9284
10410
|
}
|
|
9285
10411
|
if (!asset.address) {
|
|
@@ -9558,7 +10684,7 @@ function getAvailableTransports() {
|
|
|
9558
10684
|
}
|
|
9559
10685
|
|
|
9560
10686
|
// src/wallet/hardware/ledger.ts
|
|
9561
|
-
var
|
|
10687
|
+
var import_types29 = require("@sip-protocol/types");
|
|
9562
10688
|
var LedgerWalletAdapter = class extends BaseWalletAdapter {
|
|
9563
10689
|
chain;
|
|
9564
10690
|
name = "ledger";
|
|
@@ -9711,7 +10837,7 @@ var LedgerWalletAdapter = class extends BaseWalletAdapter {
|
|
|
9711
10837
|
async getBalance() {
|
|
9712
10838
|
throw new WalletError(
|
|
9713
10839
|
"Hardware wallets do not track balances. Use an RPC provider.",
|
|
9714
|
-
|
|
10840
|
+
import_types29.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
9715
10841
|
);
|
|
9716
10842
|
}
|
|
9717
10843
|
/**
|
|
@@ -9722,7 +10848,7 @@ var LedgerWalletAdapter = class extends BaseWalletAdapter {
|
|
|
9722
10848
|
async getTokenBalance(_asset) {
|
|
9723
10849
|
throw new WalletError(
|
|
9724
10850
|
"Hardware wallets do not track balances. Use an RPC provider.",
|
|
9725
|
-
|
|
10851
|
+
import_types29.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
9726
10852
|
);
|
|
9727
10853
|
}
|
|
9728
10854
|
// ─── Account Management ─────────────────────────────────────────────────────
|
|
@@ -10010,7 +11136,7 @@ function createLedgerAdapter(config) {
|
|
|
10010
11136
|
}
|
|
10011
11137
|
|
|
10012
11138
|
// src/wallet/hardware/trezor.ts
|
|
10013
|
-
var
|
|
11139
|
+
var import_types31 = require("@sip-protocol/types");
|
|
10014
11140
|
var TrezorWalletAdapter = class extends BaseWalletAdapter {
|
|
10015
11141
|
chain;
|
|
10016
11142
|
name = "trezor";
|
|
@@ -10156,7 +11282,7 @@ var TrezorWalletAdapter = class extends BaseWalletAdapter {
|
|
|
10156
11282
|
async getBalance() {
|
|
10157
11283
|
throw new WalletError(
|
|
10158
11284
|
"Hardware wallets do not track balances. Use an RPC provider.",
|
|
10159
|
-
|
|
11285
|
+
import_types31.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
10160
11286
|
);
|
|
10161
11287
|
}
|
|
10162
11288
|
/**
|
|
@@ -10167,7 +11293,7 @@ var TrezorWalletAdapter = class extends BaseWalletAdapter {
|
|
|
10167
11293
|
async getTokenBalance(_asset) {
|
|
10168
11294
|
throw new WalletError(
|
|
10169
11295
|
"Hardware wallets do not track balances. Use an RPC provider.",
|
|
10170
|
-
|
|
11296
|
+
import_types31.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
10171
11297
|
);
|
|
10172
11298
|
}
|
|
10173
11299
|
// ─── Account Management ─────────────────────────────────────────────────────
|
|
@@ -10448,8 +11574,8 @@ function createTrezorAdapter(config) {
|
|
|
10448
11574
|
}
|
|
10449
11575
|
|
|
10450
11576
|
// src/wallet/hardware/mock.ts
|
|
10451
|
-
var
|
|
10452
|
-
var
|
|
11577
|
+
var import_types33 = require("@sip-protocol/types");
|
|
11578
|
+
var import_utils15 = require("@noble/hashes/utils");
|
|
10453
11579
|
var MockLedgerAdapter = class extends BaseWalletAdapter {
|
|
10454
11580
|
chain;
|
|
10455
11581
|
name = "mock-ledger";
|
|
@@ -10596,7 +11722,7 @@ var MockLedgerAdapter = class extends BaseWalletAdapter {
|
|
|
10596
11722
|
async getBalance() {
|
|
10597
11723
|
throw new WalletError(
|
|
10598
11724
|
"Hardware wallets do not track balances",
|
|
10599
|
-
|
|
11725
|
+
import_types33.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
10600
11726
|
);
|
|
10601
11727
|
}
|
|
10602
11728
|
/**
|
|
@@ -10605,7 +11731,7 @@ var MockLedgerAdapter = class extends BaseWalletAdapter {
|
|
|
10605
11731
|
async getTokenBalance(_asset) {
|
|
10606
11732
|
throw new WalletError(
|
|
10607
11733
|
"Hardware wallets do not track balances",
|
|
10608
|
-
|
|
11734
|
+
import_types33.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
10609
11735
|
);
|
|
10610
11736
|
}
|
|
10611
11737
|
/**
|
|
@@ -10694,15 +11820,15 @@ var MockLedgerAdapter = class extends BaseWalletAdapter {
|
|
|
10694
11820
|
}
|
|
10695
11821
|
}
|
|
10696
11822
|
generateMockAddress(index) {
|
|
10697
|
-
const bytes = (0,
|
|
11823
|
+
const bytes = (0, import_utils15.randomBytes)(20);
|
|
10698
11824
|
bytes[0] = index;
|
|
10699
|
-
return `0x${(0,
|
|
11825
|
+
return `0x${(0, import_utils15.bytesToHex)(bytes)}`;
|
|
10700
11826
|
}
|
|
10701
11827
|
generateMockPublicKey(index) {
|
|
10702
|
-
const bytes = (0,
|
|
11828
|
+
const bytes = (0, import_utils15.randomBytes)(33);
|
|
10703
11829
|
bytes[0] = 2;
|
|
10704
11830
|
bytes[1] = index;
|
|
10705
|
-
return `0x${(0,
|
|
11831
|
+
return `0x${(0, import_utils15.bytesToHex)(bytes)}`;
|
|
10706
11832
|
}
|
|
10707
11833
|
generateMockSignature(data) {
|
|
10708
11834
|
const sig = new Uint8Array(65);
|
|
@@ -10711,7 +11837,7 @@ var MockLedgerAdapter = class extends BaseWalletAdapter {
|
|
|
10711
11837
|
sig[32 + i] = (data[i % data.length] ?? 0) ^ i * 11;
|
|
10712
11838
|
}
|
|
10713
11839
|
sig[64] = 27;
|
|
10714
|
-
return `0x${(0,
|
|
11840
|
+
return `0x${(0, import_utils15.bytesToHex)(sig)}`;
|
|
10715
11841
|
}
|
|
10716
11842
|
delay(ms) {
|
|
10717
11843
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -10835,13 +11961,13 @@ var MockTrezorAdapter = class extends BaseWalletAdapter {
|
|
|
10835
11961
|
async getBalance() {
|
|
10836
11962
|
throw new WalletError(
|
|
10837
11963
|
"Hardware wallets do not track balances",
|
|
10838
|
-
|
|
11964
|
+
import_types33.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
10839
11965
|
);
|
|
10840
11966
|
}
|
|
10841
11967
|
async getTokenBalance(_asset) {
|
|
10842
11968
|
throw new WalletError(
|
|
10843
11969
|
"Hardware wallets do not track balances",
|
|
10844
|
-
|
|
11970
|
+
import_types33.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
10845
11971
|
);
|
|
10846
11972
|
}
|
|
10847
11973
|
async getAccounts(startIndex = 0, count = 5) {
|
|
@@ -10900,15 +12026,15 @@ var MockTrezorAdapter = class extends BaseWalletAdapter {
|
|
|
10900
12026
|
}
|
|
10901
12027
|
}
|
|
10902
12028
|
generateMockAddress(index) {
|
|
10903
|
-
const bytes = (0,
|
|
12029
|
+
const bytes = (0, import_utils15.randomBytes)(20);
|
|
10904
12030
|
bytes[0] = index + 100;
|
|
10905
|
-
return `0x${(0,
|
|
12031
|
+
return `0x${(0, import_utils15.bytesToHex)(bytes)}`;
|
|
10906
12032
|
}
|
|
10907
12033
|
generateMockPublicKey(index) {
|
|
10908
|
-
const bytes = (0,
|
|
12034
|
+
const bytes = (0, import_utils15.randomBytes)(33);
|
|
10909
12035
|
bytes[0] = 3;
|
|
10910
12036
|
bytes[1] = index + 100;
|
|
10911
|
-
return `0x${(0,
|
|
12037
|
+
return `0x${(0, import_utils15.bytesToHex)(bytes)}`;
|
|
10912
12038
|
}
|
|
10913
12039
|
generateMockSignature(data) {
|
|
10914
12040
|
const sig = new Uint8Array(65);
|
|
@@ -10917,7 +12043,7 @@ var MockTrezorAdapter = class extends BaseWalletAdapter {
|
|
|
10917
12043
|
sig[32 + i] = (data[i % data.length] ?? 0) ^ i * 17;
|
|
10918
12044
|
}
|
|
10919
12045
|
sig[64] = 28;
|
|
10920
|
-
return `0x${(0,
|
|
12046
|
+
return `0x${(0, import_utils15.bytesToHex)(sig)}`;
|
|
10921
12047
|
}
|
|
10922
12048
|
delay(ms) {
|
|
10923
12049
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -10931,7 +12057,7 @@ function createMockTrezorAdapter(config) {
|
|
|
10931
12057
|
}
|
|
10932
12058
|
|
|
10933
12059
|
// src/wallet/index.ts
|
|
10934
|
-
var
|
|
12060
|
+
var import_types36 = require("@sip-protocol/types");
|
|
10935
12061
|
// Annotate the CommonJS export names for ESM import in node:
|
|
10936
12062
|
0 && (module.exports = {
|
|
10937
12063
|
ATTESTATION_VERSION,
|
|
@@ -10961,6 +12087,7 @@ var import_types33 = require("@sip-protocol/types");
|
|
|
10961
12087
|
MockWalletAdapter,
|
|
10962
12088
|
NATIVE_TOKENS,
|
|
10963
12089
|
NEARIntentsAdapter,
|
|
12090
|
+
NEARIntentsBackend,
|
|
10964
12091
|
NetworkError,
|
|
10965
12092
|
ORACLE_DOMAIN,
|
|
10966
12093
|
OneClickClient,
|
|
@@ -10982,13 +12109,18 @@ var import_types33 = require("@sip-protocol/types");
|
|
|
10982
12109
|
STABLECOIN_ADDRESSES,
|
|
10983
12110
|
STABLECOIN_DECIMALS,
|
|
10984
12111
|
STABLECOIN_INFO,
|
|
12112
|
+
SettlementRegistry,
|
|
12113
|
+
SettlementRegistryError,
|
|
12114
|
+
SmartRouter,
|
|
10985
12115
|
SolanaWalletAdapter,
|
|
12116
|
+
SwapStatus,
|
|
10986
12117
|
Treasury,
|
|
10987
12118
|
TrezorWalletAdapter,
|
|
10988
12119
|
ValidationError,
|
|
10989
12120
|
WalletError,
|
|
10990
12121
|
WalletErrorCode,
|
|
10991
12122
|
ZcashErrorCode,
|
|
12123
|
+
ZcashNativeBackend,
|
|
10992
12124
|
ZcashRPCClient,
|
|
10993
12125
|
ZcashRPCError,
|
|
10994
12126
|
ZcashShieldedService,
|
|
@@ -11017,15 +12149,18 @@ var import_types33 = require("@sip-protocol/types");
|
|
|
11017
12149
|
createMockSolver,
|
|
11018
12150
|
createMockTrezorAdapter,
|
|
11019
12151
|
createNEARIntentsAdapter,
|
|
12152
|
+
createNEARIntentsBackend,
|
|
11020
12153
|
createOracleRegistry,
|
|
11021
12154
|
createProductionSIP,
|
|
11022
12155
|
createSIP,
|
|
11023
12156
|
createShieldedIntent,
|
|
11024
12157
|
createShieldedPayment,
|
|
12158
|
+
createSmartRouter,
|
|
11025
12159
|
createSolanaAdapter,
|
|
11026
12160
|
createTrezorAdapter,
|
|
11027
12161
|
createWalletFactory,
|
|
11028
12162
|
createZcashClient,
|
|
12163
|
+
createZcashNativeBackend,
|
|
11029
12164
|
createZcashShieldedService,
|
|
11030
12165
|
createZcashSwapService,
|
|
11031
12166
|
decodeStealthMetaAddress,
|