lampamazaza-new-internal-utils 0.24.3
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/LICENSE +21 -0
- package/dist/_virtual/rolldown_runtime.cjs +43 -0
- package/dist/_virtual/rolldown_runtime.js +18 -0
- package/dist/config.cjs +82 -0
- package/dist/config.d.cts +42 -0
- package/dist/config.d.ts +42 -0
- package/dist/config.js +72 -0
- package/dist/errors/assert.cjs +11 -0
- package/dist/errors/assert.d.cts +11 -0
- package/dist/errors/assert.d.ts +11 -0
- package/dist/errors/assert.js +11 -0
- package/dist/errors/base.cjs +34 -0
- package/dist/errors/base.d.cts +21 -0
- package/dist/errors/base.d.ts +21 -0
- package/dist/errors/base.js +33 -0
- package/dist/errors/index.cjs +23 -0
- package/dist/errors/index.d.cts +11 -0
- package/dist/errors/index.d.ts +11 -0
- package/dist/errors/index.js +18 -0
- package/dist/errors/request.cjs +48 -0
- package/dist/errors/request.d.cts +61 -0
- package/dist/errors/request.d.ts +61 -0
- package/dist/errors/request.js +46 -0
- package/dist/errors/utils/isNetworkError.cjs +23 -0
- package/dist/errors/utils/isNetworkError.js +22 -0
- package/dist/errors/utils/toError.cjs +8 -0
- package/dist/errors/utils/toError.d.cts +4 -0
- package/dist/errors/utils/toError.d.ts +4 -0
- package/dist/errors/utils/toError.js +7 -0
- package/dist/index.cjs +125 -0
- package/dist/index.d.cts +30 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +30 -0
- package/dist/logger.d.cts +11 -0
- package/dist/logger.d.ts +11 -0
- package/dist/nearClient.cjs +18 -0
- package/dist/nearClient.d.cts +8 -0
- package/dist/nearClient.d.ts +8 -0
- package/dist/nearClient.js +18 -0
- package/dist/poaBridge/constants/blockchains.cjs +57 -0
- package/dist/poaBridge/constants/blockchains.d.cts +86 -0
- package/dist/poaBridge/constants/blockchains.d.ts +86 -0
- package/dist/poaBridge/constants/blockchains.js +54 -0
- package/dist/poaBridge/errors/withdrawal.cjs +52 -0
- package/dist/poaBridge/errors/withdrawal.d.cts +34 -0
- package/dist/poaBridge/errors/withdrawal.d.ts +34 -0
- package/dist/poaBridge/errors/withdrawal.js +50 -0
- package/dist/poaBridge/getPendingDeposits.cjs +9 -0
- package/dist/poaBridge/getPendingDeposits.d.cts +12 -0
- package/dist/poaBridge/getPendingDeposits.d.ts +13 -0
- package/dist/poaBridge/getPendingDeposits.js +9 -0
- package/dist/poaBridge/index.cjs +23 -0
- package/dist/poaBridge/index.d.cts +11 -0
- package/dist/poaBridge/index.d.ts +11 -0
- package/dist/poaBridge/index.js +18 -0
- package/dist/poaBridge/poaBridgeHttpClient/apis.cjs +38 -0
- package/dist/poaBridge/poaBridgeHttpClient/apis.d.cts +12 -0
- package/dist/poaBridge/poaBridgeHttpClient/apis.d.ts +12 -0
- package/dist/poaBridge/poaBridgeHttpClient/apis.js +32 -0
- package/dist/poaBridge/poaBridgeHttpClient/index.cjs +21 -0
- package/dist/poaBridge/poaBridgeHttpClient/index.d.cts +9 -0
- package/dist/poaBridge/poaBridgeHttpClient/index.d.ts +9 -0
- package/dist/poaBridge/poaBridgeHttpClient/index.js +16 -0
- package/dist/poaBridge/poaBridgeHttpClient/runtime.cjs +49 -0
- package/dist/poaBridge/poaBridgeHttpClient/runtime.js +47 -0
- package/dist/poaBridge/poaBridgeHttpClient/types.d.cts +161 -0
- package/dist/poaBridge/poaBridgeHttpClient/types.d.ts +161 -0
- package/dist/poaBridge/waitForWithdrawalCompletion.cjs +57 -0
- package/dist/poaBridge/waitForWithdrawalCompletion.d.cts +31 -0
- package/dist/poaBridge/waitForWithdrawalCompletion.d.ts +31 -0
- package/dist/poaBridge/waitForWithdrawalCompletion.js +56 -0
- package/dist/services/blockchainBalanceService.cjs +40 -0
- package/dist/services/blockchainBalanceService.d.cts +21 -0
- package/dist/services/blockchainBalanceService.d.ts +21 -0
- package/dist/services/blockchainBalanceService.js +37 -0
- package/dist/solverRelay/errors/intentSettlement.cjs +20 -0
- package/dist/solverRelay/errors/intentSettlement.d.cts +13 -0
- package/dist/solverRelay/errors/intentSettlement.d.ts +13 -0
- package/dist/solverRelay/errors/intentSettlement.js +20 -0
- package/dist/solverRelay/errors/quote.cjs +18 -0
- package/dist/solverRelay/errors/quote.d.cts +21 -0
- package/dist/solverRelay/errors/quote.d.ts +22 -0
- package/dist/solverRelay/errors/quote.js +18 -0
- package/dist/solverRelay/getQuote.cjs +49 -0
- package/dist/solverRelay/getQuote.d.cts +14 -0
- package/dist/solverRelay/getQuote.d.ts +14 -0
- package/dist/solverRelay/getQuote.js +49 -0
- package/dist/solverRelay/getStatus.cjs +26 -0
- package/dist/solverRelay/getStatus.d.cts +17 -0
- package/dist/solverRelay/getStatus.d.ts +18 -0
- package/dist/solverRelay/getStatus.js +26 -0
- package/dist/solverRelay/index.cjs +27 -0
- package/dist/solverRelay/index.d.cts +16 -0
- package/dist/solverRelay/index.d.ts +16 -0
- package/dist/solverRelay/index.js +22 -0
- package/dist/solverRelay/publishIntent.cjs +20 -0
- package/dist/solverRelay/publishIntent.d.cts +15 -0
- package/dist/solverRelay/publishIntent.d.ts +16 -0
- package/dist/solverRelay/publishIntent.js +20 -0
- package/dist/solverRelay/publishIntents.cjs +43 -0
- package/dist/solverRelay/publishIntents.d.cts +10 -0
- package/dist/solverRelay/publishIntents.d.ts +11 -0
- package/dist/solverRelay/publishIntents.js +42 -0
- package/dist/solverRelay/solverRelayHttpClient/apis.cjs +21 -0
- package/dist/solverRelay/solverRelayHttpClient/apis.d.cts +9 -0
- package/dist/solverRelay/solverRelayHttpClient/apis.d.ts +9 -0
- package/dist/solverRelay/solverRelayHttpClient/apis.js +18 -0
- package/dist/solverRelay/solverRelayHttpClient/index.cjs +18 -0
- package/dist/solverRelay/solverRelayHttpClient/index.d.cts +9 -0
- package/dist/solverRelay/solverRelayHttpClient/index.d.ts +9 -0
- package/dist/solverRelay/solverRelayHttpClient/index.js +13 -0
- package/dist/solverRelay/solverRelayHttpClient/runtime.cjs +60 -0
- package/dist/solverRelay/solverRelayHttpClient/runtime.js +58 -0
- package/dist/solverRelay/solverRelayHttpClient/types.d.cts +109 -0
- package/dist/solverRelay/solverRelayHttpClient/types.d.ts +109 -0
- package/dist/solverRelay/utils/parseFailedPublishError.cjs +40 -0
- package/dist/solverRelay/utils/parseFailedPublishError.d.cts +25 -0
- package/dist/solverRelay/utils/parseFailedPublishError.d.ts +26 -0
- package/dist/solverRelay/utils/parseFailedPublishError.js +39 -0
- package/dist/solverRelay/utils/quoteWithLog.cjs +21 -0
- package/dist/solverRelay/utils/quoteWithLog.d.cts +12 -0
- package/dist/solverRelay/utils/quoteWithLog.d.ts +14 -0
- package/dist/solverRelay/utils/quoteWithLog.js +21 -0
- package/dist/solverRelay/waitForIntentSettlement.cjs +52 -0
- package/dist/solverRelay/waitForIntentSettlement.d.cts +30 -0
- package/dist/solverRelay/waitForIntentSettlement.d.ts +30 -0
- package/dist/solverRelay/waitForIntentSettlement.js +52 -0
- package/dist/types/authHandle.cjs +22 -0
- package/dist/types/authHandle.d.cts +25 -0
- package/dist/types/authHandle.d.ts +25 -0
- package/dist/types/authHandle.js +16 -0
- package/dist/types/base.d.cts +45 -0
- package/dist/types/base.d.ts +45 -0
- package/dist/types/intentsUserId.d.cts +10 -0
- package/dist/types/intentsUserId.d.ts +10 -0
- package/dist/types/walletMessage.cjs +11 -0
- package/dist/types/walletMessage.d.cts +106 -0
- package/dist/types/walletMessage.d.ts +106 -0
- package/dist/types/walletMessage.js +5 -0
- package/dist/utils/abortSignal.cjs +19 -0
- package/dist/utils/abortSignal.js +18 -0
- package/dist/utils/appFee.cjs +20 -0
- package/dist/utils/appFee.d.cts +9 -0
- package/dist/utils/appFee.d.ts +9 -0
- package/dist/utils/appFee.js +15 -0
- package/dist/utils/assert.cjs +9 -0
- package/dist/utils/assert.d.cts +7 -0
- package/dist/utils/assert.d.ts +7 -0
- package/dist/utils/assert.js +9 -0
- package/dist/utils/authIdentity.cjs +56 -0
- package/dist/utils/authIdentity.d.cts +34 -0
- package/dist/utils/authIdentity.d.ts +34 -0
- package/dist/utils/authIdentity.js +50 -0
- package/dist/utils/failover.cjs +22 -0
- package/dist/utils/failover.d.cts +16 -0
- package/dist/utils/failover.d.ts +16 -0
- package/dist/utils/failover.js +20 -0
- package/dist/utils/handleRPCResponse.cjs +30 -0
- package/dist/utils/handleRPCResponse.js +28 -0
- package/dist/utils/index.cjs +55 -0
- package/dist/utils/index.d.cts +13 -0
- package/dist/utils/index.d.ts +13 -0
- package/dist/utils/index.js +50 -0
- package/dist/utils/messageFactory.cjs +137 -0
- package/dist/utils/messageFactory.d.cts +70 -0
- package/dist/utils/messageFactory.d.ts +70 -0
- package/dist/utils/messageFactory.js +132 -0
- package/dist/utils/multiPayload/webauthn.cjs +27 -0
- package/dist/utils/multiPayload/webauthn.js +26 -0
- package/dist/utils/near.cjs +58 -0
- package/dist/utils/near.d.cts +35 -0
- package/dist/utils/near.d.ts +35 -0
- package/dist/utils/near.js +53 -0
- package/dist/utils/poll.cjs +87 -0
- package/dist/utils/poll.d.cts +54 -0
- package/dist/utils/poll.d.ts +54 -0
- package/dist/utils/poll.js +85 -0
- package/dist/utils/prepareBroadcastRequest.cjs +98 -0
- package/dist/utils/prepareBroadcastRequest.d.cts +16 -0
- package/dist/utils/prepareBroadcastRequest.d.ts +16 -0
- package/dist/utils/prepareBroadcastRequest.js +90 -0
- package/dist/utils/promise/withTimeout.cjs +34 -0
- package/dist/utils/promise/withTimeout.d.cts +16 -0
- package/dist/utils/promise/withTimeout.d.ts +16 -0
- package/dist/utils/promise/withTimeout.js +34 -0
- package/dist/utils/request.cjs +100 -0
- package/dist/utils/request.d.cts +27 -0
- package/dist/utils/request.d.ts +27 -0
- package/dist/utils/request.js +99 -0
- package/dist/utils/requestShouldRetry.cjs +20 -0
- package/dist/utils/requestShouldRetry.js +20 -0
- package/dist/utils/retry.cjs +66 -0
- package/dist/utils/retry.d.cts +56 -0
- package/dist/utils/retry.d.ts +56 -0
- package/dist/utils/retry.js +64 -0
- package/dist/utils/serialize.cjs +82 -0
- package/dist/utils/serialize.d.cts +17 -0
- package/dist/utils/serialize.d.ts +17 -0
- package/dist/utils/serialize.js +81 -0
- package/dist/utils/stellarAddressToBytes.cjs +295 -0
- package/dist/utils/stellarAddressToBytes.js +294 -0
- package/dist/utils/token.cjs +8 -0
- package/dist/utils/token.js +7 -0
- package/dist/utils/tokenUtils.cjs +263 -0
- package/dist/utils/tokenUtils.d.cts +88 -0
- package/dist/utils/tokenUtils.d.ts +88 -0
- package/dist/utils/tokenUtils.js +238 -0
- package/dist/utils/tronAddressToHex.cjs +18 -0
- package/dist/utils/tronAddressToHex.js +17 -0
- package/dist/utils/uint8Array.cjs +15 -0
- package/dist/utils/uint8Array.d.cts +4 -0
- package/dist/utils/uint8Array.d.ts +4 -0
- package/dist/utils/uint8Array.js +14 -0
- package/dist/utils/webAuthn.cjs +91 -0
- package/dist/utils/webAuthn.js +89 -0
- package/package.json +56 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseTokenInfo, UnifiedTokenInfo } from "../types/base.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/appFee.d.ts
|
|
4
|
+
declare namespace appFee_d_exports {
|
|
5
|
+
export { computeAppFeeBps };
|
|
6
|
+
}
|
|
7
|
+
declare function computeAppFeeBps(defaultAppFeeBps: number, token1: BaseTokenInfo | UnifiedTokenInfo, token2: BaseTokenInfo | UnifiedTokenInfo): number;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { appFee_d_exports };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/rolldown_runtime.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/appFee.ts
|
|
4
|
+
var appFee_exports = /* @__PURE__ */ __exportAll({ computeAppFeeBps: () => computeAppFeeBps });
|
|
5
|
+
function computeAppFeeBps(defaultAppFeeBps, token1, token2) {
|
|
6
|
+
if (hasTags(token1) && hasTags(token2) && token1.tags.includes("type:stablecoin") && token2.tags.includes("type:stablecoin")) return 0;
|
|
7
|
+
return defaultAppFeeBps;
|
|
8
|
+
}
|
|
9
|
+
function hasTags(a) {
|
|
10
|
+
if ("tags" in a) return true;
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { appFee_exports };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_assert = require('./assert.cjs');
|
|
3
|
+
const require_stellarAddressToBytes = require('./stellarAddressToBytes.cjs');
|
|
4
|
+
const require_tronAddressToHex = require('./tronAddressToHex.cjs');
|
|
5
|
+
const require_webAuthn = require('./webAuthn.cjs');
|
|
6
|
+
let _noble_hashes_sha3 = require("@noble/hashes/sha3");
|
|
7
|
+
let _scure_base = require("@scure/base");
|
|
8
|
+
|
|
9
|
+
//#region src/utils/authIdentity.ts
|
|
10
|
+
var authIdentity_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({ authHandleToIntentsUserId: () => authHandleToIntentsUserId });
|
|
11
|
+
function authHandleToIntentsUserId(authIdentifier, authMethod) {
|
|
12
|
+
let authHandle;
|
|
13
|
+
if (typeof authIdentifier === "object") authHandle = authIdentifier;
|
|
14
|
+
else if (authMethod != null) authHandle = {
|
|
15
|
+
identifier: authIdentifier,
|
|
16
|
+
method: authMethod
|
|
17
|
+
};
|
|
18
|
+
else throw new Error("Invalid arguments");
|
|
19
|
+
switch (authHandle.method) {
|
|
20
|
+
case "evm":
|
|
21
|
+
case "near": return authHandle.identifier.toLowerCase();
|
|
22
|
+
case "solana": return _scure_base.hex.encode(_scure_base.base58.decode(authHandle.identifier));
|
|
23
|
+
case "webauthn": return webAuthnIdentifierToIntentsUserId(authHandle.identifier);
|
|
24
|
+
case "ton":
|
|
25
|
+
require_assert.assert(authHandle.identifier.length === 64);
|
|
26
|
+
_scure_base.hex.decode(authHandle.identifier);
|
|
27
|
+
return authHandle.identifier.toLowerCase();
|
|
28
|
+
case "stellar": {
|
|
29
|
+
const decoded = require_stellarAddressToBytes.stellarAddressToBytes(authHandle.identifier);
|
|
30
|
+
return _scure_base.hex.encode(decoded);
|
|
31
|
+
}
|
|
32
|
+
case "tron": return `0x${require_tronAddressToHex.tronAddressToHex(authHandle.identifier).substring(2)}`;
|
|
33
|
+
default: throw new Error("Unsupported auth method");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function webAuthnIdentifierToIntentsUserId(credential) {
|
|
37
|
+
const { curveType, publicKey } = require_webAuthn.parsePublicKey(credential);
|
|
38
|
+
switch (curveType) {
|
|
39
|
+
case "p256": {
|
|
40
|
+
const p256 = new TextEncoder().encode("p256");
|
|
41
|
+
const addressBytes = (0, _noble_hashes_sha3.keccak_256)(new Uint8Array([...p256, ...publicKey])).slice(-20);
|
|
42
|
+
return "0x" + _scure_base.hex.encode(addressBytes);
|
|
43
|
+
}
|
|
44
|
+
case "ed25519": return _scure_base.hex.encode(publicKey);
|
|
45
|
+
default: throw new Error("Unsupported curve type");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
exports.authHandleToIntentsUserId = authHandleToIntentsUserId;
|
|
51
|
+
Object.defineProperty(exports, 'authIdentity_exports', {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function () {
|
|
54
|
+
return authIdentity_exports;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { IntentsUserId } from "../types/intentsUserId.cjs";
|
|
2
|
+
import { AuthHandle, AuthIdentifier, AuthMethod } from "../types/authHandle.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/authIdentity.d.ts
|
|
5
|
+
declare namespace authIdentity_d_exports {
|
|
6
|
+
export { authHandleToIntentsUserId };
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Converts a blockchain address to a standardized Defuse user ID.
|
|
10
|
+
*
|
|
11
|
+
* The conversion follows these rules:
|
|
12
|
+
* 1. NEAR addresses: Used as-is (lowercased)
|
|
13
|
+
* - Explicit: "bob.near"
|
|
14
|
+
* - Implicit: "17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1"
|
|
15
|
+
*
|
|
16
|
+
* 2. EVM addresses: Used as-is (lowercased)
|
|
17
|
+
* - Format: "0xc0ffee254729296a45a3885639ac7e10f9d54979"
|
|
18
|
+
*
|
|
19
|
+
* 3. Solana addresses: Converted from base58 to hex
|
|
20
|
+
* - Input: base58 public key
|
|
21
|
+
* - Output: hex-encoded string
|
|
22
|
+
*
|
|
23
|
+
* 4. WebAuthn credentials: Converted based on curve type
|
|
24
|
+
* - P-256: Keccak256(prefix + pubkey) -> last 20 bytes -> hex with 0x prefix
|
|
25
|
+
* - Ed25519: Raw public key -> hex encoding
|
|
26
|
+
*
|
|
27
|
+
* @param authIdentifier - The user's identifier (blockchain address or WebAuthn public key)
|
|
28
|
+
* @param authMethod - The type of credential ("evm", "near", "solana", "webauthn")
|
|
29
|
+
* @returns A standardized Defuse user ID
|
|
30
|
+
*/
|
|
31
|
+
declare function authHandleToIntentsUserId(authIdentifier: AuthIdentifier, authMethod: AuthMethod): IntentsUserId;
|
|
32
|
+
declare function authHandleToIntentsUserId(authHandle: AuthHandle): IntentsUserId;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { authHandleToIntentsUserId, authIdentity_d_exports };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { IntentsUserId } from "../types/intentsUserId.js";
|
|
2
|
+
import { AuthHandle, AuthIdentifier, AuthMethod } from "../types/authHandle.js";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/authIdentity.d.ts
|
|
5
|
+
declare namespace authIdentity_d_exports {
|
|
6
|
+
export { authHandleToIntentsUserId };
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Converts a blockchain address to a standardized Defuse user ID.
|
|
10
|
+
*
|
|
11
|
+
* The conversion follows these rules:
|
|
12
|
+
* 1. NEAR addresses: Used as-is (lowercased)
|
|
13
|
+
* - Explicit: "bob.near"
|
|
14
|
+
* - Implicit: "17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1"
|
|
15
|
+
*
|
|
16
|
+
* 2. EVM addresses: Used as-is (lowercased)
|
|
17
|
+
* - Format: "0xc0ffee254729296a45a3885639ac7e10f9d54979"
|
|
18
|
+
*
|
|
19
|
+
* 3. Solana addresses: Converted from base58 to hex
|
|
20
|
+
* - Input: base58 public key
|
|
21
|
+
* - Output: hex-encoded string
|
|
22
|
+
*
|
|
23
|
+
* 4. WebAuthn credentials: Converted based on curve type
|
|
24
|
+
* - P-256: Keccak256(prefix + pubkey) -> last 20 bytes -> hex with 0x prefix
|
|
25
|
+
* - Ed25519: Raw public key -> hex encoding
|
|
26
|
+
*
|
|
27
|
+
* @param authIdentifier - The user's identifier (blockchain address or WebAuthn public key)
|
|
28
|
+
* @param authMethod - The type of credential ("evm", "near", "solana", "webauthn")
|
|
29
|
+
* @returns A standardized Defuse user ID
|
|
30
|
+
*/
|
|
31
|
+
declare function authHandleToIntentsUserId(authIdentifier: AuthIdentifier, authMethod: AuthMethod): IntentsUserId;
|
|
32
|
+
declare function authHandleToIntentsUserId(authHandle: AuthHandle): IntentsUserId;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { authHandleToIntentsUserId, authIdentity_d_exports };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/rolldown_runtime.js";
|
|
2
|
+
import { assert } from "./assert.js";
|
|
3
|
+
import { stellarAddressToBytes } from "./stellarAddressToBytes.js";
|
|
4
|
+
import { tronAddressToHex } from "./tronAddressToHex.js";
|
|
5
|
+
import { parsePublicKey } from "./webAuthn.js";
|
|
6
|
+
import { keccak_256 } from "@noble/hashes/sha3";
|
|
7
|
+
import { base58, hex } from "@scure/base";
|
|
8
|
+
|
|
9
|
+
//#region src/utils/authIdentity.ts
|
|
10
|
+
var authIdentity_exports = /* @__PURE__ */ __exportAll({ authHandleToIntentsUserId: () => authHandleToIntentsUserId });
|
|
11
|
+
function authHandleToIntentsUserId(authIdentifier, authMethod) {
|
|
12
|
+
let authHandle;
|
|
13
|
+
if (typeof authIdentifier === "object") authHandle = authIdentifier;
|
|
14
|
+
else if (authMethod != null) authHandle = {
|
|
15
|
+
identifier: authIdentifier,
|
|
16
|
+
method: authMethod
|
|
17
|
+
};
|
|
18
|
+
else throw new Error("Invalid arguments");
|
|
19
|
+
switch (authHandle.method) {
|
|
20
|
+
case "evm":
|
|
21
|
+
case "near": return authHandle.identifier.toLowerCase();
|
|
22
|
+
case "solana": return hex.encode(base58.decode(authHandle.identifier));
|
|
23
|
+
case "webauthn": return webAuthnIdentifierToIntentsUserId(authHandle.identifier);
|
|
24
|
+
case "ton":
|
|
25
|
+
assert(authHandle.identifier.length === 64);
|
|
26
|
+
hex.decode(authHandle.identifier);
|
|
27
|
+
return authHandle.identifier.toLowerCase();
|
|
28
|
+
case "stellar": {
|
|
29
|
+
const decoded = stellarAddressToBytes(authHandle.identifier);
|
|
30
|
+
return hex.encode(decoded);
|
|
31
|
+
}
|
|
32
|
+
case "tron": return `0x${tronAddressToHex(authHandle.identifier).substring(2)}`;
|
|
33
|
+
default: throw new Error("Unsupported auth method");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function webAuthnIdentifierToIntentsUserId(credential) {
|
|
37
|
+
const { curveType, publicKey } = parsePublicKey(credential);
|
|
38
|
+
switch (curveType) {
|
|
39
|
+
case "p256": {
|
|
40
|
+
const p256 = new TextEncoder().encode("p256");
|
|
41
|
+
const addressBytes = keccak_256(new Uint8Array([...p256, ...publicKey])).slice(-20);
|
|
42
|
+
return "0x" + hex.encode(addressBytes);
|
|
43
|
+
}
|
|
44
|
+
case "ed25519": return hex.encode(publicKey);
|
|
45
|
+
default: throw new Error("Unsupported curve type");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
export { authHandleToIntentsUserId, authIdentity_exports };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let near_api_js = require("near-api-js");
|
|
3
|
+
|
|
4
|
+
//#region src/utils/failover.ts
|
|
5
|
+
/**
|
|
6
|
+
* @note This function is specifically designed for NEAR RPC providers and should not be used with other blockchain networks.
|
|
7
|
+
* It creates a failover provider that will automatically switch between the provided RPC endpoints if one fails.
|
|
8
|
+
*/
|
|
9
|
+
function nearFailoverRpcProvider({ urls }) {
|
|
10
|
+
return createNearFailoverRpcProvider({ providers: urls.map((url) => new near_api_js.providers.JsonRpcProvider({ url })) });
|
|
11
|
+
}
|
|
12
|
+
function createNearFailoverRpcProvider({ providers: list }) {
|
|
13
|
+
return new near_api_js.providers.FailoverRpcProvider(list);
|
|
14
|
+
}
|
|
15
|
+
function unwrapNearFailoverRpcProvider(provider) {
|
|
16
|
+
if (provider instanceof near_api_js.providers.FailoverRpcProvider && provider.providers.length > 0 && provider.providers[0]) return provider.providers[0];
|
|
17
|
+
return provider;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
exports.nearFailoverRpcProvider = nearFailoverRpcProvider;
|
|
22
|
+
exports.unwrapNearFailoverRpcProvider = unwrapNearFailoverRpcProvider;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { providers } from "near-api-js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/failover.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @note This function is specifically designed for NEAR RPC providers and should not be used with other blockchain networks.
|
|
7
|
+
* It creates a failover provider that will automatically switch between the provided RPC endpoints if one fails.
|
|
8
|
+
*/
|
|
9
|
+
declare function nearFailoverRpcProvider({
|
|
10
|
+
urls
|
|
11
|
+
}: {
|
|
12
|
+
urls: string[];
|
|
13
|
+
}): providers.FailoverRpcProvider;
|
|
14
|
+
declare function unwrapNearFailoverRpcProvider(provider: providers.Provider): providers.Provider;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { nearFailoverRpcProvider, unwrapNearFailoverRpcProvider };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { providers } from "near-api-js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/failover.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @note This function is specifically designed for NEAR RPC providers and should not be used with other blockchain networks.
|
|
7
|
+
* It creates a failover provider that will automatically switch between the provided RPC endpoints if one fails.
|
|
8
|
+
*/
|
|
9
|
+
declare function nearFailoverRpcProvider({
|
|
10
|
+
urls
|
|
11
|
+
}: {
|
|
12
|
+
urls: string[];
|
|
13
|
+
}): providers.FailoverRpcProvider;
|
|
14
|
+
declare function unwrapNearFailoverRpcProvider(provider: providers.Provider): providers.Provider;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { nearFailoverRpcProvider, unwrapNearFailoverRpcProvider };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { providers } from "near-api-js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/failover.ts
|
|
4
|
+
/**
|
|
5
|
+
* @note This function is specifically designed for NEAR RPC providers and should not be used with other blockchain networks.
|
|
6
|
+
* It creates a failover provider that will automatically switch between the provided RPC endpoints if one fails.
|
|
7
|
+
*/
|
|
8
|
+
function nearFailoverRpcProvider({ urls }) {
|
|
9
|
+
return createNearFailoverRpcProvider({ providers: urls.map((url) => new providers.JsonRpcProvider({ url })) });
|
|
10
|
+
}
|
|
11
|
+
function createNearFailoverRpcProvider({ providers: list }) {
|
|
12
|
+
return new providers.FailoverRpcProvider(list);
|
|
13
|
+
}
|
|
14
|
+
function unwrapNearFailoverRpcProvider(provider) {
|
|
15
|
+
if (provider instanceof providers.FailoverRpcProvider && provider.providers.length > 0 && provider.providers[0]) return provider.providers[0];
|
|
16
|
+
return provider;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { nearFailoverRpcProvider, unwrapNearFailoverRpcProvider };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_request = require('../errors/request.cjs');
|
|
3
|
+
let valibot = require("valibot");
|
|
4
|
+
valibot = require_rolldown_runtime.__toESM(valibot);
|
|
5
|
+
|
|
6
|
+
//#region src/utils/handleRPCResponse.ts
|
|
7
|
+
async function handleRPCResponse(response, body, schema) {
|
|
8
|
+
const json = await response.json();
|
|
9
|
+
const parsed = valibot.safeParse(schema, json);
|
|
10
|
+
if (parsed.success) {
|
|
11
|
+
if (parsed.output.error !== void 0) throw new require_request.RpcRequestError({
|
|
12
|
+
body,
|
|
13
|
+
error: parsed.output.error,
|
|
14
|
+
url: response.url
|
|
15
|
+
});
|
|
16
|
+
return parsed.output.result;
|
|
17
|
+
}
|
|
18
|
+
throw new require_request.RpcRequestError({
|
|
19
|
+
body,
|
|
20
|
+
error: {
|
|
21
|
+
code: -1,
|
|
22
|
+
data: json,
|
|
23
|
+
message: "Invalid response"
|
|
24
|
+
},
|
|
25
|
+
url: response.url
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
exports.handleRPCResponse = handleRPCResponse;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { RpcRequestError } from "../errors/request.js";
|
|
2
|
+
import * as v from "valibot";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/handleRPCResponse.ts
|
|
5
|
+
async function handleRPCResponse(response, body, schema) {
|
|
6
|
+
const json = await response.json();
|
|
7
|
+
const parsed = v.safeParse(schema, json);
|
|
8
|
+
if (parsed.success) {
|
|
9
|
+
if (parsed.output.error !== void 0) throw new RpcRequestError({
|
|
10
|
+
body,
|
|
11
|
+
error: parsed.output.error,
|
|
12
|
+
url: response.url
|
|
13
|
+
});
|
|
14
|
+
return parsed.output.result;
|
|
15
|
+
}
|
|
16
|
+
throw new RpcRequestError({
|
|
17
|
+
body,
|
|
18
|
+
error: {
|
|
19
|
+
code: -1,
|
|
20
|
+
data: json,
|
|
21
|
+
message: "Invalid response"
|
|
22
|
+
},
|
|
23
|
+
url: response.url
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { handleRPCResponse };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_assert = require('./assert.cjs');
|
|
3
|
+
const require_uint8Array = require('./uint8Array.cjs');
|
|
4
|
+
const require_authIdentity = require('./authIdentity.cjs');
|
|
5
|
+
const require_prepareBroadcastRequest = require('./prepareBroadcastRequest.cjs');
|
|
6
|
+
const require_near = require('./near.cjs');
|
|
7
|
+
const require_tokenUtils = require('./tokenUtils.cjs');
|
|
8
|
+
|
|
9
|
+
//#region src/utils/index.ts
|
|
10
|
+
var utils_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
11
|
+
BASIS_POINTS_DENOMINATOR: () => require_tokenUtils.BASIS_POINTS_DENOMINATOR,
|
|
12
|
+
DuplicateTokenError: () => require_tokenUtils.DuplicateTokenError,
|
|
13
|
+
accountSlippageExactIn: () => require_tokenUtils.accountSlippageExactIn,
|
|
14
|
+
addAmounts: () => require_tokenUtils.addAmounts,
|
|
15
|
+
adjustDecimals: () => require_tokenUtils.adjustDecimals,
|
|
16
|
+
adjustDecimalsTokenValue: () => require_tokenUtils.adjustDecimalsTokenValue,
|
|
17
|
+
assert: () => require_assert.assert,
|
|
18
|
+
authHandleToIntentsUserId: () => require_authIdentity.authHandleToIntentsUserId,
|
|
19
|
+
compareAmounts: () => require_tokenUtils.compareAmounts,
|
|
20
|
+
computeTotalBalance: () => require_tokenUtils.computeTotalBalance,
|
|
21
|
+
computeTotalBalanceDifferentDecimals: () => require_tokenUtils.computeTotalBalanceDifferentDecimals,
|
|
22
|
+
computeTotalDeltaDifferentDecimals: () => require_tokenUtils.computeTotalDeltaDifferentDecimals,
|
|
23
|
+
concatUint8Arrays: () => require_uint8Array.concatUint8Arrays,
|
|
24
|
+
decodeQueryResult: () => require_near.decodeQueryResult,
|
|
25
|
+
deduplicateTokens: () => require_tokenUtils.deduplicateTokens,
|
|
26
|
+
filterOutPoaBridgeTokens: () => require_tokenUtils.filterOutPoaBridgeTokens,
|
|
27
|
+
getAnyBaseTokenInfo: () => require_tokenUtils.getAnyBaseTokenInfo,
|
|
28
|
+
getDerivedToken: () => require_tokenUtils.getDerivedToken,
|
|
29
|
+
getTokenAccountId: () => require_tokenUtils.getTokenAccountId,
|
|
30
|
+
getTokenAccountIds: () => require_tokenUtils.getTokenAccountIds,
|
|
31
|
+
getTokenMaxDecimals: () => require_tokenUtils.getTokenMaxDecimals,
|
|
32
|
+
getUnderlyingBaseTokenInfos: () => require_tokenUtils.getUnderlyingBaseTokenInfos,
|
|
33
|
+
grossUpAmount: () => require_tokenUtils.grossUpAmount,
|
|
34
|
+
isImplicitAccount: () => require_near.isImplicitAccount,
|
|
35
|
+
minAmounts: () => require_tokenUtils.minAmounts,
|
|
36
|
+
negateTokenValue: () => require_tokenUtils.negateTokenValue,
|
|
37
|
+
netDownAmount: () => require_tokenUtils.netDownAmount,
|
|
38
|
+
normalizeERC191Signature: () => require_prepareBroadcastRequest.normalizeERC191Signature,
|
|
39
|
+
parseDefuseAssetId: () => require_tokenUtils.parseDefuseAssetId,
|
|
40
|
+
prepareSwapSignedData: () => require_prepareBroadcastRequest.prepareSwapSignedData,
|
|
41
|
+
queryContract: () => require_near.queryContract,
|
|
42
|
+
subtractAmounts: () => require_tokenUtils.subtractAmounts,
|
|
43
|
+
tokenAccountIdToDefuseAssetId: () => require_tokenUtils.tokenAccountIdToDefuseAssetId,
|
|
44
|
+
transformERC191Signature: () => require_prepareBroadcastRequest.transformERC191Signature,
|
|
45
|
+
truncateTokenValue: () => require_tokenUtils.truncateTokenValue,
|
|
46
|
+
validateNearAddress: () => require_near.validateNearAddress
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
Object.defineProperty(exports, 'utils_exports', {
|
|
51
|
+
enumerable: true,
|
|
52
|
+
get: function () {
|
|
53
|
+
return utils_exports;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AssertErrorType, assert } from "./assert.cjs";
|
|
2
|
+
import { authHandleToIntentsUserId } from "./authIdentity.cjs";
|
|
3
|
+
import { normalizeERC191Signature, prepareSwapSignedData, transformERC191Signature } from "./prepareBroadcastRequest.cjs";
|
|
4
|
+
import { BASIS_POINTS_DENOMINATOR, DuplicateTokenError, ParseDefuseAssetIdErrorType, ParseDefuseAssetIdReturnType, accountSlippageExactIn, addAmounts, adjustDecimals, adjustDecimalsTokenValue, compareAmounts, computeTotalBalance, computeTotalBalanceDifferentDecimals, computeTotalDeltaDifferentDecimals, deduplicateTokens, filterOutPoaBridgeTokens, getAnyBaseTokenInfo, getDerivedToken, getTokenAccountId, getTokenAccountIds, getTokenMaxDecimals, getUnderlyingBaseTokenInfos, grossUpAmount, minAmounts, negateTokenValue, netDownAmount, parseDefuseAssetId, subtractAmounts, tokenAccountIdToDefuseAssetId, truncateTokenValue } from "./tokenUtils.cjs";
|
|
5
|
+
import { OptionalBlockReference, decodeQueryResult, isImplicitAccount, queryContract, validateNearAddress } from "./near.cjs";
|
|
6
|
+
import { concatUint8Arrays } from "./uint8Array.cjs";
|
|
7
|
+
|
|
8
|
+
//#region src/utils/index.d.ts
|
|
9
|
+
declare namespace index_d_exports {
|
|
10
|
+
export { AssertErrorType, BASIS_POINTS_DENOMINATOR, DuplicateTokenError, OptionalBlockReference, ParseDefuseAssetIdErrorType, ParseDefuseAssetIdReturnType, accountSlippageExactIn, addAmounts, adjustDecimals, adjustDecimalsTokenValue, assert, authHandleToIntentsUserId, compareAmounts, computeTotalBalance, computeTotalBalanceDifferentDecimals, computeTotalDeltaDifferentDecimals, concatUint8Arrays, decodeQueryResult, deduplicateTokens, filterOutPoaBridgeTokens, getAnyBaseTokenInfo, getDerivedToken, getTokenAccountId, getTokenAccountIds, getTokenMaxDecimals, getUnderlyingBaseTokenInfos, grossUpAmount, isImplicitAccount, minAmounts, negateTokenValue, netDownAmount, normalizeERC191Signature, parseDefuseAssetId, prepareSwapSignedData, queryContract, subtractAmounts, tokenAccountIdToDefuseAssetId, transformERC191Signature, truncateTokenValue, validateNearAddress };
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { index_d_exports };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AssertErrorType, assert } from "./assert.js";
|
|
2
|
+
import { authHandleToIntentsUserId } from "./authIdentity.js";
|
|
3
|
+
import { normalizeERC191Signature, prepareSwapSignedData, transformERC191Signature } from "./prepareBroadcastRequest.js";
|
|
4
|
+
import { BASIS_POINTS_DENOMINATOR, DuplicateTokenError, ParseDefuseAssetIdErrorType, ParseDefuseAssetIdReturnType, accountSlippageExactIn, addAmounts, adjustDecimals, adjustDecimalsTokenValue, compareAmounts, computeTotalBalance, computeTotalBalanceDifferentDecimals, computeTotalDeltaDifferentDecimals, deduplicateTokens, filterOutPoaBridgeTokens, getAnyBaseTokenInfo, getDerivedToken, getTokenAccountId, getTokenAccountIds, getTokenMaxDecimals, getUnderlyingBaseTokenInfos, grossUpAmount, minAmounts, negateTokenValue, netDownAmount, parseDefuseAssetId, subtractAmounts, tokenAccountIdToDefuseAssetId, truncateTokenValue } from "./tokenUtils.js";
|
|
5
|
+
import { OptionalBlockReference, decodeQueryResult, isImplicitAccount, queryContract, validateNearAddress } from "./near.js";
|
|
6
|
+
import { concatUint8Arrays } from "./uint8Array.js";
|
|
7
|
+
|
|
8
|
+
//#region src/utils/index.d.ts
|
|
9
|
+
declare namespace index_d_exports {
|
|
10
|
+
export { AssertErrorType, BASIS_POINTS_DENOMINATOR, DuplicateTokenError, OptionalBlockReference, ParseDefuseAssetIdErrorType, ParseDefuseAssetIdReturnType, accountSlippageExactIn, addAmounts, adjustDecimals, adjustDecimalsTokenValue, assert, authHandleToIntentsUserId, compareAmounts, computeTotalBalance, computeTotalBalanceDifferentDecimals, computeTotalDeltaDifferentDecimals, concatUint8Arrays, decodeQueryResult, deduplicateTokens, filterOutPoaBridgeTokens, getAnyBaseTokenInfo, getDerivedToken, getTokenAccountId, getTokenAccountIds, getTokenMaxDecimals, getUnderlyingBaseTokenInfos, grossUpAmount, isImplicitAccount, minAmounts, negateTokenValue, netDownAmount, normalizeERC191Signature, parseDefuseAssetId, prepareSwapSignedData, queryContract, subtractAmounts, tokenAccountIdToDefuseAssetId, transformERC191Signature, truncateTokenValue, validateNearAddress };
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { index_d_exports };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/rolldown_runtime.js";
|
|
2
|
+
import { assert } from "./assert.js";
|
|
3
|
+
import { concatUint8Arrays } from "./uint8Array.js";
|
|
4
|
+
import { authHandleToIntentsUserId } from "./authIdentity.js";
|
|
5
|
+
import { normalizeERC191Signature, prepareSwapSignedData, transformERC191Signature } from "./prepareBroadcastRequest.js";
|
|
6
|
+
import { decodeQueryResult, isImplicitAccount, queryContract, validateNearAddress } from "./near.js";
|
|
7
|
+
import { BASIS_POINTS_DENOMINATOR, DuplicateTokenError, accountSlippageExactIn, addAmounts, adjustDecimals, adjustDecimalsTokenValue, compareAmounts, computeTotalBalance, computeTotalBalanceDifferentDecimals, computeTotalDeltaDifferentDecimals, deduplicateTokens, filterOutPoaBridgeTokens, getAnyBaseTokenInfo, getDerivedToken, getTokenAccountId, getTokenAccountIds, getTokenMaxDecimals, getUnderlyingBaseTokenInfos, grossUpAmount, minAmounts, negateTokenValue, netDownAmount, parseDefuseAssetId, subtractAmounts, tokenAccountIdToDefuseAssetId, truncateTokenValue } from "./tokenUtils.js";
|
|
8
|
+
|
|
9
|
+
//#region src/utils/index.ts
|
|
10
|
+
var utils_exports = /* @__PURE__ */ __exportAll({
|
|
11
|
+
BASIS_POINTS_DENOMINATOR: () => BASIS_POINTS_DENOMINATOR,
|
|
12
|
+
DuplicateTokenError: () => DuplicateTokenError,
|
|
13
|
+
accountSlippageExactIn: () => accountSlippageExactIn,
|
|
14
|
+
addAmounts: () => addAmounts,
|
|
15
|
+
adjustDecimals: () => adjustDecimals,
|
|
16
|
+
adjustDecimalsTokenValue: () => adjustDecimalsTokenValue,
|
|
17
|
+
assert: () => assert,
|
|
18
|
+
authHandleToIntentsUserId: () => authHandleToIntentsUserId,
|
|
19
|
+
compareAmounts: () => compareAmounts,
|
|
20
|
+
computeTotalBalance: () => computeTotalBalance,
|
|
21
|
+
computeTotalBalanceDifferentDecimals: () => computeTotalBalanceDifferentDecimals,
|
|
22
|
+
computeTotalDeltaDifferentDecimals: () => computeTotalDeltaDifferentDecimals,
|
|
23
|
+
concatUint8Arrays: () => concatUint8Arrays,
|
|
24
|
+
decodeQueryResult: () => decodeQueryResult,
|
|
25
|
+
deduplicateTokens: () => deduplicateTokens,
|
|
26
|
+
filterOutPoaBridgeTokens: () => filterOutPoaBridgeTokens,
|
|
27
|
+
getAnyBaseTokenInfo: () => getAnyBaseTokenInfo,
|
|
28
|
+
getDerivedToken: () => getDerivedToken,
|
|
29
|
+
getTokenAccountId: () => getTokenAccountId,
|
|
30
|
+
getTokenAccountIds: () => getTokenAccountIds,
|
|
31
|
+
getTokenMaxDecimals: () => getTokenMaxDecimals,
|
|
32
|
+
getUnderlyingBaseTokenInfos: () => getUnderlyingBaseTokenInfos,
|
|
33
|
+
grossUpAmount: () => grossUpAmount,
|
|
34
|
+
isImplicitAccount: () => isImplicitAccount,
|
|
35
|
+
minAmounts: () => minAmounts,
|
|
36
|
+
negateTokenValue: () => negateTokenValue,
|
|
37
|
+
netDownAmount: () => netDownAmount,
|
|
38
|
+
normalizeERC191Signature: () => normalizeERC191Signature,
|
|
39
|
+
parseDefuseAssetId: () => parseDefuseAssetId,
|
|
40
|
+
prepareSwapSignedData: () => prepareSwapSignedData,
|
|
41
|
+
queryContract: () => queryContract,
|
|
42
|
+
subtractAmounts: () => subtractAmounts,
|
|
43
|
+
tokenAccountIdToDefuseAssetId: () => tokenAccountIdToDefuseAssetId,
|
|
44
|
+
transformERC191Signature: () => transformERC191Signature,
|
|
45
|
+
truncateTokenValue: () => truncateTokenValue,
|
|
46
|
+
validateNearAddress: () => validateNearAddress
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
export { utils_exports };
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_config = require('../config.cjs');
|
|
3
|
+
const require_assert = require('./assert.cjs');
|
|
4
|
+
let _scure_base = require("@scure/base");
|
|
5
|
+
let _noble_hashes_sha256 = require("@noble/hashes/sha256");
|
|
6
|
+
|
|
7
|
+
//#region src/utils/messageFactory.ts
|
|
8
|
+
var messageFactory_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
9
|
+
makeChallenge: () => makeChallenge,
|
|
10
|
+
makeEmptyMessage: () => makeEmptyMessage,
|
|
11
|
+
makeInnerSwapMessage: () => makeInnerSwapMessage,
|
|
12
|
+
makeInnerTransferMessage: () => makeInnerTransferMessage,
|
|
13
|
+
makeSwapMessage: () => makeSwapMessage,
|
|
14
|
+
randomDefuseNonce: () => randomDefuseNonce
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* @param tokenDeltas
|
|
18
|
+
* @param signerId
|
|
19
|
+
* @param deadlineTimestamp Unix timestamp in milliseconds
|
|
20
|
+
* @param referral
|
|
21
|
+
* @param memo
|
|
22
|
+
* @param appFee
|
|
23
|
+
* @param appFeeRecipient
|
|
24
|
+
*/
|
|
25
|
+
function makeInnerSwapMessage({ tokenDeltas, signerId, deadlineTimestamp, referral, memo, appFee, appFeeRecipient }) {
|
|
26
|
+
const tokenDiff = {};
|
|
27
|
+
const tokenDiffNum = {};
|
|
28
|
+
const intents = [{
|
|
29
|
+
intent: "token_diff",
|
|
30
|
+
diff: tokenDiff,
|
|
31
|
+
referral,
|
|
32
|
+
memo
|
|
33
|
+
}];
|
|
34
|
+
if (appFee.length) intents.push({
|
|
35
|
+
intent: "transfer",
|
|
36
|
+
tokens: Object.fromEntries(appFee.map(([token, amount]) => [token, amount.toString()])),
|
|
37
|
+
receiver_id: appFeeRecipient,
|
|
38
|
+
memo: "APP_FEE"
|
|
39
|
+
});
|
|
40
|
+
for (const [token, amount] of tokenDeltas) {
|
|
41
|
+
tokenDiffNum[token] ??= 0n;
|
|
42
|
+
tokenDiffNum[token] += amount;
|
|
43
|
+
tokenDiff[token] = tokenDiffNum[token].toString();
|
|
44
|
+
}
|
|
45
|
+
if (Object.keys(tokenDiff).length === 0) return {
|
|
46
|
+
deadline: new Date(deadlineTimestamp).toISOString(),
|
|
47
|
+
intents: [],
|
|
48
|
+
signer_id: signerId
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
deadline: new Date(deadlineTimestamp).toISOString(),
|
|
52
|
+
intents,
|
|
53
|
+
signer_id: signerId
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function makeSwapMessage({ innerMessage, nonce = randomDefuseNonce() }) {
|
|
57
|
+
const payload = {
|
|
58
|
+
signer_id: innerMessage.signer_id,
|
|
59
|
+
verifying_contract: require_config.config.env.contractID,
|
|
60
|
+
deadline: innerMessage.deadline,
|
|
61
|
+
nonce: _scure_base.base64.encode(nonce),
|
|
62
|
+
intents: innerMessage.intents
|
|
63
|
+
};
|
|
64
|
+
const payloadSerialized = JSON.stringify(payload);
|
|
65
|
+
const payloadBytes = new TextEncoder().encode(payloadSerialized);
|
|
66
|
+
return {
|
|
67
|
+
NEP413: {
|
|
68
|
+
message: JSON.stringify(innerMessage),
|
|
69
|
+
recipient: require_config.config.env.contractID,
|
|
70
|
+
nonce
|
|
71
|
+
},
|
|
72
|
+
ERC191: { message: JSON.stringify(payload, null, 2) },
|
|
73
|
+
SOLANA: { message: payloadBytes },
|
|
74
|
+
STELLAR: { message: JSON.stringify(payload, null, 2) },
|
|
75
|
+
WEBAUTHN: {
|
|
76
|
+
challenge: makeChallenge(payloadBytes),
|
|
77
|
+
payload: payloadSerialized,
|
|
78
|
+
parsedPayload: payload
|
|
79
|
+
},
|
|
80
|
+
TON_CONNECT: { message: {
|
|
81
|
+
type: "text",
|
|
82
|
+
text: JSON.stringify(payload, null, 2)
|
|
83
|
+
} },
|
|
84
|
+
TRON: { message: JSON.stringify(payload, null, 2) }
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function makeEmptyMessage({ signerId, deadlineTimestamp, nonce = randomDefuseNonce() }) {
|
|
88
|
+
return makeSwapMessage({
|
|
89
|
+
innerMessage: {
|
|
90
|
+
deadline: new Date(deadlineTimestamp).toISOString(),
|
|
91
|
+
intents: [],
|
|
92
|
+
signer_id: signerId
|
|
93
|
+
},
|
|
94
|
+
nonce
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function randomDefuseNonce() {
|
|
98
|
+
return randomBytes(32);
|
|
99
|
+
}
|
|
100
|
+
function randomBytes(length) {
|
|
101
|
+
return crypto.getRandomValues(new Uint8Array(length));
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Converts UTF-8 string to bytes for WebAuthn challenge
|
|
105
|
+
*/
|
|
106
|
+
function makeChallenge(payload) {
|
|
107
|
+
const hash = (0, _noble_hashes_sha256.sha256)(payload);
|
|
108
|
+
return new Uint8Array(hash);
|
|
109
|
+
}
|
|
110
|
+
function makeInnerTransferMessage({ tokenDeltas, signerId, deadlineTimestamp, receiverId, memo }) {
|
|
111
|
+
const tokens = {};
|
|
112
|
+
const seenTokens = /* @__PURE__ */ new Set();
|
|
113
|
+
for (const [token, amount] of tokenDeltas) {
|
|
114
|
+
require_assert.assert(!seenTokens.has(token), `Duplicate token found: ${token}`);
|
|
115
|
+
seenTokens.add(token);
|
|
116
|
+
require_assert.assert(amount > 0n, `Transfer amount must be positive, got: ${amount} for token ${token}`);
|
|
117
|
+
tokens[token] = amount.toString();
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
deadline: new Date(deadlineTimestamp).toISOString(),
|
|
121
|
+
intents: [{
|
|
122
|
+
intent: "transfer",
|
|
123
|
+
tokens,
|
|
124
|
+
receiver_id: receiverId,
|
|
125
|
+
...memo ? { memo } : {}
|
|
126
|
+
}],
|
|
127
|
+
signer_id: signerId
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
//#endregion
|
|
132
|
+
Object.defineProperty(exports, 'messageFactory_exports', {
|
|
133
|
+
enumerable: true,
|
|
134
|
+
get: function () {
|
|
135
|
+
return messageFactory_exports;
|
|
136
|
+
}
|
|
137
|
+
});
|