@sip-protocol/sdk 0.3.1 → 0.4.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 +2 -2
- package/dist/browser.d.ts +2 -2
- package/dist/browser.js +1028 -146
- package/dist/browser.mjs +49 -1
- package/dist/chunk-AOZIY3GU.mjs +12995 -0
- package/dist/chunk-BCLIX5T2.mjs +12940 -0
- package/dist/chunk-EU4UEWWG.mjs +12164 -0
- package/dist/chunk-FKXPHKYD.mjs +12955 -0
- package/dist/chunk-OPQ2GQIO.mjs +13013 -0
- package/dist/index-BcWNakUD.d.ts +7990 -0
- package/dist/index-BsKY3Hr0.d.mts +7990 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +999 -117
- package/dist/index.mjs +49 -1
- package/package.json +2 -1
- package/src/adapters/near-intents.ts +8 -0
- package/src/bitcoin/index.ts +51 -0
- package/src/bitcoin/silent-payments.ts +865 -0
- package/src/bitcoin/taproot.ts +590 -0
- package/src/cosmos/ibc-stealth.ts +825 -0
- package/src/cosmos/index.ts +83 -0
- package/src/cosmos/stealth.ts +487 -0
- package/src/index.ts +51 -0
- package/src/move/aptos.ts +369 -0
- package/src/move/index.ts +35 -0
- package/src/move/sui.ts +367 -0
- package/src/oracle/types.ts +8 -0
- package/src/settlement/backends/direct-chain.ts +8 -0
- package/src/settlement/backends/near-intents.ts +11 -0
- package/src/stealth.ts +3 -3
- package/src/validation.ts +42 -1
- package/src/wallet/aptos/adapter.ts +422 -0
- package/src/wallet/aptos/index.ts +10 -0
- package/src/wallet/aptos/mock.ts +410 -0
- package/src/wallet/aptos/types.ts +278 -0
- package/src/wallet/bitcoin/adapter.ts +470 -0
- package/src/wallet/bitcoin/index.ts +38 -0
- package/src/wallet/bitcoin/mock.ts +516 -0
- package/src/wallet/bitcoin/types.ts +274 -0
- package/src/wallet/cosmos/adapter.ts +484 -0
- package/src/wallet/cosmos/index.ts +63 -0
- package/src/wallet/cosmos/mock.ts +596 -0
- package/src/wallet/cosmos/types.ts +462 -0
- package/src/wallet/index.ts +127 -0
- package/src/wallet/sui/adapter.ts +471 -0
- package/src/wallet/sui/index.ts +10 -0
- package/src/wallet/sui/mock.ts +439 -0
- package/src/wallet/sui/types.ts +245 -0
package/dist/index.js
CHANGED
|
@@ -31,9 +31,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
ATTESTATION_VERSION: () => ATTESTATION_VERSION,
|
|
34
|
+
AptosStealthService: () => AptosStealthService,
|
|
34
35
|
BaseWalletAdapter: () => BaseWalletAdapter,
|
|
35
36
|
CHAIN_NUMERIC_IDS: () => CHAIN_NUMERIC_IDS,
|
|
37
|
+
COSMOS_CHAIN_PREFIXES: () => CHAIN_PREFIXES,
|
|
36
38
|
ComplianceManager: () => ComplianceManager,
|
|
39
|
+
CosmosStealthService: () => CosmosStealthService,
|
|
37
40
|
CryptoError: () => CryptoError,
|
|
38
41
|
DEFAULT_THRESHOLD: () => DEFAULT_THRESHOLD,
|
|
39
42
|
DEFAULT_TOTAL_ORACLES: () => DEFAULT_TOTAL_ORACLES,
|
|
@@ -46,7 +49,7 @@ __export(index_exports, {
|
|
|
46
49
|
HardwareWalletError: () => HardwareWalletError,
|
|
47
50
|
IntentBuilder: () => IntentBuilder,
|
|
48
51
|
IntentError: () => IntentError,
|
|
49
|
-
IntentStatus: () =>
|
|
52
|
+
IntentStatus: () => import_types55.IntentStatus,
|
|
50
53
|
LedgerWalletAdapter: () => LedgerWalletAdapter,
|
|
51
54
|
MockEthereumAdapter: () => MockEthereumAdapter,
|
|
52
55
|
MockLedgerAdapter: () => MockLedgerAdapter,
|
|
@@ -55,27 +58,27 @@ __export(index_exports, {
|
|
|
55
58
|
MockSolver: () => MockSolver,
|
|
56
59
|
MockTrezorAdapter: () => MockTrezorAdapter,
|
|
57
60
|
MockWalletAdapter: () => MockWalletAdapter,
|
|
58
|
-
NATIVE_TOKENS: () =>
|
|
61
|
+
NATIVE_TOKENS: () => import_types55.NATIVE_TOKENS,
|
|
59
62
|
NEARIntentsAdapter: () => NEARIntentsAdapter,
|
|
60
63
|
NEARIntentsBackend: () => NEARIntentsBackend,
|
|
61
64
|
NetworkError: () => NetworkError,
|
|
62
65
|
ORACLE_DOMAIN: () => ORACLE_DOMAIN,
|
|
63
66
|
OneClickClient: () => OneClickClient,
|
|
64
|
-
OneClickDepositMode: () =>
|
|
65
|
-
OneClickErrorCode: () =>
|
|
66
|
-
OneClickSwapStatus: () =>
|
|
67
|
-
OneClickSwapType: () =>
|
|
67
|
+
OneClickDepositMode: () => import_types59.OneClickDepositMode,
|
|
68
|
+
OneClickErrorCode: () => import_types59.OneClickErrorCode,
|
|
69
|
+
OneClickSwapStatus: () => import_types59.OneClickSwapStatus,
|
|
70
|
+
OneClickSwapType: () => import_types59.OneClickSwapType,
|
|
68
71
|
PaymentBuilder: () => PaymentBuilder,
|
|
69
|
-
PaymentStatus: () =>
|
|
70
|
-
PrivacyLevel: () =>
|
|
72
|
+
PaymentStatus: () => import_types56.PaymentStatus,
|
|
73
|
+
PrivacyLevel: () => import_types55.PrivacyLevel,
|
|
71
74
|
ProofError: () => ProofError,
|
|
72
75
|
ProofGenerationError: () => ProofGenerationError,
|
|
73
76
|
ProofNotImplementedError: () => ProofNotImplementedError,
|
|
74
|
-
ProposalStatus: () =>
|
|
75
|
-
ReportStatus: () =>
|
|
77
|
+
ProposalStatus: () => import_types57.ProposalStatus,
|
|
78
|
+
ReportStatus: () => import_types58.ReportStatus,
|
|
76
79
|
SIP: () => SIP,
|
|
77
80
|
SIPError: () => SIPError,
|
|
78
|
-
SIP_VERSION: () =>
|
|
81
|
+
SIP_VERSION: () => import_types55.SIP_VERSION,
|
|
79
82
|
STABLECOIN_ADDRESSES: () => STABLECOIN_ADDRESSES,
|
|
80
83
|
STABLECOIN_DECIMALS: () => STABLECOIN_DECIMALS,
|
|
81
84
|
STABLECOIN_INFO: () => STABLECOIN_INFO,
|
|
@@ -88,8 +91,8 @@ __export(index_exports, {
|
|
|
88
91
|
TrezorWalletAdapter: () => TrezorWalletAdapter,
|
|
89
92
|
ValidationError: () => ValidationError,
|
|
90
93
|
WalletError: () => WalletError,
|
|
91
|
-
WalletErrorCode: () =>
|
|
92
|
-
ZcashErrorCode: () =>
|
|
94
|
+
WalletErrorCode: () => import_types54.WalletErrorCode,
|
|
95
|
+
ZcashErrorCode: () => import_types60.ZcashErrorCode,
|
|
93
96
|
ZcashNativeBackend: () => ZcashNativeBackend,
|
|
94
97
|
ZcashRPCClient: () => ZcashRPCClient,
|
|
95
98
|
ZcashRPCError: () => ZcashRPCError,
|
|
@@ -98,17 +101,21 @@ __export(index_exports, {
|
|
|
98
101
|
addBlindings: () => addBlindings,
|
|
99
102
|
addCommitments: () => addCommitments,
|
|
100
103
|
addOracle: () => addOracle,
|
|
104
|
+
aptosAddressToAuthKey: () => aptosAddressToAuthKey,
|
|
101
105
|
attachProofs: () => attachProofs,
|
|
102
106
|
base58ToHex: () => base58ToHex,
|
|
103
|
-
browserBytesToHex: () =>
|
|
104
|
-
browserHexToBytes: () =>
|
|
107
|
+
browserBytesToHex: () => bytesToHex11,
|
|
108
|
+
browserHexToBytes: () => hexToBytes9,
|
|
109
|
+
checkAptosStealthAddress: () => checkAptosStealthAddress,
|
|
105
110
|
checkEd25519StealthAddress: () => checkEd25519StealthAddress,
|
|
106
111
|
checkStealthAddress: () => checkStealthAddress,
|
|
107
112
|
commit: () => commit,
|
|
108
113
|
commitZero: () => commitZero,
|
|
109
114
|
computeAttestationHash: () => computeAttestationHash,
|
|
115
|
+
computeTweakedKey: () => computeTweakedKey,
|
|
110
116
|
createCommitment: () => createCommitment,
|
|
111
117
|
createEthereumAdapter: () => createEthereumAdapter,
|
|
118
|
+
createKeySpendOnlyOutput: () => createKeySpendOnlyOutput,
|
|
112
119
|
createLedgerAdapter: () => createLedgerAdapter,
|
|
113
120
|
createMockEthereumAdapter: () => createMockEthereumAdapter,
|
|
114
121
|
createMockEthereumProvider: () => createMockEthereumProvider,
|
|
@@ -127,6 +134,7 @@ __export(index_exports, {
|
|
|
127
134
|
createShieldedPayment: () => createShieldedPayment,
|
|
128
135
|
createSmartRouter: () => createSmartRouter,
|
|
129
136
|
createSolanaAdapter: () => createSolanaAdapter,
|
|
137
|
+
createTaprootOutput: () => createTaprootOutput,
|
|
130
138
|
createTrezorAdapter: () => createTrezorAdapter,
|
|
131
139
|
createWalletFactory: () => createWalletFactory,
|
|
132
140
|
createZcashClient: () => createZcashClient,
|
|
@@ -134,8 +142,10 @@ __export(index_exports, {
|
|
|
134
142
|
createZcashShieldedService: () => createZcashShieldedService,
|
|
135
143
|
createZcashSwapService: () => createZcashSwapService,
|
|
136
144
|
decodeStealthMetaAddress: () => decodeStealthMetaAddress,
|
|
145
|
+
decodeTaprootAddress: () => decodeTaprootAddress,
|
|
137
146
|
decryptMemo: () => decryptMemo,
|
|
138
147
|
decryptWithViewing: () => decryptWithViewing,
|
|
148
|
+
deriveAptosStealthPrivateKey: () => deriveAptosStealthPrivateKey,
|
|
139
149
|
deriveEd25519StealthPrivateKey: () => deriveEd25519StealthPrivateKey,
|
|
140
150
|
deriveOracleId: () => deriveOracleId,
|
|
141
151
|
deriveStealthPrivateKey: () => deriveStealthPrivateKey,
|
|
@@ -145,6 +155,7 @@ __export(index_exports, {
|
|
|
145
155
|
deserializePayment: () => deserializePayment,
|
|
146
156
|
detectEthereumWallets: () => detectEthereumWallets,
|
|
147
157
|
detectSolanaWallets: () => detectSolanaWallets,
|
|
158
|
+
ed25519PublicKeyToAptosAddress: () => ed25519PublicKeyToAptosAddress,
|
|
148
159
|
ed25519PublicKeyToNearAddress: () => ed25519PublicKeyToNearAddress,
|
|
149
160
|
ed25519PublicKeyToSolanaAddress: () => ed25519PublicKeyToSolanaAddress,
|
|
150
161
|
encodeStealthMetaAddress: () => encodeStealthMetaAddress,
|
|
@@ -153,7 +164,10 @@ __export(index_exports, {
|
|
|
153
164
|
formatStablecoinAmount: () => formatStablecoinAmount,
|
|
154
165
|
fromHex: () => fromHex,
|
|
155
166
|
fromStablecoinUnits: () => fromStablecoinUnits,
|
|
167
|
+
generateAptosStealthAddress: () => generateAptosStealthAddress,
|
|
156
168
|
generateBlinding: () => generateBlinding,
|
|
169
|
+
generateCosmosStealthAddress: () => generateCosmosStealthAddress,
|
|
170
|
+
generateCosmosStealthMetaAddress: () => generateCosmosStealthMetaAddress,
|
|
157
171
|
generateEd25519StealthAddress: () => generateEd25519StealthAddress,
|
|
158
172
|
generateEd25519StealthMetaAddress: () => generateEd25519StealthMetaAddress,
|
|
159
173
|
generateIntentId: () => generateIntentId,
|
|
@@ -183,6 +197,7 @@ __export(index_exports, {
|
|
|
183
197
|
getStablecoinsForChain: () => getStablecoinsForChain,
|
|
184
198
|
getSupportedStablecoins: () => getSupportedStablecoins,
|
|
185
199
|
getTimeRemaining: () => getTimeRemaining,
|
|
200
|
+
getXOnlyPublicKey: () => getXOnlyPublicKey,
|
|
186
201
|
hasEnoughOracles: () => hasEnoughOracles,
|
|
187
202
|
hasErrorCode: () => hasErrorCode,
|
|
188
203
|
hasRequiredProofs: () => hasRequiredProofs,
|
|
@@ -193,14 +208,16 @@ __export(index_exports, {
|
|
|
193
208
|
isExpired: () => isExpired,
|
|
194
209
|
isNonNegativeAmount: () => isNonNegativeAmount,
|
|
195
210
|
isPaymentExpired: () => isPaymentExpired,
|
|
196
|
-
isPrivate: () =>
|
|
211
|
+
isPrivate: () => import_types55.isPrivate,
|
|
197
212
|
isPrivateWalletAdapter: () => isPrivateWalletAdapter,
|
|
198
213
|
isSIPError: () => isSIPError,
|
|
199
214
|
isStablecoin: () => isStablecoin,
|
|
200
215
|
isStablecoinOnChain: () => isStablecoinOnChain,
|
|
201
216
|
isValidAmount: () => isValidAmount,
|
|
217
|
+
isValidAptosAddress: () => isValidAptosAddress,
|
|
202
218
|
isValidChainId: () => isValidChainId,
|
|
203
219
|
isValidCompressedPublicKey: () => isValidCompressedPublicKey,
|
|
220
|
+
isValidCosmosAddress: () => isValidCosmosAddress,
|
|
204
221
|
isValidEd25519PublicKey: () => isValidEd25519PublicKey,
|
|
205
222
|
isValidHex: () => isValidHex,
|
|
206
223
|
isValidHexLength: () => isValidHexLength,
|
|
@@ -212,12 +229,17 @@ __export(index_exports, {
|
|
|
212
229
|
isValidSlippage: () => isValidSlippage,
|
|
213
230
|
isValidSolanaAddress: () => isValidSolanaAddress,
|
|
214
231
|
isValidStealthMetaAddress: () => isValidStealthMetaAddress,
|
|
232
|
+
isValidTaprootAddress: () => isValidTaprootAddress,
|
|
215
233
|
nearAddressToEd25519PublicKey: () => nearAddressToEd25519PublicKey,
|
|
216
234
|
normalizeAddress: () => normalizeAddress,
|
|
217
235
|
notConnectedError: () => notConnectedError,
|
|
218
236
|
publicKeyToEthAddress: () => publicKeyToEthAddress,
|
|
219
237
|
registerWallet: () => registerWallet,
|
|
220
238
|
removeOracle: () => removeOracle,
|
|
239
|
+
schnorrSign: () => schnorrSign,
|
|
240
|
+
schnorrSignHex: () => schnorrSignHex,
|
|
241
|
+
schnorrVerify: () => schnorrVerify,
|
|
242
|
+
schnorrVerifyHex: () => schnorrVerifyHex,
|
|
221
243
|
secureWipe: () => secureWipe,
|
|
222
244
|
secureWipeAll: () => secureWipeAll,
|
|
223
245
|
serializeAttestationMessage: () => serializeAttestationMessage,
|
|
@@ -226,14 +248,16 @@ __export(index_exports, {
|
|
|
226
248
|
signAttestationMessage: () => signAttestationMessage,
|
|
227
249
|
solanaAddressToEd25519PublicKey: () => solanaAddressToEd25519PublicKey,
|
|
228
250
|
solanaPublicKeyToHex: () => solanaPublicKeyToHex,
|
|
251
|
+
stealthKeyToCosmosAddress: () => stealthKeyToCosmosAddress,
|
|
229
252
|
subtractBlindings: () => subtractBlindings,
|
|
230
253
|
subtractCommitments: () => subtractCommitments,
|
|
231
254
|
supportsSharedArrayBuffer: () => supportsSharedArrayBuffer,
|
|
232
|
-
supportsViewingKey: () =>
|
|
255
|
+
supportsViewingKey: () => import_types55.supportsViewingKey,
|
|
233
256
|
supportsWebBluetooth: () => supportsWebBluetooth,
|
|
234
257
|
supportsWebHID: () => supportsWebHID,
|
|
235
258
|
supportsWebUSB: () => supportsWebUSB,
|
|
236
259
|
supportsWebWorkers: () => supportsWebWorkers,
|
|
260
|
+
taprootAddress: () => taprootAddress,
|
|
237
261
|
toHex: () => toHex,
|
|
238
262
|
toStablecoinUnits: () => toStablecoinUnits,
|
|
239
263
|
trackIntent: () => trackIntent,
|
|
@@ -474,7 +498,16 @@ var VALID_CHAIN_IDS = [
|
|
|
474
498
|
"polygon",
|
|
475
499
|
"arbitrum",
|
|
476
500
|
"optimism",
|
|
477
|
-
"base"
|
|
501
|
+
"base",
|
|
502
|
+
"bitcoin",
|
|
503
|
+
"aptos",
|
|
504
|
+
"sui",
|
|
505
|
+
"cosmos",
|
|
506
|
+
"osmosis",
|
|
507
|
+
"injective",
|
|
508
|
+
"celestia",
|
|
509
|
+
"sei",
|
|
510
|
+
"dydx"
|
|
478
511
|
];
|
|
479
512
|
function isValidChainId(chain) {
|
|
480
513
|
return VALID_CHAIN_IDS.includes(chain);
|
|
@@ -671,6 +704,12 @@ function isValidNearAddressFormat(address) {
|
|
|
671
704
|
if (address.includes("..")) return false;
|
|
672
705
|
return true;
|
|
673
706
|
}
|
|
707
|
+
function isValidCosmosAddressFormat(address) {
|
|
708
|
+
if (typeof address !== "string") return false;
|
|
709
|
+
if (address.length < 39 || address.length > 90) return false;
|
|
710
|
+
const bech32Pattern = /^[a-z]+1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38,}$/;
|
|
711
|
+
return bech32Pattern.test(address);
|
|
712
|
+
}
|
|
674
713
|
function getChainAddressType(chain) {
|
|
675
714
|
switch (chain) {
|
|
676
715
|
case "ethereum":
|
|
@@ -685,6 +724,13 @@ function getChainAddressType(chain) {
|
|
|
685
724
|
return "near";
|
|
686
725
|
case "zcash":
|
|
687
726
|
return "zcash";
|
|
727
|
+
case "cosmos":
|
|
728
|
+
case "osmosis":
|
|
729
|
+
case "injective":
|
|
730
|
+
case "celestia":
|
|
731
|
+
case "sei":
|
|
732
|
+
case "dydx":
|
|
733
|
+
return "cosmos";
|
|
688
734
|
default:
|
|
689
735
|
return "unknown";
|
|
690
736
|
}
|
|
@@ -728,6 +774,15 @@ function validateAddressForChain(address, chain, field = "address") {
|
|
|
728
774
|
);
|
|
729
775
|
}
|
|
730
776
|
break;
|
|
777
|
+
case "cosmos":
|
|
778
|
+
if (!isValidCosmosAddressFormat(address)) {
|
|
779
|
+
throw new ValidationError(
|
|
780
|
+
`Invalid address format for ${chain}. Expected Cosmos bech32 address, got: ${address.slice(0, 20)}...`,
|
|
781
|
+
field,
|
|
782
|
+
{ chain, expectedFormat: "bech32" }
|
|
783
|
+
);
|
|
784
|
+
}
|
|
785
|
+
break;
|
|
731
786
|
default:
|
|
732
787
|
break;
|
|
733
788
|
}
|
|
@@ -779,7 +834,7 @@ function secureWipeAll(...buffers) {
|
|
|
779
834
|
function generateStealthMetaAddress(chain, label) {
|
|
780
835
|
if (!isValidChainId(chain)) {
|
|
781
836
|
throw new ValidationError(
|
|
782
|
-
`invalid chain '${chain}', must be one of: solana, ethereum, near, zcash, polygon, arbitrum, optimism, base`,
|
|
837
|
+
`invalid chain '${chain}', must be one of: solana, ethereum, near, zcash, polygon, arbitrum, optimism, base, bitcoin, aptos, sui, cosmos, osmosis, injective, celestia, sei, dydx`,
|
|
783
838
|
"chain"
|
|
784
839
|
);
|
|
785
840
|
}
|
|
@@ -1059,7 +1114,7 @@ function toChecksumAddress(address) {
|
|
|
1059
1114
|
return checksummed;
|
|
1060
1115
|
}
|
|
1061
1116
|
var ED25519_ORDER = 2n ** 252n + 27742317777372353535851937790883648493n;
|
|
1062
|
-
var ED25519_CHAINS = ["solana", "near"];
|
|
1117
|
+
var ED25519_CHAINS = ["solana", "near", "aptos", "sui"];
|
|
1063
1118
|
function isEd25519Chain(chain) {
|
|
1064
1119
|
return ED25519_CHAINS.includes(chain);
|
|
1065
1120
|
}
|
|
@@ -1144,7 +1199,7 @@ function bigIntToBytesLE(value, length) {
|
|
|
1144
1199
|
function generateEd25519StealthMetaAddress(chain, label) {
|
|
1145
1200
|
if (!isValidChainId(chain)) {
|
|
1146
1201
|
throw new ValidationError(
|
|
1147
|
-
`invalid chain '${chain}', must be one of: solana, ethereum, near, zcash, polygon, arbitrum, optimism, base`,
|
|
1202
|
+
`invalid chain '${chain}', must be one of: solana, ethereum, near, zcash, polygon, arbitrum, optimism, base, bitcoin, aptos, sui, cosmos, osmosis, injective, celestia, sei, dydx`,
|
|
1148
1203
|
"chain"
|
|
1149
1204
|
);
|
|
1150
1205
|
}
|
|
@@ -2514,7 +2569,15 @@ var CHAIN_BLOCKCHAIN_MAP = {
|
|
|
2514
2569
|
arbitrum: "evm",
|
|
2515
2570
|
optimism: "evm",
|
|
2516
2571
|
base: "evm",
|
|
2517
|
-
bitcoin: "bitcoin"
|
|
2572
|
+
bitcoin: "bitcoin",
|
|
2573
|
+
aptos: "aptos",
|
|
2574
|
+
sui: "sui",
|
|
2575
|
+
cosmos: "cosmos",
|
|
2576
|
+
osmosis: "cosmos",
|
|
2577
|
+
injective: "cosmos",
|
|
2578
|
+
celestia: "cosmos",
|
|
2579
|
+
sei: "cosmos",
|
|
2580
|
+
dydx: "cosmos"
|
|
2518
2581
|
};
|
|
2519
2582
|
var NEARIntentsAdapter = class {
|
|
2520
2583
|
client;
|
|
@@ -3274,6 +3337,448 @@ function createProductionSIP(config) {
|
|
|
3274
3337
|
});
|
|
3275
3338
|
}
|
|
3276
3339
|
|
|
3340
|
+
// src/move/aptos.ts
|
|
3341
|
+
var import_sha32 = require("@noble/hashes/sha3");
|
|
3342
|
+
var import_utils7 = require("@noble/hashes/utils");
|
|
3343
|
+
var APTOS_SINGLE_ED25519_SCHEME = 0;
|
|
3344
|
+
function ed25519PublicKeyToAptosAddress(publicKey) {
|
|
3345
|
+
if (!isValidHex(publicKey)) {
|
|
3346
|
+
throw new ValidationError(
|
|
3347
|
+
"publicKey must be a valid hex string with 0x prefix",
|
|
3348
|
+
"publicKey"
|
|
3349
|
+
);
|
|
3350
|
+
}
|
|
3351
|
+
if (!isValidEd25519PublicKey(publicKey)) {
|
|
3352
|
+
throw new ValidationError(
|
|
3353
|
+
"publicKey must be 32 bytes (64 hex characters)",
|
|
3354
|
+
"publicKey"
|
|
3355
|
+
);
|
|
3356
|
+
}
|
|
3357
|
+
const publicKeyBytes = (0, import_utils7.hexToBytes)(publicKey.slice(2));
|
|
3358
|
+
const authKeyInput = new Uint8Array(publicKeyBytes.length + 1);
|
|
3359
|
+
authKeyInput.set(publicKeyBytes, 0);
|
|
3360
|
+
authKeyInput[publicKeyBytes.length] = APTOS_SINGLE_ED25519_SCHEME;
|
|
3361
|
+
const addressHash = (0, import_sha32.sha3_256)(authKeyInput);
|
|
3362
|
+
return `0x${(0, import_utils7.bytesToHex)(addressHash)}`;
|
|
3363
|
+
}
|
|
3364
|
+
function isValidAptosAddress(address) {
|
|
3365
|
+
if (typeof address !== "string" || address.length === 0) {
|
|
3366
|
+
return false;
|
|
3367
|
+
}
|
|
3368
|
+
if (!address.startsWith("0x")) {
|
|
3369
|
+
return false;
|
|
3370
|
+
}
|
|
3371
|
+
const hexPart = address.slice(2);
|
|
3372
|
+
if (hexPart.length !== 64) {
|
|
3373
|
+
return false;
|
|
3374
|
+
}
|
|
3375
|
+
return /^[0-9a-fA-F]{64}$/.test(hexPart);
|
|
3376
|
+
}
|
|
3377
|
+
function aptosAddressToAuthKey(address) {
|
|
3378
|
+
if (!isValidAptosAddress(address)) {
|
|
3379
|
+
throw new ValidationError(
|
|
3380
|
+
"Invalid Aptos address format (must be 0x-prefixed 64 hex characters)",
|
|
3381
|
+
"address"
|
|
3382
|
+
);
|
|
3383
|
+
}
|
|
3384
|
+
return address.toLowerCase();
|
|
3385
|
+
}
|
|
3386
|
+
function generateAptosStealthAddress(recipientMetaAddress) {
|
|
3387
|
+
if (recipientMetaAddress.chain !== "aptos") {
|
|
3388
|
+
throw new ValidationError(
|
|
3389
|
+
`Expected chain 'aptos', got '${recipientMetaAddress.chain}'`,
|
|
3390
|
+
"recipientMetaAddress.chain"
|
|
3391
|
+
);
|
|
3392
|
+
}
|
|
3393
|
+
const { stealthAddress, sharedSecret } = generateEd25519StealthAddress(recipientMetaAddress);
|
|
3394
|
+
const aptosAddress = ed25519PublicKeyToAptosAddress(stealthAddress.address);
|
|
3395
|
+
return {
|
|
3396
|
+
stealthAddress: aptosAddress,
|
|
3397
|
+
stealthPublicKey: stealthAddress.address,
|
|
3398
|
+
ephemeralPublicKey: stealthAddress.ephemeralPublicKey,
|
|
3399
|
+
viewTag: stealthAddress.viewTag,
|
|
3400
|
+
sharedSecret
|
|
3401
|
+
};
|
|
3402
|
+
}
|
|
3403
|
+
function deriveAptosStealthPrivateKey(stealthAddress, spendingPrivateKey, viewingPrivateKey) {
|
|
3404
|
+
const recovery = deriveEd25519StealthPrivateKey(
|
|
3405
|
+
stealthAddress,
|
|
3406
|
+
spendingPrivateKey,
|
|
3407
|
+
viewingPrivateKey
|
|
3408
|
+
);
|
|
3409
|
+
const aptosAddress = ed25519PublicKeyToAptosAddress(recovery.stealthAddress);
|
|
3410
|
+
return {
|
|
3411
|
+
...recovery,
|
|
3412
|
+
aptosAddress
|
|
3413
|
+
};
|
|
3414
|
+
}
|
|
3415
|
+
function checkAptosStealthAddress(stealthAddress, spendingPrivateKey, viewingPrivateKey) {
|
|
3416
|
+
return checkEd25519StealthAddress(
|
|
3417
|
+
stealthAddress,
|
|
3418
|
+
spendingPrivateKey,
|
|
3419
|
+
viewingPrivateKey
|
|
3420
|
+
);
|
|
3421
|
+
}
|
|
3422
|
+
var AptosStealthService = class {
|
|
3423
|
+
/**
|
|
3424
|
+
* Generate a stealth address for an Aptos recipient
|
|
3425
|
+
*
|
|
3426
|
+
* @param recipientMetaAddress - Recipient's stealth meta-address
|
|
3427
|
+
* @returns Complete stealth address result
|
|
3428
|
+
*/
|
|
3429
|
+
generateStealthAddress(recipientMetaAddress) {
|
|
3430
|
+
return generateAptosStealthAddress(recipientMetaAddress);
|
|
3431
|
+
}
|
|
3432
|
+
/**
|
|
3433
|
+
* Convert an ed25519 public key to Aptos address format
|
|
3434
|
+
*
|
|
3435
|
+
* @param publicKey - 32-byte ed25519 public key
|
|
3436
|
+
* @returns Aptos address string
|
|
3437
|
+
*/
|
|
3438
|
+
stealthKeyToAptosAddress(publicKey) {
|
|
3439
|
+
return ed25519PublicKeyToAptosAddress(publicKey);
|
|
3440
|
+
}
|
|
3441
|
+
/**
|
|
3442
|
+
* Derive the private key for a stealth address
|
|
3443
|
+
*
|
|
3444
|
+
* @param stealthAddress - Stealth address data
|
|
3445
|
+
* @param spendingPrivateKey - Recipient's spending private key
|
|
3446
|
+
* @param viewingPrivateKey - Recipient's viewing private key
|
|
3447
|
+
* @returns Recovery data with derived private key
|
|
3448
|
+
*/
|
|
3449
|
+
deriveStealthPrivateKey(stealthAddress, spendingPrivateKey, viewingPrivateKey) {
|
|
3450
|
+
return deriveAptosStealthPrivateKey(stealthAddress, spendingPrivateKey, viewingPrivateKey);
|
|
3451
|
+
}
|
|
3452
|
+
/**
|
|
3453
|
+
* Check if a stealth address belongs to this recipient
|
|
3454
|
+
*
|
|
3455
|
+
* @param stealthAddress - Stealth address to check
|
|
3456
|
+
* @param spendingPrivateKey - Recipient's spending private key
|
|
3457
|
+
* @param viewingPrivateKey - Recipient's viewing private key
|
|
3458
|
+
* @returns true if the address belongs to this recipient
|
|
3459
|
+
*/
|
|
3460
|
+
checkStealthAddress(stealthAddress, spendingPrivateKey, viewingPrivateKey) {
|
|
3461
|
+
return checkAptosStealthAddress(stealthAddress, spendingPrivateKey, viewingPrivateKey);
|
|
3462
|
+
}
|
|
3463
|
+
/**
|
|
3464
|
+
* Validate an Aptos address format
|
|
3465
|
+
*
|
|
3466
|
+
* @param address - Address to validate
|
|
3467
|
+
* @returns true if valid format
|
|
3468
|
+
*/
|
|
3469
|
+
isValidAddress(address) {
|
|
3470
|
+
return isValidAptosAddress(address);
|
|
3471
|
+
}
|
|
3472
|
+
};
|
|
3473
|
+
|
|
3474
|
+
// src/move/sui.ts
|
|
3475
|
+
var import_blake2b = require("@noble/hashes/blake2b");
|
|
3476
|
+
var import_utils8 = require("@noble/hashes/utils");
|
|
3477
|
+
|
|
3478
|
+
// src/cosmos/stealth.ts
|
|
3479
|
+
var import_sha2566 = require("@noble/hashes/sha256");
|
|
3480
|
+
var import_ripemd160 = require("@noble/hashes/ripemd160");
|
|
3481
|
+
var import_utils9 = require("@noble/hashes/utils");
|
|
3482
|
+
var import_base = require("@scure/base");
|
|
3483
|
+
var CHAIN_PREFIXES = {
|
|
3484
|
+
cosmos: "cosmos",
|
|
3485
|
+
osmosis: "osmo",
|
|
3486
|
+
injective: "inj",
|
|
3487
|
+
celestia: "celestia",
|
|
3488
|
+
sei: "sei",
|
|
3489
|
+
dydx: "dydx"
|
|
3490
|
+
};
|
|
3491
|
+
var CosmosStealthService = class {
|
|
3492
|
+
/**
|
|
3493
|
+
* Generate a stealth meta-address for a Cosmos chain
|
|
3494
|
+
*
|
|
3495
|
+
* @param chain - Cosmos chain identifier
|
|
3496
|
+
* @param label - Optional human-readable label
|
|
3497
|
+
* @returns Stealth meta-address and private keys
|
|
3498
|
+
* @throws {ValidationError} If chain is invalid
|
|
3499
|
+
*
|
|
3500
|
+
* @example
|
|
3501
|
+
* ```typescript
|
|
3502
|
+
* const service = new CosmosStealthService()
|
|
3503
|
+
* const { metaAddress, spendingPrivateKey, viewingPrivateKey } =
|
|
3504
|
+
* service.generateStealthMetaAddress('cosmos', 'My Cosmos Wallet')
|
|
3505
|
+
* ```
|
|
3506
|
+
*/
|
|
3507
|
+
generateStealthMetaAddress(chain, label) {
|
|
3508
|
+
if (!this.isValidCosmosChain(chain)) {
|
|
3509
|
+
throw new ValidationError(
|
|
3510
|
+
`invalid Cosmos chain '${chain}', must be one of: ${Object.keys(CHAIN_PREFIXES).join(", ")}`,
|
|
3511
|
+
"chain"
|
|
3512
|
+
);
|
|
3513
|
+
}
|
|
3514
|
+
const result = generateStealthMetaAddress("ethereum", label);
|
|
3515
|
+
return {
|
|
3516
|
+
...result,
|
|
3517
|
+
metaAddress: {
|
|
3518
|
+
...result.metaAddress,
|
|
3519
|
+
chain
|
|
3520
|
+
// Will be updated in types package
|
|
3521
|
+
}
|
|
3522
|
+
};
|
|
3523
|
+
}
|
|
3524
|
+
/**
|
|
3525
|
+
* Generate a one-time stealth address for a Cosmos chain
|
|
3526
|
+
*
|
|
3527
|
+
* @param spendingPubKey - Recipient's spending public key (33-byte compressed)
|
|
3528
|
+
* @param viewingPubKey - Recipient's viewing public key (33-byte compressed)
|
|
3529
|
+
* @param chain - Cosmos chain identifier
|
|
3530
|
+
* @returns Cosmos stealth address with bech32 encoding
|
|
3531
|
+
* @throws {ValidationError} If keys or chain are invalid
|
|
3532
|
+
*
|
|
3533
|
+
* @example
|
|
3534
|
+
* ```typescript
|
|
3535
|
+
* const service = new CosmosStealthService()
|
|
3536
|
+
* const result = service.generateStealthAddress(
|
|
3537
|
+
* spendingKey,
|
|
3538
|
+
* viewingKey,
|
|
3539
|
+
* 'osmosis'
|
|
3540
|
+
* )
|
|
3541
|
+
* console.log(result.stealthAddress) // "osmo1..."
|
|
3542
|
+
* ```
|
|
3543
|
+
*/
|
|
3544
|
+
generateStealthAddress(spendingPubKey, viewingPubKey, chain) {
|
|
3545
|
+
if (!this.isValidCosmosChain(chain)) {
|
|
3546
|
+
throw new ValidationError(
|
|
3547
|
+
`invalid Cosmos chain '${chain}', must be one of: ${Object.keys(CHAIN_PREFIXES).join(", ")}`,
|
|
3548
|
+
"chain"
|
|
3549
|
+
);
|
|
3550
|
+
}
|
|
3551
|
+
if (spendingPubKey.length !== 33) {
|
|
3552
|
+
throw new ValidationError(
|
|
3553
|
+
"spendingPubKey must be 33 bytes (compressed secp256k1)",
|
|
3554
|
+
"spendingPubKey"
|
|
3555
|
+
);
|
|
3556
|
+
}
|
|
3557
|
+
if (viewingPubKey.length !== 33) {
|
|
3558
|
+
throw new ValidationError(
|
|
3559
|
+
"viewingPubKey must be 33 bytes (compressed secp256k1)",
|
|
3560
|
+
"viewingPubKey"
|
|
3561
|
+
);
|
|
3562
|
+
}
|
|
3563
|
+
const metaAddress = {
|
|
3564
|
+
spendingKey: `0x${(0, import_utils9.bytesToHex)(spendingPubKey)}`,
|
|
3565
|
+
viewingKey: `0x${(0, import_utils9.bytesToHex)(viewingPubKey)}`,
|
|
3566
|
+
chain: "ethereum"
|
|
3567
|
+
// Use ethereum for secp256k1 generation
|
|
3568
|
+
};
|
|
3569
|
+
const { stealthAddress, sharedSecret } = generateStealthAddress(metaAddress);
|
|
3570
|
+
const cosmosAddress = this.stealthKeyToCosmosAddress(
|
|
3571
|
+
(0, import_utils9.hexToBytes)(stealthAddress.address.slice(2)),
|
|
3572
|
+
CHAIN_PREFIXES[chain]
|
|
3573
|
+
);
|
|
3574
|
+
return {
|
|
3575
|
+
stealthAddress: cosmosAddress,
|
|
3576
|
+
stealthPublicKey: stealthAddress.address,
|
|
3577
|
+
ephemeralPublicKey: stealthAddress.ephemeralPublicKey,
|
|
3578
|
+
viewTag: stealthAddress.viewTag,
|
|
3579
|
+
viewKeyHash: sharedSecret
|
|
3580
|
+
};
|
|
3581
|
+
}
|
|
3582
|
+
/**
|
|
3583
|
+
* Generate stealth address from StealthMetaAddress
|
|
3584
|
+
*
|
|
3585
|
+
* Convenience method that accepts a StealthMetaAddress directly.
|
|
3586
|
+
*
|
|
3587
|
+
* @param recipientMetaAddress - Recipient's stealth meta-address
|
|
3588
|
+
* @param chain - Cosmos chain identifier
|
|
3589
|
+
* @returns Cosmos stealth address with bech32 encoding
|
|
3590
|
+
* @throws {ValidationError} If meta-address or chain are invalid
|
|
3591
|
+
*
|
|
3592
|
+
* @example
|
|
3593
|
+
* ```typescript
|
|
3594
|
+
* const service = new CosmosStealthService()
|
|
3595
|
+
* const result = service.generateStealthAddressFromMeta(metaAddress, 'cosmos')
|
|
3596
|
+
* ```
|
|
3597
|
+
*/
|
|
3598
|
+
generateStealthAddressFromMeta(recipientMetaAddress, chain) {
|
|
3599
|
+
const spendingPubKey = (0, import_utils9.hexToBytes)(recipientMetaAddress.spendingKey.slice(2));
|
|
3600
|
+
const viewingPubKey = (0, import_utils9.hexToBytes)(recipientMetaAddress.viewingKey.slice(2));
|
|
3601
|
+
return this.generateStealthAddress(spendingPubKey, viewingPubKey, chain);
|
|
3602
|
+
}
|
|
3603
|
+
/**
|
|
3604
|
+
* Convert stealth public key to Cosmos bech32 address
|
|
3605
|
+
*
|
|
3606
|
+
* Algorithm:
|
|
3607
|
+
* 1. SHA256 hash of compressed public key
|
|
3608
|
+
* 2. RIPEMD160 hash of SHA256 hash
|
|
3609
|
+
* 3. Bech32 encode with chain prefix
|
|
3610
|
+
*
|
|
3611
|
+
* @param publicKey - Compressed secp256k1 public key (33 bytes)
|
|
3612
|
+
* @param prefix - Bech32 address prefix (e.g., "cosmos", "osmo")
|
|
3613
|
+
* @returns Bech32-encoded address
|
|
3614
|
+
* @throws {ValidationError} If public key is invalid
|
|
3615
|
+
*
|
|
3616
|
+
* @example
|
|
3617
|
+
* ```typescript
|
|
3618
|
+
* const service = new CosmosStealthService()
|
|
3619
|
+
* const address = service.stealthKeyToCosmosAddress(pubKey, 'cosmos')
|
|
3620
|
+
* // Returns: "cosmos1abc..."
|
|
3621
|
+
* ```
|
|
3622
|
+
*/
|
|
3623
|
+
stealthKeyToCosmosAddress(publicKey, prefix) {
|
|
3624
|
+
if (publicKey.length !== 33) {
|
|
3625
|
+
throw new ValidationError(
|
|
3626
|
+
"public key must be 33 bytes (compressed secp256k1)",
|
|
3627
|
+
"publicKey"
|
|
3628
|
+
);
|
|
3629
|
+
}
|
|
3630
|
+
const sha256Hash = (0, import_sha2566.sha256)(publicKey);
|
|
3631
|
+
const hash160 = (0, import_ripemd160.ripemd160)(sha256Hash);
|
|
3632
|
+
const words = import_base.bech32.toWords(hash160);
|
|
3633
|
+
return import_base.bech32.encode(prefix, words);
|
|
3634
|
+
}
|
|
3635
|
+
/**
|
|
3636
|
+
* Derive stealth private key for recipient to claim funds
|
|
3637
|
+
*
|
|
3638
|
+
* @param stealthAddress - The stealth address to recover (as StealthAddress)
|
|
3639
|
+
* @param spendingPrivateKey - Recipient's spending private key
|
|
3640
|
+
* @param viewingPrivateKey - Recipient's viewing private key
|
|
3641
|
+
* @returns Recovery data with derived private key
|
|
3642
|
+
* @throws {ValidationError} If any input is invalid
|
|
3643
|
+
*
|
|
3644
|
+
* @example
|
|
3645
|
+
* ```typescript
|
|
3646
|
+
* const service = new CosmosStealthService()
|
|
3647
|
+
* const recovery = service.deriveStealthPrivateKey(
|
|
3648
|
+
* stealthAddress,
|
|
3649
|
+
* spendingPrivKey,
|
|
3650
|
+
* viewingPrivKey
|
|
3651
|
+
* )
|
|
3652
|
+
* // Use recovery.privateKey to spend funds
|
|
3653
|
+
* ```
|
|
3654
|
+
*/
|
|
3655
|
+
deriveStealthPrivateKey(stealthAddress, spendingPrivateKey, viewingPrivateKey) {
|
|
3656
|
+
return deriveStealthPrivateKey(
|
|
3657
|
+
stealthAddress,
|
|
3658
|
+
spendingPrivateKey,
|
|
3659
|
+
viewingPrivateKey
|
|
3660
|
+
);
|
|
3661
|
+
}
|
|
3662
|
+
/**
|
|
3663
|
+
* Check if a string is a valid Cosmos chain identifier
|
|
3664
|
+
*/
|
|
3665
|
+
isValidCosmosChain(chain) {
|
|
3666
|
+
return chain in CHAIN_PREFIXES;
|
|
3667
|
+
}
|
|
3668
|
+
/**
|
|
3669
|
+
* Decode a Cosmos bech32 address to raw hash
|
|
3670
|
+
*
|
|
3671
|
+
* @param address - Bech32-encoded address
|
|
3672
|
+
* @returns Decoded address hash (20 bytes)
|
|
3673
|
+
* @throws {ValidationError} If address is invalid
|
|
3674
|
+
*
|
|
3675
|
+
* @example
|
|
3676
|
+
* ```typescript
|
|
3677
|
+
* const service = new CosmosStealthService()
|
|
3678
|
+
* const { prefix, hash } = service.decodeBech32Address('cosmos1abc...')
|
|
3679
|
+
* ```
|
|
3680
|
+
*/
|
|
3681
|
+
decodeBech32Address(address) {
|
|
3682
|
+
try {
|
|
3683
|
+
const decoded = import_base.bech32.decode(address);
|
|
3684
|
+
const hash2 = import_base.bech32.fromWords(decoded.words);
|
|
3685
|
+
if (hash2.length !== 20) {
|
|
3686
|
+
throw new ValidationError(
|
|
3687
|
+
`invalid address hash length: ${hash2.length}, expected 20`,
|
|
3688
|
+
"address"
|
|
3689
|
+
);
|
|
3690
|
+
}
|
|
3691
|
+
return {
|
|
3692
|
+
prefix: decoded.prefix,
|
|
3693
|
+
hash: new Uint8Array(hash2)
|
|
3694
|
+
};
|
|
3695
|
+
} catch (error) {
|
|
3696
|
+
if (error instanceof ValidationError) {
|
|
3697
|
+
throw error;
|
|
3698
|
+
}
|
|
3699
|
+
throw new ValidationError(
|
|
3700
|
+
`invalid bech32 address: ${error instanceof Error ? error.message : "unknown error"}`,
|
|
3701
|
+
"address"
|
|
3702
|
+
);
|
|
3703
|
+
}
|
|
3704
|
+
}
|
|
3705
|
+
/**
|
|
3706
|
+
* Validate a Cosmos bech32 address format
|
|
3707
|
+
*
|
|
3708
|
+
* @param address - Address to validate
|
|
3709
|
+
* @param expectedChain - Optional chain to validate prefix against
|
|
3710
|
+
* @returns true if valid, false otherwise
|
|
3711
|
+
*
|
|
3712
|
+
* @example
|
|
3713
|
+
* ```typescript
|
|
3714
|
+
* const service = new CosmosStealthService()
|
|
3715
|
+
* service.isValidCosmosAddress('cosmos1abc...', 'cosmos') // true
|
|
3716
|
+
* service.isValidCosmosAddress('osmo1xyz...', 'cosmos') // false (wrong prefix)
|
|
3717
|
+
* ```
|
|
3718
|
+
*/
|
|
3719
|
+
isValidCosmosAddress(address, expectedChain) {
|
|
3720
|
+
try {
|
|
3721
|
+
const { prefix, hash: hash2 } = this.decodeBech32Address(address);
|
|
3722
|
+
if (hash2.length !== 20) {
|
|
3723
|
+
return false;
|
|
3724
|
+
}
|
|
3725
|
+
if (expectedChain) {
|
|
3726
|
+
return prefix === CHAIN_PREFIXES[expectedChain];
|
|
3727
|
+
}
|
|
3728
|
+
return Object.values(CHAIN_PREFIXES).includes(prefix);
|
|
3729
|
+
} catch {
|
|
3730
|
+
return false;
|
|
3731
|
+
}
|
|
3732
|
+
}
|
|
3733
|
+
/**
|
|
3734
|
+
* Get the chain ID from a bech32 address prefix
|
|
3735
|
+
*
|
|
3736
|
+
* @param address - Bech32-encoded address
|
|
3737
|
+
* @returns Chain ID or null if unknown prefix
|
|
3738
|
+
*
|
|
3739
|
+
* @example
|
|
3740
|
+
* ```typescript
|
|
3741
|
+
* const service = new CosmosStealthService()
|
|
3742
|
+
* service.getChainFromAddress('cosmos1abc...') // 'cosmos'
|
|
3743
|
+
* service.getChainFromAddress('osmo1xyz...') // 'osmosis'
|
|
3744
|
+
* ```
|
|
3745
|
+
*/
|
|
3746
|
+
getChainFromAddress(address) {
|
|
3747
|
+
try {
|
|
3748
|
+
const { prefix } = this.decodeBech32Address(address);
|
|
3749
|
+
for (const [chain, chainPrefix] of Object.entries(CHAIN_PREFIXES)) {
|
|
3750
|
+
if (chainPrefix === prefix) {
|
|
3751
|
+
return chain;
|
|
3752
|
+
}
|
|
3753
|
+
}
|
|
3754
|
+
return null;
|
|
3755
|
+
} catch {
|
|
3756
|
+
return null;
|
|
3757
|
+
}
|
|
3758
|
+
}
|
|
3759
|
+
};
|
|
3760
|
+
function generateCosmosStealthMetaAddress(chain, label) {
|
|
3761
|
+
const service = new CosmosStealthService();
|
|
3762
|
+
return service.generateStealthMetaAddress(chain, label);
|
|
3763
|
+
}
|
|
3764
|
+
function generateCosmosStealthAddress(spendingPubKey, viewingPubKey, chain) {
|
|
3765
|
+
const service = new CosmosStealthService();
|
|
3766
|
+
return service.generateStealthAddress(spendingPubKey, viewingPubKey, chain);
|
|
3767
|
+
}
|
|
3768
|
+
function stealthKeyToCosmosAddress(publicKey, prefix) {
|
|
3769
|
+
const service = new CosmosStealthService();
|
|
3770
|
+
return service.stealthKeyToCosmosAddress(publicKey, prefix);
|
|
3771
|
+
}
|
|
3772
|
+
function isValidCosmosAddress(address, expectedChain) {
|
|
3773
|
+
const service = new CosmosStealthService();
|
|
3774
|
+
return service.isValidCosmosAddress(address, expectedChain);
|
|
3775
|
+
}
|
|
3776
|
+
|
|
3777
|
+
// src/cosmos/ibc-stealth.ts
|
|
3778
|
+
var import_utils10 = require("@noble/hashes/utils");
|
|
3779
|
+
var import_secp256k13 = require("@noble/curves/secp256k1");
|
|
3780
|
+
var import_sha2567 = require("@noble/hashes/sha256");
|
|
3781
|
+
|
|
3277
3782
|
// src/proofs/interface.ts
|
|
3278
3783
|
var ProofGenerationError = class extends Error {
|
|
3279
3784
|
proofType;
|
|
@@ -3287,8 +3792,8 @@ var ProofGenerationError = class extends Error {
|
|
|
3287
3792
|
};
|
|
3288
3793
|
|
|
3289
3794
|
// src/proofs/mock.ts
|
|
3290
|
-
var
|
|
3291
|
-
var
|
|
3795
|
+
var import_sha2568 = require("@noble/hashes/sha256");
|
|
3796
|
+
var import_utils11 = require("@noble/hashes/utils");
|
|
3292
3797
|
var MOCK_PROOF_PREFIX = "0x4d4f434b";
|
|
3293
3798
|
var WARNING_MESSAGE = `
|
|
3294
3799
|
\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557
|
|
@@ -3453,22 +3958,22 @@ var MockProofProvider = class {
|
|
|
3453
3958
|
{ type: proofType, params },
|
|
3454
3959
|
(_, v) => typeof v === "bigint" ? v.toString() : v
|
|
3455
3960
|
);
|
|
3456
|
-
const hash2 = (0,
|
|
3457
|
-
const random = (0,
|
|
3961
|
+
const hash2 = (0, import_sha2568.sha256)(new TextEncoder().encode(input));
|
|
3962
|
+
const random = (0, import_utils11.randomBytes)(16);
|
|
3458
3963
|
const combined = new Uint8Array(4 + hash2.length + random.length);
|
|
3459
3964
|
combined.set(new TextEncoder().encode("MOCK"), 0);
|
|
3460
3965
|
combined.set(hash2, 4);
|
|
3461
3966
|
combined.set(random, 4 + hash2.length);
|
|
3462
|
-
return `${MOCK_PROOF_PREFIX}${(0,
|
|
3967
|
+
return `${MOCK_PROOF_PREFIX}${(0, import_utils11.bytesToHex)(combined.slice(4))}`;
|
|
3463
3968
|
}
|
|
3464
3969
|
hashToHex(data) {
|
|
3465
|
-
const hash2 = (0,
|
|
3466
|
-
return `0x${(0,
|
|
3970
|
+
const hash2 = (0, import_sha2568.sha256)(new TextEncoder().encode(data));
|
|
3971
|
+
return `0x${(0, import_utils11.bytesToHex)(hash2)}`;
|
|
3467
3972
|
}
|
|
3468
3973
|
};
|
|
3469
3974
|
|
|
3470
3975
|
// src/proofs/browser-utils.ts
|
|
3471
|
-
function
|
|
3976
|
+
function hexToBytes9(hex) {
|
|
3472
3977
|
const h = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
3473
3978
|
if (h.length === 0) return new Uint8Array(0);
|
|
3474
3979
|
if (h.length % 2 !== 0) {
|
|
@@ -3480,7 +3985,7 @@ function hexToBytes5(hex) {
|
|
|
3480
3985
|
}
|
|
3481
3986
|
return bytes;
|
|
3482
3987
|
}
|
|
3483
|
-
function
|
|
3988
|
+
function bytesToHex11(bytes) {
|
|
3484
3989
|
return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
3485
3990
|
}
|
|
3486
3991
|
function isBrowser() {
|
|
@@ -3522,18 +4027,34 @@ var CHAIN_NUMERIC_IDS = {
|
|
|
3522
4027
|
// Non-standard, SIP-specific
|
|
3523
4028
|
near: 502,
|
|
3524
4029
|
// Non-standard, SIP-specific
|
|
3525
|
-
zcash: 503
|
|
4030
|
+
zcash: 503,
|
|
4031
|
+
// Non-standard, SIP-specific
|
|
4032
|
+
aptos: 504,
|
|
4033
|
+
// Non-standard, SIP-specific
|
|
4034
|
+
sui: 505,
|
|
4035
|
+
// Non-standard, SIP-specific
|
|
4036
|
+
cosmos: 506,
|
|
4037
|
+
// Non-standard, SIP-specific (Cosmos Hub)
|
|
4038
|
+
osmosis: 507,
|
|
4039
|
+
// Non-standard, SIP-specific
|
|
4040
|
+
injective: 508,
|
|
4041
|
+
// Non-standard, SIP-specific
|
|
4042
|
+
celestia: 509,
|
|
4043
|
+
// Non-standard, SIP-specific
|
|
4044
|
+
sei: 510,
|
|
4045
|
+
// Non-standard, SIP-specific
|
|
4046
|
+
dydx: 511
|
|
3526
4047
|
// Non-standard, SIP-specific
|
|
3527
4048
|
};
|
|
3528
4049
|
|
|
3529
4050
|
// src/oracle/verification.ts
|
|
3530
4051
|
var import_ed255192 = require("@noble/curves/ed25519");
|
|
3531
|
-
var
|
|
3532
|
-
var
|
|
4052
|
+
var import_sha25610 = require("@noble/hashes/sha256");
|
|
4053
|
+
var import_utils13 = require("@noble/hashes/utils");
|
|
3533
4054
|
|
|
3534
4055
|
// src/oracle/serialization.ts
|
|
3535
|
-
var
|
|
3536
|
-
var
|
|
4056
|
+
var import_sha2569 = require("@noble/hashes/sha256");
|
|
4057
|
+
var import_utils12 = require("@noble/hashes/utils");
|
|
3537
4058
|
function serializeAttestationMessage(message) {
|
|
3538
4059
|
const buffer = new Uint8Array(197);
|
|
3539
4060
|
const view = new DataView(buffer.buffer);
|
|
@@ -3576,19 +4097,19 @@ function deserializeAttestationMessage(bytes) {
|
|
|
3576
4097
|
const version = bytes[offset++];
|
|
3577
4098
|
const chainId = view.getUint32(offset, false);
|
|
3578
4099
|
offset += 4;
|
|
3579
|
-
const intentHash = `0x${(0,
|
|
4100
|
+
const intentHash = `0x${(0, import_utils12.bytesToHex)(bytes.slice(offset, offset + 32))}`;
|
|
3580
4101
|
offset += 32;
|
|
3581
|
-
const recipient = `0x${(0,
|
|
4102
|
+
const recipient = `0x${(0, import_utils12.bytesToHex)(bytes.slice(offset, offset + 32))}`;
|
|
3582
4103
|
offset += 32;
|
|
3583
4104
|
const amount = bytesToBigint(bytes.slice(offset, offset + 16));
|
|
3584
4105
|
offset += 16;
|
|
3585
|
-
const assetId = `0x${(0,
|
|
4106
|
+
const assetId = `0x${(0, import_utils12.bytesToHex)(bytes.slice(offset, offset + 32))}`;
|
|
3586
4107
|
offset += 32;
|
|
3587
|
-
const txHash = `0x${(0,
|
|
4108
|
+
const txHash = `0x${(0, import_utils12.bytesToHex)(bytes.slice(offset, offset + 32))}`;
|
|
3588
4109
|
offset += 32;
|
|
3589
4110
|
const blockNumber = view.getBigUint64(offset, false);
|
|
3590
4111
|
offset += 8;
|
|
3591
|
-
const blockHash = `0x${(0,
|
|
4112
|
+
const blockHash = `0x${(0, import_utils12.bytesToHex)(bytes.slice(offset, offset + 32))}`;
|
|
3592
4113
|
offset += 32;
|
|
3593
4114
|
const timestamp = Number(view.getBigUint64(offset, false));
|
|
3594
4115
|
return {
|
|
@@ -3605,12 +4126,12 @@ function deserializeAttestationMessage(bytes) {
|
|
|
3605
4126
|
};
|
|
3606
4127
|
}
|
|
3607
4128
|
function computeAttestationHash(message) {
|
|
3608
|
-
const domain = (0,
|
|
4129
|
+
const domain = (0, import_utils12.utf8ToBytes)(ORACLE_DOMAIN);
|
|
3609
4130
|
const messageBytes = serializeAttestationMessage(message);
|
|
3610
4131
|
const toHash = new Uint8Array(domain.length + messageBytes.length);
|
|
3611
4132
|
toHash.set(domain, 0);
|
|
3612
4133
|
toHash.set(messageBytes, domain.length);
|
|
3613
|
-
return (0,
|
|
4134
|
+
return (0, import_sha2569.sha256)(toHash);
|
|
3614
4135
|
}
|
|
3615
4136
|
function getChainNumericId(chain) {
|
|
3616
4137
|
const id = CHAIN_NUMERIC_IDS[chain];
|
|
@@ -3621,7 +4142,7 @@ function getChainNumericId(chain) {
|
|
|
3621
4142
|
}
|
|
3622
4143
|
function normalizeToBytes(hex, length, field) {
|
|
3623
4144
|
const stripped = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
3624
|
-
const bytes = (0,
|
|
4145
|
+
const bytes = (0, import_utils12.hexToBytes)(stripped);
|
|
3625
4146
|
if (bytes.length === length) {
|
|
3626
4147
|
return bytes;
|
|
3627
4148
|
}
|
|
@@ -3654,9 +4175,9 @@ function bytesToBigint(bytes) {
|
|
|
3654
4175
|
|
|
3655
4176
|
// src/oracle/verification.ts
|
|
3656
4177
|
function deriveOracleId(publicKey) {
|
|
3657
|
-
const keyBytes = typeof publicKey === "string" ? (0,
|
|
3658
|
-
const hash2 = (0,
|
|
3659
|
-
return `0x${(0,
|
|
4178
|
+
const keyBytes = typeof publicKey === "string" ? (0, import_utils13.hexToBytes)(publicKey.startsWith("0x") ? publicKey.slice(2) : publicKey) : publicKey;
|
|
4179
|
+
const hash2 = (0, import_sha25610.sha256)(keyBytes);
|
|
4180
|
+
return `0x${(0, import_utils13.bytesToHex)(hash2)}`;
|
|
3660
4181
|
}
|
|
3661
4182
|
function verifyAttestation(attestation, registry) {
|
|
3662
4183
|
const { message, signatures } = attestation;
|
|
@@ -3686,10 +4207,10 @@ function verifyAttestation(attestation, registry) {
|
|
|
3686
4207
|
continue;
|
|
3687
4208
|
}
|
|
3688
4209
|
try {
|
|
3689
|
-
const publicKeyBytes = (0,
|
|
4210
|
+
const publicKeyBytes = (0, import_utils13.hexToBytes)(
|
|
3690
4211
|
oracle.publicKey.startsWith("0x") ? oracle.publicKey.slice(2) : oracle.publicKey
|
|
3691
4212
|
);
|
|
3692
|
-
const signatureBytes = (0,
|
|
4213
|
+
const signatureBytes = (0, import_utils13.hexToBytes)(
|
|
3693
4214
|
sig.signature.startsWith("0x") ? sig.signature.slice(2) : sig.signature
|
|
3694
4215
|
);
|
|
3695
4216
|
const isValid = import_ed255192.ed25519.verify(signatureBytes, messageHash, publicKeyBytes);
|
|
@@ -3714,10 +4235,10 @@ function verifyAttestation(attestation, registry) {
|
|
|
3714
4235
|
}
|
|
3715
4236
|
function verifyOracleSignature(signature, messageHash, oracle) {
|
|
3716
4237
|
try {
|
|
3717
|
-
const publicKeyBytes = (0,
|
|
4238
|
+
const publicKeyBytes = (0, import_utils13.hexToBytes)(
|
|
3718
4239
|
oracle.publicKey.startsWith("0x") ? oracle.publicKey.slice(2) : oracle.publicKey
|
|
3719
4240
|
);
|
|
3720
|
-
const signatureBytes = (0,
|
|
4241
|
+
const signatureBytes = (0, import_utils13.hexToBytes)(
|
|
3721
4242
|
signature.signature.startsWith("0x") ? signature.signature.slice(2) : signature.signature
|
|
3722
4243
|
);
|
|
3723
4244
|
return import_ed255192.ed25519.verify(signatureBytes, messageHash, publicKeyBytes);
|
|
@@ -3731,7 +4252,7 @@ function signAttestationMessage(messageHash, privateKey) {
|
|
|
3731
4252
|
const oracleId = deriveOracleId(publicKey);
|
|
3732
4253
|
return {
|
|
3733
4254
|
oracleId,
|
|
3734
|
-
signature: `0x${(0,
|
|
4255
|
+
signature: `0x${(0, import_utils13.bytesToHex)(signature)}`
|
|
3735
4256
|
};
|
|
3736
4257
|
}
|
|
3737
4258
|
function createOracleRegistry(config = {}) {
|
|
@@ -3783,14 +4304,14 @@ function hasEnoughOracles(registry) {
|
|
|
3783
4304
|
}
|
|
3784
4305
|
|
|
3785
4306
|
// src/index.ts
|
|
3786
|
-
var
|
|
3787
|
-
var
|
|
3788
|
-
var
|
|
3789
|
-
var
|
|
4307
|
+
var import_types55 = require("@sip-protocol/types");
|
|
4308
|
+
var import_types56 = require("@sip-protocol/types");
|
|
4309
|
+
var import_types57 = require("@sip-protocol/types");
|
|
4310
|
+
var import_types58 = require("@sip-protocol/types");
|
|
3790
4311
|
|
|
3791
4312
|
// src/solver/mock-solver.ts
|
|
3792
4313
|
var import_types7 = require("@sip-protocol/types");
|
|
3793
|
-
var
|
|
4314
|
+
var import_utils14 = require("@noble/hashes/utils");
|
|
3794
4315
|
var MockSolver = class {
|
|
3795
4316
|
info;
|
|
3796
4317
|
capabilities;
|
|
@@ -3872,7 +4393,7 @@ var MockSolver = class {
|
|
|
3872
4393
|
const spreadAmount = baseOutput * BigInt(Math.floor(this.spreadPercent * 1e4)) / 10000n;
|
|
3873
4394
|
const outputAmount = baseOutput + spreadAmount;
|
|
3874
4395
|
const feeAmount = outputAmount * BigInt(Math.floor(this.feePercent * 1e4)) / 10000n;
|
|
3875
|
-
const quoteId = `quote-${(0,
|
|
4396
|
+
const quoteId = `quote-${(0, import_utils14.bytesToHex)((0, import_utils14.randomBytes)(8))}`;
|
|
3876
4397
|
const now = Math.floor(Date.now() / 1e3);
|
|
3877
4398
|
const quote = {
|
|
3878
4399
|
quoteId,
|
|
@@ -3883,7 +4404,7 @@ var MockSolver = class {
|
|
|
3883
4404
|
expiry: now + 60,
|
|
3884
4405
|
// Quote valid for 1 minute
|
|
3885
4406
|
fee: feeAmount,
|
|
3886
|
-
signature: `0x${(0,
|
|
4407
|
+
signature: `0x${(0, import_utils14.bytesToHex)((0, import_utils14.randomBytes)(64))}`,
|
|
3887
4408
|
// Mock signature
|
|
3888
4409
|
validUntil: now + 60,
|
|
3889
4410
|
estimatedGas: 200000n
|
|
@@ -3920,7 +4441,7 @@ var MockSolver = class {
|
|
|
3920
4441
|
error: status.error
|
|
3921
4442
|
};
|
|
3922
4443
|
}
|
|
3923
|
-
const txHash = `0x${(0,
|
|
4444
|
+
const txHash = `0x${(0, import_utils14.bytesToHex)((0, import_utils14.randomBytes)(32))}`;
|
|
3924
4445
|
status.status = "completed";
|
|
3925
4446
|
status.txHash = txHash;
|
|
3926
4447
|
return {
|
|
@@ -3930,10 +4451,10 @@ var MockSolver = class {
|
|
|
3930
4451
|
txHash: intent.privacyLevel === "transparent" ? txHash : void 0,
|
|
3931
4452
|
fulfillmentProof: {
|
|
3932
4453
|
type: "fulfillment",
|
|
3933
|
-
proof: `0x${(0,
|
|
4454
|
+
proof: `0x${(0, import_utils14.bytesToHex)((0, import_utils14.randomBytes)(128))}`,
|
|
3934
4455
|
publicInputs: [
|
|
3935
|
-
`0x${(0,
|
|
3936
|
-
`0x${(0,
|
|
4456
|
+
`0x${(0, import_utils14.bytesToHex)(new TextEncoder().encode(intent.intentId))}`,
|
|
4457
|
+
`0x${(0, import_utils14.bytesToHex)(new TextEncoder().encode(quote.quoteId))}`
|
|
3937
4458
|
]
|
|
3938
4459
|
},
|
|
3939
4460
|
fulfilledAt: Math.floor(Date.now() / 1e3)
|
|
@@ -3971,7 +4492,7 @@ function createMockSolver(config) {
|
|
|
3971
4492
|
}
|
|
3972
4493
|
|
|
3973
4494
|
// src/index.ts
|
|
3974
|
-
var
|
|
4495
|
+
var import_types59 = require("@sip-protocol/types");
|
|
3975
4496
|
|
|
3976
4497
|
// src/settlement/interface.ts
|
|
3977
4498
|
var SwapStatus = /* @__PURE__ */ ((SwapStatus2) => {
|
|
@@ -4699,6 +5220,15 @@ var NEARIntentsBackend = class {
|
|
|
4699
5220
|
"senderAddress"
|
|
4700
5221
|
);
|
|
4701
5222
|
}
|
|
5223
|
+
if (params.slippageTolerance !== void 0) {
|
|
5224
|
+
if (params.slippageTolerance < 0 || params.slippageTolerance > 1e4) {
|
|
5225
|
+
throw new ValidationError(
|
|
5226
|
+
"slippageTolerance must be between 0-10000 basis points (0-100%)",
|
|
5227
|
+
"slippageTolerance",
|
|
5228
|
+
{ provided: params.slippageTolerance, validRange: "0-10000" }
|
|
5229
|
+
);
|
|
5230
|
+
}
|
|
5231
|
+
}
|
|
4702
5232
|
if (!this.capabilities.supportedSourceChains.includes(params.fromChain)) {
|
|
4703
5233
|
throw new ValidationError(
|
|
4704
5234
|
`Source chain ${params.fromChain} is not supported`,
|
|
@@ -5068,7 +5598,7 @@ function createZcashNativeBackend(config) {
|
|
|
5068
5598
|
|
|
5069
5599
|
// src/settlement/backends/direct-chain.ts
|
|
5070
5600
|
var import_types10 = require("@sip-protocol/types");
|
|
5071
|
-
var
|
|
5601
|
+
var import_utils15 = require("@noble/hashes/utils");
|
|
5072
5602
|
var DEFAULT_GAS_FEES = {
|
|
5073
5603
|
ethereum: 21000n * 50n * 1000000000n,
|
|
5074
5604
|
// 21k gas * 50 gwei = 0.00105 ETH
|
|
@@ -5086,8 +5616,24 @@ var DEFAULT_GAS_FEES = {
|
|
|
5086
5616
|
// 21k gas * 0.001 gwei ETH = 21 gwei = 21e6 wei
|
|
5087
5617
|
base: 2100000000n,
|
|
5088
5618
|
// 21k gas * 0.1 gwei ETH = 2100 gwei = 2.1e9 wei
|
|
5089
|
-
bitcoin: 10000n
|
|
5619
|
+
bitcoin: 10000n,
|
|
5090
5620
|
// 10000 sats = 0.0001 BTC (estimate for 1 input, 2 outputs)
|
|
5621
|
+
aptos: 100n,
|
|
5622
|
+
// 0.000001 APT in octas (gas units)
|
|
5623
|
+
sui: 1000n,
|
|
5624
|
+
// 0.000001 SUI in MIST
|
|
5625
|
+
cosmos: 5000n,
|
|
5626
|
+
// 0.005 ATOM in uatom
|
|
5627
|
+
osmosis: 5000n,
|
|
5628
|
+
// 0.005 OSMO in uosmo
|
|
5629
|
+
injective: 5000n,
|
|
5630
|
+
// 0.000005 INJ in inj (18 decimals)
|
|
5631
|
+
celestia: 5000n,
|
|
5632
|
+
// 0.005 TIA in utia
|
|
5633
|
+
sei: 5000n,
|
|
5634
|
+
// 0.005 SEI in usei
|
|
5635
|
+
dydx: 5000n
|
|
5636
|
+
// 0.000005 DYDX in dydx (18 decimals)
|
|
5091
5637
|
};
|
|
5092
5638
|
|
|
5093
5639
|
// src/zcash/rpc-client.ts
|
|
@@ -6372,12 +6918,300 @@ function createZcashSwapService(config) {
|
|
|
6372
6918
|
var import_types14 = require("@sip-protocol/types");
|
|
6373
6919
|
|
|
6374
6920
|
// src/index.ts
|
|
6375
|
-
var
|
|
6921
|
+
var import_types60 = require("@sip-protocol/types");
|
|
6922
|
+
|
|
6923
|
+
// src/bitcoin/taproot.ts
|
|
6924
|
+
var import_secp256k14 = require("@noble/curves/secp256k1");
|
|
6925
|
+
var import_sha25611 = require("@noble/hashes/sha256");
|
|
6926
|
+
var import_utils16 = require("@noble/hashes/utils");
|
|
6927
|
+
var BECH32_CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
|
|
6928
|
+
var BECH32_GENERATOR = [996825010, 642813549, 513874426, 1027748829, 705979059];
|
|
6929
|
+
function taggedHash(tag, data) {
|
|
6930
|
+
const tagHash = (0, import_sha25611.sha256)(new TextEncoder().encode(tag));
|
|
6931
|
+
const taggedData = new Uint8Array(tagHash.length * 2 + data.length);
|
|
6932
|
+
taggedData.set(tagHash, 0);
|
|
6933
|
+
taggedData.set(tagHash, tagHash.length);
|
|
6934
|
+
taggedData.set(data, tagHash.length * 2);
|
|
6935
|
+
return (0, import_sha25611.sha256)(taggedData);
|
|
6936
|
+
}
|
|
6937
|
+
function schnorrSign(message, privateKey, auxRand) {
|
|
6938
|
+
if (message.length !== 32) {
|
|
6939
|
+
throw new ValidationError("message must be 32 bytes", "message");
|
|
6940
|
+
}
|
|
6941
|
+
if (privateKey.length !== 32) {
|
|
6942
|
+
throw new ValidationError("privateKey must be 32 bytes", "privateKey");
|
|
6943
|
+
}
|
|
6944
|
+
if (auxRand && auxRand.length !== 32) {
|
|
6945
|
+
throw new ValidationError("auxRand must be 32 bytes if provided", "auxRand");
|
|
6946
|
+
}
|
|
6947
|
+
return import_secp256k14.schnorr.sign(message, privateKey, auxRand);
|
|
6948
|
+
}
|
|
6949
|
+
function schnorrVerify(signature, message, publicKey) {
|
|
6950
|
+
if (signature.length !== 64) {
|
|
6951
|
+
throw new ValidationError("signature must be 64 bytes", "signature");
|
|
6952
|
+
}
|
|
6953
|
+
if (message.length !== 32) {
|
|
6954
|
+
throw new ValidationError("message must be 32 bytes", "message");
|
|
6955
|
+
}
|
|
6956
|
+
if (publicKey.length !== 32) {
|
|
6957
|
+
throw new ValidationError("publicKey must be 32 bytes (x-only)", "publicKey");
|
|
6958
|
+
}
|
|
6959
|
+
try {
|
|
6960
|
+
return import_secp256k14.schnorr.verify(signature, message, publicKey);
|
|
6961
|
+
} catch {
|
|
6962
|
+
return false;
|
|
6963
|
+
}
|
|
6964
|
+
}
|
|
6965
|
+
function getXOnlyPublicKey(privateKey) {
|
|
6966
|
+
if (privateKey.length !== 32) {
|
|
6967
|
+
throw new ValidationError("privateKey must be 32 bytes", "privateKey");
|
|
6968
|
+
}
|
|
6969
|
+
const publicKey = import_secp256k14.secp256k1.getPublicKey(privateKey, false);
|
|
6970
|
+
return publicKey.slice(1, 33);
|
|
6971
|
+
}
|
|
6972
|
+
function computeTweakedKey(internalKey, merkleRoot) {
|
|
6973
|
+
if (internalKey.length !== 32) {
|
|
6974
|
+
throw new ValidationError("internalKey must be 32 bytes (x-only)", "internalKey");
|
|
6975
|
+
}
|
|
6976
|
+
if (merkleRoot && merkleRoot.length !== 32) {
|
|
6977
|
+
throw new ValidationError("merkleRoot must be 32 bytes if provided", "merkleRoot");
|
|
6978
|
+
}
|
|
6979
|
+
const tweakData = merkleRoot ? new Uint8Array([...internalKey, ...merkleRoot]) : internalKey;
|
|
6980
|
+
const tweak = taggedHash("TapTweak", tweakData);
|
|
6981
|
+
const tweakScalar = BigInt("0x" + (0, import_utils16.bytesToHex)(tweak)) % import_secp256k14.secp256k1.CURVE.n;
|
|
6982
|
+
const internalPoint = import_secp256k14.secp256k1.ProjectivePoint.fromHex(
|
|
6983
|
+
"02" + (0, import_utils16.bytesToHex)(internalKey)
|
|
6984
|
+
);
|
|
6985
|
+
const tweakPoint = import_secp256k14.secp256k1.ProjectivePoint.BASE.multiply(tweakScalar);
|
|
6986
|
+
const tweakedPoint = internalPoint.add(tweakPoint);
|
|
6987
|
+
const tweakedKeyBytes = tweakedPoint.toRawBytes(false);
|
|
6988
|
+
const xOnly = tweakedKeyBytes.slice(1, 33);
|
|
6989
|
+
const yCoord = tweakedKeyBytes.slice(33, 65);
|
|
6990
|
+
const yBigInt = BigInt("0x" + (0, import_utils16.bytesToHex)(yCoord));
|
|
6991
|
+
const parity = Number(yBigInt & 1n);
|
|
6992
|
+
return {
|
|
6993
|
+
tweakedKey: xOnly,
|
|
6994
|
+
parity
|
|
6995
|
+
};
|
|
6996
|
+
}
|
|
6997
|
+
function createTaprootOutput(internalKey, scripts) {
|
|
6998
|
+
if (internalKey.length !== 32) {
|
|
6999
|
+
throw new ValidationError("internalKey must be 32 bytes (x-only)", "internalKey");
|
|
7000
|
+
}
|
|
7001
|
+
let merkleRoot;
|
|
7002
|
+
if (scripts && scripts.length > 0) {
|
|
7003
|
+
if (scripts.length === 1) {
|
|
7004
|
+
const script = scripts[0];
|
|
7005
|
+
const leafData = new Uint8Array([
|
|
7006
|
+
script.leafVersion,
|
|
7007
|
+
script.script.length,
|
|
7008
|
+
...script.script
|
|
7009
|
+
]);
|
|
7010
|
+
merkleRoot = taggedHash("TapLeaf", leafData);
|
|
7011
|
+
} else {
|
|
7012
|
+
throw new ValidationError(
|
|
7013
|
+
"Multiple tapscripts not yet implemented - use single script or no scripts",
|
|
7014
|
+
"scripts"
|
|
7015
|
+
);
|
|
7016
|
+
}
|
|
7017
|
+
}
|
|
7018
|
+
const { tweakedKey, parity } = computeTweakedKey(internalKey, merkleRoot);
|
|
7019
|
+
return {
|
|
7020
|
+
tweakedKey: `0x${(0, import_utils16.bytesToHex)(tweakedKey)}`,
|
|
7021
|
+
internalKey: `0x${(0, import_utils16.bytesToHex)(internalKey)}`,
|
|
7022
|
+
merkleRoot: merkleRoot ? `0x${(0, import_utils16.bytesToHex)(merkleRoot)}` : void 0,
|
|
7023
|
+
parity
|
|
7024
|
+
};
|
|
7025
|
+
}
|
|
7026
|
+
function bech32Polymod(values) {
|
|
7027
|
+
let chk = 1;
|
|
7028
|
+
for (const value of values) {
|
|
7029
|
+
const top = chk >> 25;
|
|
7030
|
+
chk = (chk & 33554431) << 5 ^ value;
|
|
7031
|
+
for (let i = 0; i < 5; i++) {
|
|
7032
|
+
if (top >> i & 1) {
|
|
7033
|
+
chk ^= BECH32_GENERATOR[i];
|
|
7034
|
+
}
|
|
7035
|
+
}
|
|
7036
|
+
}
|
|
7037
|
+
return chk;
|
|
7038
|
+
}
|
|
7039
|
+
function bech32HrpExpand(hrp) {
|
|
7040
|
+
const result = [];
|
|
7041
|
+
for (let i = 0; i < hrp.length; i++) {
|
|
7042
|
+
result.push(hrp.charCodeAt(i) >> 5);
|
|
7043
|
+
}
|
|
7044
|
+
result.push(0);
|
|
7045
|
+
for (let i = 0; i < hrp.length; i++) {
|
|
7046
|
+
result.push(hrp.charCodeAt(i) & 31);
|
|
7047
|
+
}
|
|
7048
|
+
return result;
|
|
7049
|
+
}
|
|
7050
|
+
function bech32VerifyChecksum(hrp, data) {
|
|
7051
|
+
return bech32Polymod([...bech32HrpExpand(hrp), ...data]) === 734539939;
|
|
7052
|
+
}
|
|
7053
|
+
function bech32CreateChecksum(hrp, data) {
|
|
7054
|
+
const values = [...bech32HrpExpand(hrp), ...data, 0, 0, 0, 0, 0, 0];
|
|
7055
|
+
const polymod = bech32Polymod(values) ^ 734539939;
|
|
7056
|
+
const checksum = [];
|
|
7057
|
+
for (let i = 0; i < 6; i++) {
|
|
7058
|
+
checksum.push(polymod >> 5 * (5 - i) & 31);
|
|
7059
|
+
}
|
|
7060
|
+
return checksum;
|
|
7061
|
+
}
|
|
7062
|
+
function convertBits(data, fromBits, toBits, pad) {
|
|
7063
|
+
let acc = 0;
|
|
7064
|
+
let bits = 0;
|
|
7065
|
+
const result = [];
|
|
7066
|
+
const maxv = (1 << toBits) - 1;
|
|
7067
|
+
for (const value of data) {
|
|
7068
|
+
if (value < 0 || value >> fromBits !== 0) {
|
|
7069
|
+
return null;
|
|
7070
|
+
}
|
|
7071
|
+
acc = acc << fromBits | value;
|
|
7072
|
+
bits += fromBits;
|
|
7073
|
+
while (bits >= toBits) {
|
|
7074
|
+
bits -= toBits;
|
|
7075
|
+
result.push(acc >> bits & maxv);
|
|
7076
|
+
}
|
|
7077
|
+
}
|
|
7078
|
+
if (pad) {
|
|
7079
|
+
if (bits > 0) {
|
|
7080
|
+
result.push(acc << toBits - bits & maxv);
|
|
7081
|
+
}
|
|
7082
|
+
} else if (bits >= fromBits || acc << toBits - bits & maxv) {
|
|
7083
|
+
return null;
|
|
7084
|
+
}
|
|
7085
|
+
return result;
|
|
7086
|
+
}
|
|
7087
|
+
function taprootAddress(tweakedKey, network = "mainnet") {
|
|
7088
|
+
if (tweakedKey.length !== 32) {
|
|
7089
|
+
throw new ValidationError("tweakedKey must be 32 bytes", "tweakedKey");
|
|
7090
|
+
}
|
|
7091
|
+
const hrp = network === "mainnet" ? "bc" : network === "testnet" ? "tb" : "bcrt";
|
|
7092
|
+
const version = 1;
|
|
7093
|
+
const words = convertBits(tweakedKey, 8, 5, true);
|
|
7094
|
+
if (!words) {
|
|
7095
|
+
throw new ValidationError("Failed to convert tweaked key to bech32 format", "tweakedKey");
|
|
7096
|
+
}
|
|
7097
|
+
const data = [version, ...words];
|
|
7098
|
+
const checksum = bech32CreateChecksum(hrp, data);
|
|
7099
|
+
const combined = [...data, ...checksum];
|
|
7100
|
+
let result = hrp + "1";
|
|
7101
|
+
for (const value of combined) {
|
|
7102
|
+
result += BECH32_CHARSET[value];
|
|
7103
|
+
}
|
|
7104
|
+
return result;
|
|
7105
|
+
}
|
|
7106
|
+
function decodeTaprootAddress(address) {
|
|
7107
|
+
if (typeof address !== "string" || address.length < 14 || address.length > 90) {
|
|
7108
|
+
throw new ValidationError("Invalid Taproot address format", "address");
|
|
7109
|
+
}
|
|
7110
|
+
const addressLower = address.toLowerCase();
|
|
7111
|
+
const sepIndex = addressLower.lastIndexOf("1");
|
|
7112
|
+
if (sepIndex === -1 || sepIndex + 7 > addressLower.length) {
|
|
7113
|
+
throw new ValidationError("Invalid Taproot address: no separator", "address");
|
|
7114
|
+
}
|
|
7115
|
+
const hrp = addressLower.slice(0, sepIndex);
|
|
7116
|
+
const dataStr = addressLower.slice(sepIndex + 1);
|
|
7117
|
+
let network;
|
|
7118
|
+
if (hrp === "bc") {
|
|
7119
|
+
network = "mainnet";
|
|
7120
|
+
} else if (hrp === "tb") {
|
|
7121
|
+
network = "testnet";
|
|
7122
|
+
} else if (hrp === "bcrt") {
|
|
7123
|
+
network = "regtest";
|
|
7124
|
+
} else {
|
|
7125
|
+
throw new ValidationError(`Unknown HRP: ${hrp}`, "address");
|
|
7126
|
+
}
|
|
7127
|
+
const data = [];
|
|
7128
|
+
for (const char of dataStr) {
|
|
7129
|
+
const index = BECH32_CHARSET.indexOf(char);
|
|
7130
|
+
if (index === -1) {
|
|
7131
|
+
throw new ValidationError(`Invalid bech32 character: ${char}`, "address");
|
|
7132
|
+
}
|
|
7133
|
+
data.push(index);
|
|
7134
|
+
}
|
|
7135
|
+
if (!bech32VerifyChecksum(hrp, data)) {
|
|
7136
|
+
throw new ValidationError("Invalid Taproot address checksum", "address");
|
|
7137
|
+
}
|
|
7138
|
+
const version = data[0];
|
|
7139
|
+
if (version !== 1) {
|
|
7140
|
+
throw new ValidationError(`Expected witness version 1 (Taproot), got ${version}`, "address");
|
|
7141
|
+
}
|
|
7142
|
+
const program = convertBits(new Uint8Array(data.slice(1, -6)), 5, 8, false);
|
|
7143
|
+
if (!program || program.length !== 32) {
|
|
7144
|
+
throw new ValidationError("Invalid Taproot program length", "address");
|
|
7145
|
+
}
|
|
7146
|
+
return {
|
|
7147
|
+
tweakedKey: new Uint8Array(program),
|
|
7148
|
+
network
|
|
7149
|
+
};
|
|
7150
|
+
}
|
|
7151
|
+
function createKeySpendOnlyOutput(privateKey, network = "mainnet") {
|
|
7152
|
+
if (!isValidPrivateKey(privateKey)) {
|
|
7153
|
+
throw new ValidationError("privateKey must be a valid 32-byte hex string", "privateKey");
|
|
7154
|
+
}
|
|
7155
|
+
const privKeyBytes = (0, import_utils16.hexToBytes)(privateKey.slice(2));
|
|
7156
|
+
const internalKey = getXOnlyPublicKey(privKeyBytes);
|
|
7157
|
+
const output = createTaprootOutput(internalKey);
|
|
7158
|
+
const tweakedKeyBytes = (0, import_utils16.hexToBytes)(output.tweakedKey.slice(2));
|
|
7159
|
+
const address = taprootAddress(tweakedKeyBytes, network);
|
|
7160
|
+
return {
|
|
7161
|
+
output,
|
|
7162
|
+
address,
|
|
7163
|
+
internalPrivateKey: privateKey
|
|
7164
|
+
};
|
|
7165
|
+
}
|
|
7166
|
+
function isValidTaprootAddress(address) {
|
|
7167
|
+
try {
|
|
7168
|
+
decodeTaprootAddress(address);
|
|
7169
|
+
return true;
|
|
7170
|
+
} catch {
|
|
7171
|
+
return false;
|
|
7172
|
+
}
|
|
7173
|
+
}
|
|
7174
|
+
function schnorrSignHex(message, privateKey, auxRand) {
|
|
7175
|
+
if (!isValidHex(message)) {
|
|
7176
|
+
throw new ValidationError("message must be a hex string", "message");
|
|
7177
|
+
}
|
|
7178
|
+
if (!isValidPrivateKey(privateKey)) {
|
|
7179
|
+
throw new ValidationError("privateKey must be a valid 32-byte hex string", "privateKey");
|
|
7180
|
+
}
|
|
7181
|
+
if (auxRand && !isValidHex(auxRand)) {
|
|
7182
|
+
throw new ValidationError("auxRand must be a hex string", "auxRand");
|
|
7183
|
+
}
|
|
7184
|
+
const messageBytes = (0, import_utils16.hexToBytes)(message.slice(2));
|
|
7185
|
+
const privateKeyBytes = (0, import_utils16.hexToBytes)(privateKey.slice(2));
|
|
7186
|
+
const auxRandBytes = auxRand ? (0, import_utils16.hexToBytes)(auxRand.slice(2)) : void 0;
|
|
7187
|
+
const signature = schnorrSign(messageBytes, privateKeyBytes, auxRandBytes);
|
|
7188
|
+
return `0x${(0, import_utils16.bytesToHex)(signature)}`;
|
|
7189
|
+
}
|
|
7190
|
+
function schnorrVerifyHex(signature, message, publicKey) {
|
|
7191
|
+
if (!isValidHex(signature)) {
|
|
7192
|
+
throw new ValidationError("signature must be a hex string", "signature");
|
|
7193
|
+
}
|
|
7194
|
+
if (!isValidHex(message)) {
|
|
7195
|
+
throw new ValidationError("message must be a hex string", "message");
|
|
7196
|
+
}
|
|
7197
|
+
if (!isValidHex(publicKey)) {
|
|
7198
|
+
throw new ValidationError("publicKey must be a hex string", "publicKey");
|
|
7199
|
+
}
|
|
7200
|
+
const signatureBytes = (0, import_utils16.hexToBytes)(signature.slice(2));
|
|
7201
|
+
const messageBytes = (0, import_utils16.hexToBytes)(message.slice(2));
|
|
7202
|
+
const publicKeyBytes = (0, import_utils16.hexToBytes)(publicKey.slice(2));
|
|
7203
|
+
return schnorrVerify(signatureBytes, messageBytes, publicKeyBytes);
|
|
7204
|
+
}
|
|
7205
|
+
|
|
7206
|
+
// src/bitcoin/silent-payments.ts
|
|
7207
|
+
var import_secp256k15 = require("@noble/curves/secp256k1");
|
|
7208
|
+
var import_sha25612 = require("@noble/hashes/sha256");
|
|
7209
|
+
var import_utils17 = require("@noble/hashes/utils");
|
|
6376
7210
|
|
|
6377
7211
|
// src/payment/payment.ts
|
|
6378
7212
|
var import_types15 = require("@sip-protocol/types");
|
|
6379
|
-
var
|
|
6380
|
-
var
|
|
7213
|
+
var import_sha25613 = require("@noble/hashes/sha256");
|
|
7214
|
+
var import_utils18 = require("@noble/hashes/utils");
|
|
6381
7215
|
var import_chacha2 = require("@noble/ciphers/chacha.js");
|
|
6382
7216
|
var import_hkdf2 = require("@noble/hashes/hkdf");
|
|
6383
7217
|
|
|
@@ -6873,8 +7707,8 @@ async function createShieldedPayment(params, options) {
|
|
|
6873
7707
|
let viewingKeyHash;
|
|
6874
7708
|
if (viewingKey) {
|
|
6875
7709
|
const keyHex = viewingKey.startsWith("0x") ? viewingKey.slice(2) : viewingKey;
|
|
6876
|
-
const keyBytes = (0,
|
|
6877
|
-
viewingKeyHash = `0x${(0,
|
|
7710
|
+
const keyBytes = (0, import_utils18.hexToBytes)(keyHex);
|
|
7711
|
+
viewingKeyHash = `0x${(0, import_utils18.bytesToHex)((0, import_sha25613.sha256)(keyBytes))}`;
|
|
6878
7712
|
}
|
|
6879
7713
|
const privacyConfig = getPrivacyConfig(
|
|
6880
7714
|
privacy,
|
|
@@ -6914,7 +7748,7 @@ async function createShieldedPayment(params, options) {
|
|
|
6914
7748
|
if (privacy !== import_types15.PrivacyLevel.TRANSPARENT && proofProvider?.isReady) {
|
|
6915
7749
|
const hexToUint8 = (hex) => {
|
|
6916
7750
|
const cleanHex = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
6917
|
-
return (0,
|
|
7751
|
+
return (0, import_utils18.hexToBytes)(cleanHex);
|
|
6918
7752
|
};
|
|
6919
7753
|
const fundingResult = await proofProvider.generateFundingProof({
|
|
6920
7754
|
balance: amount,
|
|
@@ -6941,17 +7775,17 @@ async function createShieldedPayment(params, options) {
|
|
|
6941
7775
|
}
|
|
6942
7776
|
function encryptMemo(memo, viewingKey) {
|
|
6943
7777
|
const keyHex = viewingKey.startsWith("0x") ? viewingKey.slice(2) : viewingKey;
|
|
6944
|
-
const keyBytes = (0,
|
|
6945
|
-
const encKey = (0, import_hkdf2.hkdf)(
|
|
7778
|
+
const keyBytes = (0, import_utils18.hexToBytes)(keyHex);
|
|
7779
|
+
const encKey = (0, import_hkdf2.hkdf)(import_sha25613.sha256, keyBytes, new Uint8Array(0), new Uint8Array(0), 32);
|
|
6946
7780
|
try {
|
|
6947
|
-
const nonce = (0,
|
|
7781
|
+
const nonce = (0, import_utils18.randomBytes)(24);
|
|
6948
7782
|
const cipher = (0, import_chacha2.xchacha20poly1305)(encKey, nonce);
|
|
6949
7783
|
const plaintext = new TextEncoder().encode(memo);
|
|
6950
7784
|
const ciphertext = cipher.encrypt(plaintext);
|
|
6951
7785
|
const result = new Uint8Array(nonce.length + ciphertext.length);
|
|
6952
7786
|
result.set(nonce);
|
|
6953
7787
|
result.set(ciphertext, nonce.length);
|
|
6954
|
-
return `0x${(0,
|
|
7788
|
+
return `0x${(0, import_utils18.bytesToHex)(result)}`;
|
|
6955
7789
|
} finally {
|
|
6956
7790
|
secureWipe(keyBytes);
|
|
6957
7791
|
secureWipe(encKey);
|
|
@@ -6959,11 +7793,11 @@ function encryptMemo(memo, viewingKey) {
|
|
|
6959
7793
|
}
|
|
6960
7794
|
function decryptMemo(encryptedMemo, viewingKey) {
|
|
6961
7795
|
const keyHex = viewingKey.startsWith("0x") ? viewingKey.slice(2) : viewingKey;
|
|
6962
|
-
const keyBytes = (0,
|
|
6963
|
-
const encKey = (0, import_hkdf2.hkdf)(
|
|
7796
|
+
const keyBytes = (0, import_utils18.hexToBytes)(keyHex);
|
|
7797
|
+
const encKey = (0, import_hkdf2.hkdf)(import_sha25613.sha256, keyBytes, new Uint8Array(0), new Uint8Array(0), 32);
|
|
6964
7798
|
try {
|
|
6965
7799
|
const dataHex = encryptedMemo.startsWith("0x") ? encryptedMemo.slice(2) : encryptedMemo;
|
|
6966
|
-
const data = (0,
|
|
7800
|
+
const data = (0, import_utils18.hexToBytes)(dataHex);
|
|
6967
7801
|
const nonce = data.slice(0, 24);
|
|
6968
7802
|
const ciphertext = data.slice(24);
|
|
6969
7803
|
const cipher = (0, import_chacha2.xchacha20poly1305)(encKey, nonce);
|
|
@@ -7011,9 +7845,9 @@ function getPaymentSummary(payment) {
|
|
|
7011
7845
|
|
|
7012
7846
|
// src/treasury/treasury.ts
|
|
7013
7847
|
var import_types16 = require("@sip-protocol/types");
|
|
7014
|
-
var
|
|
7015
|
-
var
|
|
7016
|
-
var
|
|
7848
|
+
var import_secp256k16 = require("@noble/curves/secp256k1");
|
|
7849
|
+
var import_sha25614 = require("@noble/hashes/sha256");
|
|
7850
|
+
var import_utils19 = require("@noble/hashes/utils");
|
|
7017
7851
|
var DEFAULT_PROPOSAL_TTL = 7 * 24 * 60 * 60;
|
|
7018
7852
|
var Treasury = class _Treasury {
|
|
7019
7853
|
config;
|
|
@@ -7504,12 +8338,12 @@ var Treasury = class _Treasury {
|
|
|
7504
8338
|
}
|
|
7505
8339
|
};
|
|
7506
8340
|
function generateTreasuryId() {
|
|
7507
|
-
const bytes = (0,
|
|
7508
|
-
return `treasury_${(0,
|
|
8341
|
+
const bytes = (0, import_utils19.randomBytes)(16);
|
|
8342
|
+
return `treasury_${(0, import_utils19.bytesToHex)(bytes)}`;
|
|
7509
8343
|
}
|
|
7510
8344
|
function generateProposalId() {
|
|
7511
|
-
const bytes = (0,
|
|
7512
|
-
return `prop_${(0,
|
|
8345
|
+
const bytes = (0, import_utils19.randomBytes)(16);
|
|
8346
|
+
return `prop_${(0, import_utils19.bytesToHex)(bytes)}`;
|
|
7513
8347
|
}
|
|
7514
8348
|
function computeProposalHash(proposal) {
|
|
7515
8349
|
const data = JSON.stringify({
|
|
@@ -7521,13 +8355,13 @@ function computeProposalHash(proposal) {
|
|
|
7521
8355
|
createdAt: proposal.createdAt,
|
|
7522
8356
|
expiresAt: proposal.expiresAt
|
|
7523
8357
|
}, (_, value) => typeof value === "bigint" ? value.toString() : value);
|
|
7524
|
-
return (0,
|
|
8358
|
+
return (0, import_sha25614.sha256)(new TextEncoder().encode(data));
|
|
7525
8359
|
}
|
|
7526
8360
|
function signMessage(messageHash, privateKey) {
|
|
7527
8361
|
const keyHex = privateKey.startsWith("0x") ? privateKey.slice(2) : privateKey;
|
|
7528
|
-
const keyBytes = (0,
|
|
8362
|
+
const keyBytes = (0, import_utils19.hexToBytes)(keyHex);
|
|
7529
8363
|
try {
|
|
7530
|
-
const signature =
|
|
8364
|
+
const signature = import_secp256k16.secp256k1.sign(messageHash, keyBytes);
|
|
7531
8365
|
return `0x${signature.toCompactHex()}`;
|
|
7532
8366
|
} finally {
|
|
7533
8367
|
secureWipe(keyBytes);
|
|
@@ -7537,9 +8371,9 @@ function verifySignature(messageHash, signature, publicKey) {
|
|
|
7537
8371
|
const sigHex = signature.startsWith("0x") ? signature.slice(2) : signature;
|
|
7538
8372
|
const pubKeyHex = publicKey.startsWith("0x") ? publicKey.slice(2) : publicKey;
|
|
7539
8373
|
try {
|
|
7540
|
-
const sigBytes = (0,
|
|
7541
|
-
const pubKeyBytes = (0,
|
|
7542
|
-
return
|
|
8374
|
+
const sigBytes = (0, import_utils19.hexToBytes)(sigHex);
|
|
8375
|
+
const pubKeyBytes = (0, import_utils19.hexToBytes)(pubKeyHex);
|
|
8376
|
+
return import_secp256k16.secp256k1.verify(sigBytes, messageHash, pubKeyBytes);
|
|
7543
8377
|
} catch {
|
|
7544
8378
|
return false;
|
|
7545
8379
|
}
|
|
@@ -7697,7 +8531,7 @@ function validateBatchProposalParams(params, config) {
|
|
|
7697
8531
|
|
|
7698
8532
|
// src/compliance/compliance-manager.ts
|
|
7699
8533
|
var import_types17 = require("@sip-protocol/types");
|
|
7700
|
-
var
|
|
8534
|
+
var import_utils20 = require("@noble/hashes/utils");
|
|
7701
8535
|
var DEFAULTS2 = {
|
|
7702
8536
|
riskThreshold: 70,
|
|
7703
8537
|
highValueThreshold: 10000000000n,
|
|
@@ -8371,7 +9205,7 @@ var ComplianceManager = class _ComplianceManager {
|
|
|
8371
9205
|
}
|
|
8372
9206
|
};
|
|
8373
9207
|
function generateId(prefix) {
|
|
8374
|
-
return `${prefix}_${(0,
|
|
9208
|
+
return `${prefix}_${(0, import_utils20.bytesToHex)((0, import_utils20.randomBytes)(12))}`;
|
|
8375
9209
|
}
|
|
8376
9210
|
function validateRegisterAuditorParams(params) {
|
|
8377
9211
|
if (!params.organization?.trim()) {
|
|
@@ -10615,6 +11449,30 @@ function createMockEthereumProvider(config = {}) {
|
|
|
10615
11449
|
return provider;
|
|
10616
11450
|
}
|
|
10617
11451
|
|
|
11452
|
+
// src/wallet/cosmos/adapter.ts
|
|
11453
|
+
var import_types29 = require("@sip-protocol/types");
|
|
11454
|
+
|
|
11455
|
+
// src/wallet/cosmos/mock.ts
|
|
11456
|
+
var import_types31 = require("@sip-protocol/types");
|
|
11457
|
+
|
|
11458
|
+
// src/wallet/bitcoin/adapter.ts
|
|
11459
|
+
var import_types34 = require("@sip-protocol/types");
|
|
11460
|
+
|
|
11461
|
+
// src/wallet/bitcoin/mock.ts
|
|
11462
|
+
var import_types36 = require("@sip-protocol/types");
|
|
11463
|
+
|
|
11464
|
+
// src/wallet/aptos/adapter.ts
|
|
11465
|
+
var import_types39 = require("@sip-protocol/types");
|
|
11466
|
+
|
|
11467
|
+
// src/wallet/aptos/mock.ts
|
|
11468
|
+
var import_types41 = require("@sip-protocol/types");
|
|
11469
|
+
|
|
11470
|
+
// src/wallet/sui/adapter.ts
|
|
11471
|
+
var import_types43 = require("@sip-protocol/types");
|
|
11472
|
+
|
|
11473
|
+
// src/wallet/sui/mock.ts
|
|
11474
|
+
var import_types45 = require("@sip-protocol/types");
|
|
11475
|
+
|
|
10618
11476
|
// src/wallet/hardware/types.ts
|
|
10619
11477
|
var DerivationPath = {
|
|
10620
11478
|
/** Ethereum: m/44'/60'/0'/0/index */
|
|
@@ -10690,7 +11548,7 @@ function getAvailableTransports() {
|
|
|
10690
11548
|
}
|
|
10691
11549
|
|
|
10692
11550
|
// src/wallet/hardware/ledger.ts
|
|
10693
|
-
var
|
|
11551
|
+
var import_types47 = require("@sip-protocol/types");
|
|
10694
11552
|
var LedgerWalletAdapter = class extends BaseWalletAdapter {
|
|
10695
11553
|
chain;
|
|
10696
11554
|
name = "ledger";
|
|
@@ -10843,7 +11701,7 @@ var LedgerWalletAdapter = class extends BaseWalletAdapter {
|
|
|
10843
11701
|
async getBalance() {
|
|
10844
11702
|
throw new WalletError(
|
|
10845
11703
|
"Hardware wallets do not track balances. Use an RPC provider.",
|
|
10846
|
-
|
|
11704
|
+
import_types47.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
10847
11705
|
);
|
|
10848
11706
|
}
|
|
10849
11707
|
/**
|
|
@@ -10854,7 +11712,7 @@ var LedgerWalletAdapter = class extends BaseWalletAdapter {
|
|
|
10854
11712
|
async getTokenBalance(_asset) {
|
|
10855
11713
|
throw new WalletError(
|
|
10856
11714
|
"Hardware wallets do not track balances. Use an RPC provider.",
|
|
10857
|
-
|
|
11715
|
+
import_types47.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
10858
11716
|
);
|
|
10859
11717
|
}
|
|
10860
11718
|
// ─── Account Management ─────────────────────────────────────────────────────
|
|
@@ -11142,7 +12000,7 @@ function createLedgerAdapter(config) {
|
|
|
11142
12000
|
}
|
|
11143
12001
|
|
|
11144
12002
|
// src/wallet/hardware/trezor.ts
|
|
11145
|
-
var
|
|
12003
|
+
var import_types49 = require("@sip-protocol/types");
|
|
11146
12004
|
var TrezorWalletAdapter = class extends BaseWalletAdapter {
|
|
11147
12005
|
chain;
|
|
11148
12006
|
name = "trezor";
|
|
@@ -11288,7 +12146,7 @@ var TrezorWalletAdapter = class extends BaseWalletAdapter {
|
|
|
11288
12146
|
async getBalance() {
|
|
11289
12147
|
throw new WalletError(
|
|
11290
12148
|
"Hardware wallets do not track balances. Use an RPC provider.",
|
|
11291
|
-
|
|
12149
|
+
import_types49.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
11292
12150
|
);
|
|
11293
12151
|
}
|
|
11294
12152
|
/**
|
|
@@ -11299,7 +12157,7 @@ var TrezorWalletAdapter = class extends BaseWalletAdapter {
|
|
|
11299
12157
|
async getTokenBalance(_asset) {
|
|
11300
12158
|
throw new WalletError(
|
|
11301
12159
|
"Hardware wallets do not track balances. Use an RPC provider.",
|
|
11302
|
-
|
|
12160
|
+
import_types49.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
11303
12161
|
);
|
|
11304
12162
|
}
|
|
11305
12163
|
// ─── Account Management ─────────────────────────────────────────────────────
|
|
@@ -11580,8 +12438,8 @@ function createTrezorAdapter(config) {
|
|
|
11580
12438
|
}
|
|
11581
12439
|
|
|
11582
12440
|
// src/wallet/hardware/mock.ts
|
|
11583
|
-
var
|
|
11584
|
-
var
|
|
12441
|
+
var import_types51 = require("@sip-protocol/types");
|
|
12442
|
+
var import_utils21 = require("@noble/hashes/utils");
|
|
11585
12443
|
var MockLedgerAdapter = class extends BaseWalletAdapter {
|
|
11586
12444
|
chain;
|
|
11587
12445
|
name = "mock-ledger";
|
|
@@ -11728,7 +12586,7 @@ var MockLedgerAdapter = class extends BaseWalletAdapter {
|
|
|
11728
12586
|
async getBalance() {
|
|
11729
12587
|
throw new WalletError(
|
|
11730
12588
|
"Hardware wallets do not track balances",
|
|
11731
|
-
|
|
12589
|
+
import_types51.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
11732
12590
|
);
|
|
11733
12591
|
}
|
|
11734
12592
|
/**
|
|
@@ -11737,7 +12595,7 @@ var MockLedgerAdapter = class extends BaseWalletAdapter {
|
|
|
11737
12595
|
async getTokenBalance(_asset) {
|
|
11738
12596
|
throw new WalletError(
|
|
11739
12597
|
"Hardware wallets do not track balances",
|
|
11740
|
-
|
|
12598
|
+
import_types51.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
11741
12599
|
);
|
|
11742
12600
|
}
|
|
11743
12601
|
/**
|
|
@@ -11826,15 +12684,15 @@ var MockLedgerAdapter = class extends BaseWalletAdapter {
|
|
|
11826
12684
|
}
|
|
11827
12685
|
}
|
|
11828
12686
|
generateMockAddress(index) {
|
|
11829
|
-
const bytes = (0,
|
|
12687
|
+
const bytes = (0, import_utils21.randomBytes)(20);
|
|
11830
12688
|
bytes[0] = index;
|
|
11831
|
-
return `0x${(0,
|
|
12689
|
+
return `0x${(0, import_utils21.bytesToHex)(bytes)}`;
|
|
11832
12690
|
}
|
|
11833
12691
|
generateMockPublicKey(index) {
|
|
11834
|
-
const bytes = (0,
|
|
12692
|
+
const bytes = (0, import_utils21.randomBytes)(33);
|
|
11835
12693
|
bytes[0] = 2;
|
|
11836
12694
|
bytes[1] = index;
|
|
11837
|
-
return `0x${(0,
|
|
12695
|
+
return `0x${(0, import_utils21.bytesToHex)(bytes)}`;
|
|
11838
12696
|
}
|
|
11839
12697
|
generateMockSignature(data) {
|
|
11840
12698
|
const sig = new Uint8Array(65);
|
|
@@ -11843,7 +12701,7 @@ var MockLedgerAdapter = class extends BaseWalletAdapter {
|
|
|
11843
12701
|
sig[32 + i] = (data[i % data.length] ?? 0) ^ i * 11;
|
|
11844
12702
|
}
|
|
11845
12703
|
sig[64] = 27;
|
|
11846
|
-
return `0x${(0,
|
|
12704
|
+
return `0x${(0, import_utils21.bytesToHex)(sig)}`;
|
|
11847
12705
|
}
|
|
11848
12706
|
delay(ms) {
|
|
11849
12707
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -11967,13 +12825,13 @@ var MockTrezorAdapter = class extends BaseWalletAdapter {
|
|
|
11967
12825
|
async getBalance() {
|
|
11968
12826
|
throw new WalletError(
|
|
11969
12827
|
"Hardware wallets do not track balances",
|
|
11970
|
-
|
|
12828
|
+
import_types51.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
11971
12829
|
);
|
|
11972
12830
|
}
|
|
11973
12831
|
async getTokenBalance(_asset) {
|
|
11974
12832
|
throw new WalletError(
|
|
11975
12833
|
"Hardware wallets do not track balances",
|
|
11976
|
-
|
|
12834
|
+
import_types51.WalletErrorCode.UNSUPPORTED_OPERATION
|
|
11977
12835
|
);
|
|
11978
12836
|
}
|
|
11979
12837
|
async getAccounts(startIndex = 0, count = 5) {
|
|
@@ -12032,15 +12890,15 @@ var MockTrezorAdapter = class extends BaseWalletAdapter {
|
|
|
12032
12890
|
}
|
|
12033
12891
|
}
|
|
12034
12892
|
generateMockAddress(index) {
|
|
12035
|
-
const bytes = (0,
|
|
12893
|
+
const bytes = (0, import_utils21.randomBytes)(20);
|
|
12036
12894
|
bytes[0] = index + 100;
|
|
12037
|
-
return `0x${(0,
|
|
12895
|
+
return `0x${(0, import_utils21.bytesToHex)(bytes)}`;
|
|
12038
12896
|
}
|
|
12039
12897
|
generateMockPublicKey(index) {
|
|
12040
|
-
const bytes = (0,
|
|
12898
|
+
const bytes = (0, import_utils21.randomBytes)(33);
|
|
12041
12899
|
bytes[0] = 3;
|
|
12042
12900
|
bytes[1] = index + 100;
|
|
12043
|
-
return `0x${(0,
|
|
12901
|
+
return `0x${(0, import_utils21.bytesToHex)(bytes)}`;
|
|
12044
12902
|
}
|
|
12045
12903
|
generateMockSignature(data) {
|
|
12046
12904
|
const sig = new Uint8Array(65);
|
|
@@ -12049,7 +12907,7 @@ var MockTrezorAdapter = class extends BaseWalletAdapter {
|
|
|
12049
12907
|
sig[32 + i] = (data[i % data.length] ?? 0) ^ i * 17;
|
|
12050
12908
|
}
|
|
12051
12909
|
sig[64] = 28;
|
|
12052
|
-
return `0x${(0,
|
|
12910
|
+
return `0x${(0, import_utils21.bytesToHex)(sig)}`;
|
|
12053
12911
|
}
|
|
12054
12912
|
delay(ms) {
|
|
12055
12913
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -12063,13 +12921,16 @@ function createMockTrezorAdapter(config) {
|
|
|
12063
12921
|
}
|
|
12064
12922
|
|
|
12065
12923
|
// src/wallet/index.ts
|
|
12066
|
-
var
|
|
12924
|
+
var import_types54 = require("@sip-protocol/types");
|
|
12067
12925
|
// Annotate the CommonJS export names for ESM import in node:
|
|
12068
12926
|
0 && (module.exports = {
|
|
12069
12927
|
ATTESTATION_VERSION,
|
|
12928
|
+
AptosStealthService,
|
|
12070
12929
|
BaseWalletAdapter,
|
|
12071
12930
|
CHAIN_NUMERIC_IDS,
|
|
12931
|
+
COSMOS_CHAIN_PREFIXES,
|
|
12072
12932
|
ComplianceManager,
|
|
12933
|
+
CosmosStealthService,
|
|
12073
12934
|
CryptoError,
|
|
12074
12935
|
DEFAULT_THRESHOLD,
|
|
12075
12936
|
DEFAULT_TOTAL_ORACLES,
|
|
@@ -12134,17 +12995,21 @@ var import_types36 = require("@sip-protocol/types");
|
|
|
12134
12995
|
addBlindings,
|
|
12135
12996
|
addCommitments,
|
|
12136
12997
|
addOracle,
|
|
12998
|
+
aptosAddressToAuthKey,
|
|
12137
12999
|
attachProofs,
|
|
12138
13000
|
base58ToHex,
|
|
12139
13001
|
browserBytesToHex,
|
|
12140
13002
|
browserHexToBytes,
|
|
13003
|
+
checkAptosStealthAddress,
|
|
12141
13004
|
checkEd25519StealthAddress,
|
|
12142
13005
|
checkStealthAddress,
|
|
12143
13006
|
commit,
|
|
12144
13007
|
commitZero,
|
|
12145
13008
|
computeAttestationHash,
|
|
13009
|
+
computeTweakedKey,
|
|
12146
13010
|
createCommitment,
|
|
12147
13011
|
createEthereumAdapter,
|
|
13012
|
+
createKeySpendOnlyOutput,
|
|
12148
13013
|
createLedgerAdapter,
|
|
12149
13014
|
createMockEthereumAdapter,
|
|
12150
13015
|
createMockEthereumProvider,
|
|
@@ -12163,6 +13028,7 @@ var import_types36 = require("@sip-protocol/types");
|
|
|
12163
13028
|
createShieldedPayment,
|
|
12164
13029
|
createSmartRouter,
|
|
12165
13030
|
createSolanaAdapter,
|
|
13031
|
+
createTaprootOutput,
|
|
12166
13032
|
createTrezorAdapter,
|
|
12167
13033
|
createWalletFactory,
|
|
12168
13034
|
createZcashClient,
|
|
@@ -12170,8 +13036,10 @@ var import_types36 = require("@sip-protocol/types");
|
|
|
12170
13036
|
createZcashShieldedService,
|
|
12171
13037
|
createZcashSwapService,
|
|
12172
13038
|
decodeStealthMetaAddress,
|
|
13039
|
+
decodeTaprootAddress,
|
|
12173
13040
|
decryptMemo,
|
|
12174
13041
|
decryptWithViewing,
|
|
13042
|
+
deriveAptosStealthPrivateKey,
|
|
12175
13043
|
deriveEd25519StealthPrivateKey,
|
|
12176
13044
|
deriveOracleId,
|
|
12177
13045
|
deriveStealthPrivateKey,
|
|
@@ -12181,6 +13049,7 @@ var import_types36 = require("@sip-protocol/types");
|
|
|
12181
13049
|
deserializePayment,
|
|
12182
13050
|
detectEthereumWallets,
|
|
12183
13051
|
detectSolanaWallets,
|
|
13052
|
+
ed25519PublicKeyToAptosAddress,
|
|
12184
13053
|
ed25519PublicKeyToNearAddress,
|
|
12185
13054
|
ed25519PublicKeyToSolanaAddress,
|
|
12186
13055
|
encodeStealthMetaAddress,
|
|
@@ -12189,7 +13058,10 @@ var import_types36 = require("@sip-protocol/types");
|
|
|
12189
13058
|
formatStablecoinAmount,
|
|
12190
13059
|
fromHex,
|
|
12191
13060
|
fromStablecoinUnits,
|
|
13061
|
+
generateAptosStealthAddress,
|
|
12192
13062
|
generateBlinding,
|
|
13063
|
+
generateCosmosStealthAddress,
|
|
13064
|
+
generateCosmosStealthMetaAddress,
|
|
12193
13065
|
generateEd25519StealthAddress,
|
|
12194
13066
|
generateEd25519StealthMetaAddress,
|
|
12195
13067
|
generateIntentId,
|
|
@@ -12219,6 +13091,7 @@ var import_types36 = require("@sip-protocol/types");
|
|
|
12219
13091
|
getStablecoinsForChain,
|
|
12220
13092
|
getSupportedStablecoins,
|
|
12221
13093
|
getTimeRemaining,
|
|
13094
|
+
getXOnlyPublicKey,
|
|
12222
13095
|
hasEnoughOracles,
|
|
12223
13096
|
hasErrorCode,
|
|
12224
13097
|
hasRequiredProofs,
|
|
@@ -12235,8 +13108,10 @@ var import_types36 = require("@sip-protocol/types");
|
|
|
12235
13108
|
isStablecoin,
|
|
12236
13109
|
isStablecoinOnChain,
|
|
12237
13110
|
isValidAmount,
|
|
13111
|
+
isValidAptosAddress,
|
|
12238
13112
|
isValidChainId,
|
|
12239
13113
|
isValidCompressedPublicKey,
|
|
13114
|
+
isValidCosmosAddress,
|
|
12240
13115
|
isValidEd25519PublicKey,
|
|
12241
13116
|
isValidHex,
|
|
12242
13117
|
isValidHexLength,
|
|
@@ -12248,12 +13123,17 @@ var import_types36 = require("@sip-protocol/types");
|
|
|
12248
13123
|
isValidSlippage,
|
|
12249
13124
|
isValidSolanaAddress,
|
|
12250
13125
|
isValidStealthMetaAddress,
|
|
13126
|
+
isValidTaprootAddress,
|
|
12251
13127
|
nearAddressToEd25519PublicKey,
|
|
12252
13128
|
normalizeAddress,
|
|
12253
13129
|
notConnectedError,
|
|
12254
13130
|
publicKeyToEthAddress,
|
|
12255
13131
|
registerWallet,
|
|
12256
13132
|
removeOracle,
|
|
13133
|
+
schnorrSign,
|
|
13134
|
+
schnorrSignHex,
|
|
13135
|
+
schnorrVerify,
|
|
13136
|
+
schnorrVerifyHex,
|
|
12257
13137
|
secureWipe,
|
|
12258
13138
|
secureWipeAll,
|
|
12259
13139
|
serializeAttestationMessage,
|
|
@@ -12262,6 +13142,7 @@ var import_types36 = require("@sip-protocol/types");
|
|
|
12262
13142
|
signAttestationMessage,
|
|
12263
13143
|
solanaAddressToEd25519PublicKey,
|
|
12264
13144
|
solanaPublicKeyToHex,
|
|
13145
|
+
stealthKeyToCosmosAddress,
|
|
12265
13146
|
subtractBlindings,
|
|
12266
13147
|
subtractCommitments,
|
|
12267
13148
|
supportsSharedArrayBuffer,
|
|
@@ -12270,6 +13151,7 @@ var import_types36 = require("@sip-protocol/types");
|
|
|
12270
13151
|
supportsWebHID,
|
|
12271
13152
|
supportsWebUSB,
|
|
12272
13153
|
supportsWebWorkers,
|
|
13154
|
+
taprootAddress,
|
|
12273
13155
|
toHex,
|
|
12274
13156
|
toStablecoinUnits,
|
|
12275
13157
|
trackIntent,
|