@flashnet/sdk 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +479 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/src/api/client.d.ts +20 -0
- package/dist/src/api/client.d.ts.map +1 -0
- package/dist/src/api/client.js +85 -0
- package/dist/src/api/client.js.map +1 -0
- package/dist/src/api/typed-endpoints.d.ts +135 -0
- package/dist/src/api/typed-endpoints.d.ts.map +1 -0
- package/dist/src/api/typed-endpoints.js +202 -0
- package/dist/src/api/typed-endpoints.js.map +1 -0
- package/dist/src/api/validation.d.ts +114 -0
- package/dist/src/api/validation.d.ts.map +1 -0
- package/dist/src/api/validation.js +128 -0
- package/dist/src/api/validation.js.map +1 -0
- package/dist/src/client/FlashnetClient.d.ts +216 -0
- package/dist/src/client/FlashnetClient.d.ts.map +1 -0
- package/dist/src/client/FlashnetClient.js +800 -0
- package/dist/src/client/FlashnetClient.js.map +1 -0
- package/dist/src/config/index.d.ts +14 -0
- package/dist/src/config/index.d.ts.map +1 -0
- package/dist/src/config/index.js +40 -0
- package/dist/src/config/index.js.map +1 -0
- package/dist/src/types/index.d.ts +484 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/types/index.js +2 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/utils/auth.d.ts +26 -0
- package/dist/src/utils/auth.d.ts.map +1 -0
- package/dist/src/utils/auth.js +85 -0
- package/dist/src/utils/auth.js.map +1 -0
- package/dist/src/utils/index.d.ts +8 -0
- package/dist/src/utils/index.d.ts.map +1 -0
- package/dist/src/utils/index.js +19 -0
- package/dist/src/utils/index.js.map +1 -0
- package/dist/src/utils/intents.d.ts +86 -0
- package/dist/src/utils/intents.d.ts.map +1 -0
- package/dist/src/utils/intents.js +133 -0
- package/dist/src/utils/intents.js.map +1 -0
- package/dist/src/utils/signer.d.ts +29 -0
- package/dist/src/utils/signer.d.ts.map +1 -0
- package/dist/src/utils/signer.js +34 -0
- package/dist/src/utils/signer.js.map +1 -0
- package/dist/src/utils/spark-address.d.ts +60 -0
- package/dist/src/utils/spark-address.d.ts.map +1 -0
- package/dist/src/utils/spark-address.js +227 -0
- package/dist/src/utils/spark-address.js.map +1 -0
- package/package.json +43 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
export class AuthManager {
|
|
2
|
+
apiClient;
|
|
3
|
+
wallet;
|
|
4
|
+
signer;
|
|
5
|
+
pubkey;
|
|
6
|
+
/**
|
|
7
|
+
* Create an AuthManager with either a wallet or a custom signer
|
|
8
|
+
* @param apiClient - The API client instance
|
|
9
|
+
* @param pubkey - The public key associated with the signer
|
|
10
|
+
* @param signerOrWallet - Either a Spark wallet or a custom signer
|
|
11
|
+
*/
|
|
12
|
+
constructor(apiClient, pubkey, signerOrWallet) {
|
|
13
|
+
this.apiClient = apiClient;
|
|
14
|
+
this.pubkey = pubkey;
|
|
15
|
+
// Check if it's a wallet (has getIdentityPublicKey method) or a signer
|
|
16
|
+
if ("getIdentityPublicKey" in signerOrWallet) {
|
|
17
|
+
this.wallet = signerOrWallet;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
this.signer = signerOrWallet;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Sign a message with either the wallet's identity key or the custom signer
|
|
25
|
+
*/
|
|
26
|
+
async signMessage(message) {
|
|
27
|
+
try {
|
|
28
|
+
const messageBytes = message.startsWith("0x")
|
|
29
|
+
? Buffer.from(message.slice(2), "hex")
|
|
30
|
+
: Buffer.from(message, "hex");
|
|
31
|
+
const messageHash = new Uint8Array(await crypto.subtle.digest("SHA-256", messageBytes));
|
|
32
|
+
let signature;
|
|
33
|
+
if (this.wallet) {
|
|
34
|
+
// Use wallet signing
|
|
35
|
+
signature =
|
|
36
|
+
// @ts-expect-error
|
|
37
|
+
await this.wallet.config.signer.signMessageWithIdentityKey(messageHash, true);
|
|
38
|
+
}
|
|
39
|
+
else if (this.signer) {
|
|
40
|
+
// Use custom signer
|
|
41
|
+
signature = await this.signer.signMessage(messageHash);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
throw new Error("No wallet or signer available");
|
|
45
|
+
}
|
|
46
|
+
return Buffer.from(signature).toString("hex");
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
throw new Error(`Failed to sign message: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Authenticate with the AMM API and get an access token
|
|
54
|
+
*/
|
|
55
|
+
async authenticate() {
|
|
56
|
+
try {
|
|
57
|
+
// Step 1: Get challenge
|
|
58
|
+
const challengeRequest = {
|
|
59
|
+
publicKey: this.pubkey,
|
|
60
|
+
};
|
|
61
|
+
const challengeResponse = await this.apiClient.ammPost("/v1/auth/challenge", challengeRequest);
|
|
62
|
+
if (!challengeResponse.challenge) {
|
|
63
|
+
throw new Error("No challenge received from server");
|
|
64
|
+
}
|
|
65
|
+
// Step 2: Sign the challenge
|
|
66
|
+
const signature = await this.signMessage(challengeResponse.challenge);
|
|
67
|
+
// Step 3: Verify signature and get access token
|
|
68
|
+
const verifyRequest = {
|
|
69
|
+
publicKey: this.pubkey,
|
|
70
|
+
signature,
|
|
71
|
+
};
|
|
72
|
+
const verifyResponse = await this.apiClient.ammPost("/v1/auth/verify", verifyRequest);
|
|
73
|
+
if (!verifyResponse.accessToken) {
|
|
74
|
+
throw new Error("No access token received from server");
|
|
75
|
+
}
|
|
76
|
+
// Set the token in the API client
|
|
77
|
+
this.apiClient.setAuthToken(verifyResponse.accessToken);
|
|
78
|
+
return verifyResponse.accessToken;
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
throw new Error(`Authentication failed: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
82
|
+
}
|
|
83
|
+
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I,KAAK,CAAC,sCAAsC,CAAC,CAAC;YAC1D,CAAC;YAED,kCAAkC;YAClC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;YAExD,OAAO,cAAc,CAAC,WAAW,CAAC;QACpC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CACb,0BACE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAC3C,EAAE,CACH,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./auth";
|
|
2
|
+
export * from "./intents";
|
|
3
|
+
export * from "./spark-address";
|
|
4
|
+
export declare function generateNonce(): string;
|
|
5
|
+
export declare function toSmallestUnit(amount: number, decimals: number): bigint;
|
|
6
|
+
export declare function fromSmallestUnit(amount: bigint | string | number, decimals: number): number;
|
|
7
|
+
export { createWalletSigner } from "../utils/signer";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAGhC,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAGD,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEvE;AAGD,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAChC,QAAQ,EAAE,MAAM,GACf,MAAM,CAGR;AAGD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export * from "./auth";
|
|
2
|
+
export * from "./intents";
|
|
3
|
+
export * from "./spark-address";
|
|
4
|
+
// Helper function to generate UUID (nonce)
|
|
5
|
+
export function generateNonce() {
|
|
6
|
+
return crypto.randomUUID();
|
|
7
|
+
}
|
|
8
|
+
// Helper function to convert decimal amounts to smallest units
|
|
9
|
+
export function toSmallestUnit(amount, decimals) {
|
|
10
|
+
return BigInt(Math.floor(amount * 10 ** decimals));
|
|
11
|
+
}
|
|
12
|
+
// Helper function to convert from smallest units to decimal
|
|
13
|
+
export function fromSmallestUnit(amount, decimals) {
|
|
14
|
+
const bigintAmount = typeof amount === "bigint" ? amount : BigInt(amount);
|
|
15
|
+
return Number(bigintAmount) / 10 ** decimals;
|
|
16
|
+
}
|
|
17
|
+
// Export the createWalletSigner utility
|
|
18
|
+
export { createWalletSigner } from "../utils/signer";
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAEhC,2CAA2C;AAC3C,MAAM,UAAU,aAAa;IAC3B,OAAO,MAAM,CAAC,UAAU,EAAE,CAAC;AAC7B,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,cAAc,CAAC,MAAc,EAAE,QAAgB;IAC7D,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,EAAE,IAAI,QAAQ,CAAC,CAAC,CAAC;AACrD,CAAC;AAED,4DAA4D;AAC5D,MAAM,UAAU,gBAAgB,CAC9B,MAAgC,EAChC,QAAgB;IAEhB,MAAM,YAAY,GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC1E,OAAO,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,IAAI,QAAQ,CAAC;AAC/C,CAAC;AAED,wCAAwC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { AmmAddLiquiditySettlementRequest, AmmRemoveLiquiditySettlementRequest } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Generates a pool initialization intent message
|
|
4
|
+
* @param params Parameters for pool initialization
|
|
5
|
+
* @returns The serialized intent message as ValidateAmmInitializeSingleSidedPoolData
|
|
6
|
+
*/
|
|
7
|
+
export declare function generatePoolInitializationIntentMessage(params: {
|
|
8
|
+
poolOwnerPublicKey: string;
|
|
9
|
+
assetATokenPublicKey: string;
|
|
10
|
+
assetBTokenPublicKey: string;
|
|
11
|
+
assetAInitialReserve: string;
|
|
12
|
+
assetAInitialVirtualReserve: string;
|
|
13
|
+
assetBInitialVirtualReserve: string;
|
|
14
|
+
threshold: string;
|
|
15
|
+
lpFeeRateBps: string;
|
|
16
|
+
totalHostFeeRateBps: string;
|
|
17
|
+
nonce: string;
|
|
18
|
+
}): Uint8Array;
|
|
19
|
+
/**
|
|
20
|
+
* Generates a constant product pool initialization intent message
|
|
21
|
+
* @param params Parameters for constant product pool initialization
|
|
22
|
+
* @returns The serialized intent message as ValidateAmmInitializeConstantProductPoolData
|
|
23
|
+
*/
|
|
24
|
+
export declare function generateConstantProductPoolInitializationIntentMessage(params: {
|
|
25
|
+
poolOwnerPublicKey: string;
|
|
26
|
+
assetATokenPublicKey: string;
|
|
27
|
+
assetBTokenPublicKey: string;
|
|
28
|
+
lpFeeRateBps: string;
|
|
29
|
+
totalHostFeeRateBps: string;
|
|
30
|
+
nonce: string;
|
|
31
|
+
}): Uint8Array;
|
|
32
|
+
/**
|
|
33
|
+
* Generates a pool confirm initial deposit intent message
|
|
34
|
+
* @param params Parameters for confirming initial deposit
|
|
35
|
+
* @returns The serialized intent message
|
|
36
|
+
*/
|
|
37
|
+
export declare function generatePoolConfirmInitialDepositIntentMessage(params: {
|
|
38
|
+
poolOwnerPublicKey: string;
|
|
39
|
+
lpIdentityPublicKey: string;
|
|
40
|
+
assetASparkTransferId: string;
|
|
41
|
+
nonce: string;
|
|
42
|
+
}): Uint8Array;
|
|
43
|
+
/**
|
|
44
|
+
* Generates a pool swap intent message
|
|
45
|
+
* @param params Parameters for swap
|
|
46
|
+
* @returns The serialized intent message
|
|
47
|
+
*/
|
|
48
|
+
export declare function generatePoolSwapIntentMessage(params: {
|
|
49
|
+
userPublicKey: string;
|
|
50
|
+
lpIdentityPublicKey: string;
|
|
51
|
+
assetASparkTransferId: string;
|
|
52
|
+
assetInTokenPublicKey: string;
|
|
53
|
+
assetOutTokenPublicKey: string;
|
|
54
|
+
amountIn: string;
|
|
55
|
+
minAmountOut: string;
|
|
56
|
+
maxSlippageBps: string;
|
|
57
|
+
nonce: string;
|
|
58
|
+
}): Uint8Array;
|
|
59
|
+
/**
|
|
60
|
+
* Generate the intent message for adding liquidity
|
|
61
|
+
*/
|
|
62
|
+
export declare function generateAddLiquidityIntentMessage(params: AmmAddLiquiditySettlementRequest): Uint8Array;
|
|
63
|
+
/**
|
|
64
|
+
* Generate the intent message for removing liquidity
|
|
65
|
+
*/
|
|
66
|
+
export declare function generateRemoveLiquidityIntentMessage(params: AmmRemoveLiquiditySettlementRequest): Uint8Array;
|
|
67
|
+
/**
|
|
68
|
+
* Generate the intent message for registering a host
|
|
69
|
+
*/
|
|
70
|
+
export declare function generateRegisterHostIntentMessage(params: {
|
|
71
|
+
namespace: string;
|
|
72
|
+
minFeeBps: number;
|
|
73
|
+
feeRecipientPublicKey: string;
|
|
74
|
+
nonce: string;
|
|
75
|
+
}): Uint8Array;
|
|
76
|
+
/**
|
|
77
|
+
* Generate the intent message for withdrawing host fees
|
|
78
|
+
*/
|
|
79
|
+
export declare function generateWithdrawHostFeesIntentMessage(params: {
|
|
80
|
+
hostPublicKey: string;
|
|
81
|
+
lpIdentityPublicKey: string;
|
|
82
|
+
assetAAmount?: string;
|
|
83
|
+
assetBAmount?: string;
|
|
84
|
+
nonce: string;
|
|
85
|
+
}): Uint8Array;
|
|
86
|
+
//# sourceMappingURL=intents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intents.d.ts","sourceRoot":"","sources":["../../../src/utils/intents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gCAAgC,EAChC,mCAAmC,EAKpC,MAAM,UAAU,CAAC;AAElB;;;;GAIG;AACH,wBAAgB,uCAAuC,CAAC,MAAM,EAAE;IAC9D,kBAAkB,EAAE,MAAM,CAAC;IAC3B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,2BAA2B,EAAE,MAAM,CAAC;IACpC,2BAA2B,EAAE,MAAM,CAAC;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,KAAK,EAAE,MAAM,CAAC;CACf,GAAG,UAAU,CAgBb;AAED;;;;GAIG;AACH,wBAAgB,sDAAsD,CAAC,MAAM,EAAE;IAC7E,kBAAkB,EAAE,MAAM,CAAC;IAC3B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,YAAY,EAAE,MAAM,CAAC;IACrB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,KAAK,EAAE,MAAM,CAAC;CACf,GAAG,UAAU,CAYb;AAED;;;;GAIG;AACH,wBAAgB,8CAA8C,CAAC,MAAM,EAAE;IACrE,kBAAkB,EAAE,MAAM,CAAC;IAC3B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,KAAK,EAAE,MAAM,CAAC;CACf,GAAG,UAAU,CAQb;AAED;;;;GAIG;AACH,wBAAgB,6BAA6B,CAAC,MAAM,EAAE;IACpD,aAAa,EAAE,MAAM,CAAC;IACtB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,sBAAsB,EAAE,MAAM,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;CACf,GAAG,UAAU,CAcb;AAED;;GAEG;AACH,wBAAgB,iCAAiC,CAC/C,MAAM,EAAE,gCAAgC,GACvC,UAAU,CAcZ;AAED;;GAEG;AACH,wBAAgB,oCAAoC,CAClD,MAAM,EAAE,mCAAmC,GAC1C,UAAU,CAWZ;AAED;;GAEG;AACH,wBAAgB,iCAAiC,CAAC,MAAM,EAAE;IACxD,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,KAAK,EAAE,MAAM,CAAC;CACf,GAAG,UAAU,CAYb;AAED;;GAEG;AACH,wBAAgB,qCAAqC,CAAC,MAAM,EAAE;IAC5D,aAAa,EAAE,MAAM,CAAC;IACtB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;CACf,GAAG,UAAU,CAYb"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a pool initialization intent message
|
|
3
|
+
* @param params Parameters for pool initialization
|
|
4
|
+
* @returns The serialized intent message as ValidateAmmInitializeSingleSidedPoolData
|
|
5
|
+
*/
|
|
6
|
+
export function generatePoolInitializationIntentMessage(params) {
|
|
7
|
+
const intentMessage = {
|
|
8
|
+
poolOwnerPublicKey: params.poolOwnerPublicKey,
|
|
9
|
+
assetATokenPublicKey: params.assetATokenPublicKey,
|
|
10
|
+
assetBTokenPublicKey: params.assetBTokenPublicKey,
|
|
11
|
+
assetAInitialReserve: params.assetAInitialReserve,
|
|
12
|
+
assetAInitialVirtualReserve: params.assetAInitialVirtualReserve,
|
|
13
|
+
assetBInitialVirtualReserve: params.assetBInitialVirtualReserve,
|
|
14
|
+
threshold: params.threshold,
|
|
15
|
+
hostFeeShares: [],
|
|
16
|
+
totalHostFeeRateBps: params.totalHostFeeRateBps,
|
|
17
|
+
lpFeeRateBps: params.lpFeeRateBps,
|
|
18
|
+
nonce: params.nonce,
|
|
19
|
+
};
|
|
20
|
+
return new TextEncoder().encode(JSON.stringify(intentMessage));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Generates a constant product pool initialization intent message
|
|
24
|
+
* @param params Parameters for constant product pool initialization
|
|
25
|
+
* @returns The serialized intent message as ValidateAmmInitializeConstantProductPoolData
|
|
26
|
+
*/
|
|
27
|
+
export function generateConstantProductPoolInitializationIntentMessage(params) {
|
|
28
|
+
const intentMessage = {
|
|
29
|
+
poolOwnerPublicKey: params.poolOwnerPublicKey,
|
|
30
|
+
assetATokenPublicKey: params.assetATokenPublicKey,
|
|
31
|
+
assetBTokenPublicKey: params.assetBTokenPublicKey,
|
|
32
|
+
hostFeeShares: [],
|
|
33
|
+
totalHostFeeRateBps: params.totalHostFeeRateBps,
|
|
34
|
+
lpFeeRateBps: params.lpFeeRateBps,
|
|
35
|
+
nonce: params.nonce,
|
|
36
|
+
};
|
|
37
|
+
return new TextEncoder().encode(JSON.stringify(intentMessage));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Generates a pool confirm initial deposit intent message
|
|
41
|
+
* @param params Parameters for confirming initial deposit
|
|
42
|
+
* @returns The serialized intent message
|
|
43
|
+
*/
|
|
44
|
+
export function generatePoolConfirmInitialDepositIntentMessage(params) {
|
|
45
|
+
const intentMessage = {
|
|
46
|
+
poolOwnerPublicKey: params.poolOwnerPublicKey,
|
|
47
|
+
lpIdentityPublicKey: params.lpIdentityPublicKey,
|
|
48
|
+
assetASparkTransferId: params.assetASparkTransferId,
|
|
49
|
+
nonce: params.nonce,
|
|
50
|
+
};
|
|
51
|
+
return new TextEncoder().encode(JSON.stringify(intentMessage));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Generates a pool swap intent message
|
|
55
|
+
* @param params Parameters for swap
|
|
56
|
+
* @returns The serialized intent message
|
|
57
|
+
*/
|
|
58
|
+
export function generatePoolSwapIntentMessage(params) {
|
|
59
|
+
const intentMessage = {
|
|
60
|
+
userPublicKey: params.userPublicKey,
|
|
61
|
+
lpIdentityPublicKey: params.lpIdentityPublicKey,
|
|
62
|
+
assetASparkTransferId: params.assetASparkTransferId,
|
|
63
|
+
assetInTokenPublicKey: params.assetInTokenPublicKey,
|
|
64
|
+
assetOutTokenPublicKey: params.assetOutTokenPublicKey,
|
|
65
|
+
amountIn: params.amountIn,
|
|
66
|
+
minAmountOut: params.minAmountOut,
|
|
67
|
+
maxSlippageBps: params.maxSlippageBps,
|
|
68
|
+
nonce: params.nonce,
|
|
69
|
+
};
|
|
70
|
+
return new TextEncoder().encode(JSON.stringify(intentMessage));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Generate the intent message for adding liquidity
|
|
74
|
+
*/
|
|
75
|
+
export function generateAddLiquidityIntentMessage(params) {
|
|
76
|
+
// Create the signing payload with sorted keys
|
|
77
|
+
const signingPayload = {
|
|
78
|
+
userPublicKey: params.userPublicKey,
|
|
79
|
+
lpIdentityPublicKey: params.lpIdentityPublicKey,
|
|
80
|
+
assetASparkTransferId: params.assetASparkTransferId,
|
|
81
|
+
assetBSparkTransferId: params.assetBSparkTransferId,
|
|
82
|
+
assetAAmount: BigInt(params.assetAAmount).toString(),
|
|
83
|
+
assetBAmount: BigInt(params.assetBAmount).toString(),
|
|
84
|
+
nonce: params.nonce,
|
|
85
|
+
};
|
|
86
|
+
// Return as Uint8Array for consistent handling
|
|
87
|
+
return new TextEncoder().encode(JSON.stringify(signingPayload));
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Generate the intent message for removing liquidity
|
|
91
|
+
*/
|
|
92
|
+
export function generateRemoveLiquidityIntentMessage(params) {
|
|
93
|
+
// Create the signing payload with sorted keys
|
|
94
|
+
const signingPayload = {
|
|
95
|
+
userPublicKey: params.userPublicKey,
|
|
96
|
+
lpIdentityPublicKey: params.lpIdentityPublicKey,
|
|
97
|
+
lpTokensToRemove: params.lpTokensToRemove,
|
|
98
|
+
nonce: params.nonce,
|
|
99
|
+
};
|
|
100
|
+
// Return as Uint8Array for consistent handling
|
|
101
|
+
return new TextEncoder().encode(JSON.stringify(signingPayload));
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Generate the intent message for registering a host
|
|
105
|
+
*/
|
|
106
|
+
export function generateRegisterHostIntentMessage(params) {
|
|
107
|
+
// Create the signing payload following the camelCase pattern
|
|
108
|
+
const signingPayload = {
|
|
109
|
+
namespace: params.namespace,
|
|
110
|
+
minFeeBps: params.minFeeBps,
|
|
111
|
+
feeRecipientPublicKey: params.feeRecipientPublicKey,
|
|
112
|
+
nonce: params.nonce,
|
|
113
|
+
signature: "",
|
|
114
|
+
};
|
|
115
|
+
// Return as Uint8Array for consistent handling
|
|
116
|
+
return new TextEncoder().encode(JSON.stringify(signingPayload));
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Generate the intent message for withdrawing host fees
|
|
120
|
+
*/
|
|
121
|
+
export function generateWithdrawHostFeesIntentMessage(params) {
|
|
122
|
+
// Create the signing payload with camelCase fields matching ValidateAmmWithdrawHostFeesData
|
|
123
|
+
const signingPayload = {
|
|
124
|
+
hostPublicKey: params.hostPublicKey,
|
|
125
|
+
lpIdentityPublicKey: params.lpIdentityPublicKey,
|
|
126
|
+
assetAAmount: params.assetAAmount,
|
|
127
|
+
assetBAmount: params.assetBAmount,
|
|
128
|
+
nonce: params.nonce,
|
|
129
|
+
};
|
|
130
|
+
// Return as Uint8Array for consistent handling
|
|
131
|
+
return new TextEncoder().encode(JSON.stringify(signingPayload));
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=intents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intents.js","sourceRoot":"","sources":["../../../src/utils/intents.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,MAAM,UAAU,uCAAuC,CAAC,MAWvD;IACC,MAAM,aAAa,GAA6C;QAC9D,kBAAkB,EAAE,MAAM,CAAC,kBAAkB;QAC7C,oBAAoB,EAAE,MAAM,CAAC,oBAAoB;QACjD,oBAAoB,EAAE,MAAM,CAAC,oBAAoB;QACjD,oBAAoB,EAAE,MAAM,CAAC,oBAAoB;QACjD,2BAA2B,EAAE,MAAM,CAAC,2BAA2B;QAC/D,2BAA2B,EAAE,MAAM,CAAC,2BAA2B;QAC/D,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,aAAa,EAAE,EAAE;QACjB,mBAAmB,EAAE,MAAM,CAAC,mBAAmB;QAC/C,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,KAAK,EAAE,MAAM,CAAC,KAAK;KACpB,CAAC;IAEF,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC;AACjE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,sDAAsD,CAAC,MAOtE;IACC,MAAM,aAAa,GAAiD;QAClE,kBAAkB,EAAE,MAAM,CAAC,kBAAkB;QAC7C,oBAAoB,EAAE,MAAM,CAAC,oBAAoB;QACjD,oBAAoB,EAAE,MAAM,CAAC,oBAAoB;QACjD,aAAa,EAAE,EAAE;QACjB,mBAAmB,EAAE,MAAM,CAAC,mBAAmB;QAC/C,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,KAAK,EAAE,MAAM,CAAC,KAAK;KACpB,CAAC;IAEF,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,aAAa,CAA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AE,MAAM,CAAC,YAAY;QACjC,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,KAAK,EAAE,MAAM,CAAC,KAAK;KACpB,CAAC;IAEF,+CAA+C;IAC/C,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { IssuerSparkWallet } from "@buildonspark/issuer-sdk";
|
|
2
|
+
import type { SparkWallet } from "@buildonspark/spark-sdk";
|
|
3
|
+
import type { Signer } from "../types";
|
|
4
|
+
/**
|
|
5
|
+
* Creates a Signer implementation from a SparkWallet
|
|
6
|
+
* This allows using SparkWallet's signing capabilities through the generic Signer interface
|
|
7
|
+
*
|
|
8
|
+
* @param wallet - The SparkWallet instance
|
|
9
|
+
* @returns A Signer implementation
|
|
10
|
+
*/
|
|
11
|
+
export declare function createWalletSigner(wallet: IssuerSparkWallet | SparkWallet): Signer;
|
|
12
|
+
/**
|
|
13
|
+
* Example of a custom signer implementation using a private key
|
|
14
|
+
* This is just an example - users would implement their own signers
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* class PrivateKeySigner implements Signer {
|
|
19
|
+
* constructor(private privateKey: Uint8Array) {}
|
|
20
|
+
*
|
|
21
|
+
* async signMessage(message: Uint8Array): Promise<Uint8Array> {
|
|
22
|
+
* // Implementation would use the private key to sign the message
|
|
23
|
+
* // This is just a placeholder
|
|
24
|
+
* throw new Error("Not implemented - use your own signing library");
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
//# sourceMappingURL=signer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../../src/utils/signer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,iBAAiB,GAAG,WAAW,GACtC,MAAM,CAWR;AAED;;;;;;;;;;;;;;;;GAgBG"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a Signer implementation from a SparkWallet
|
|
3
|
+
* This allows using SparkWallet's signing capabilities through the generic Signer interface
|
|
4
|
+
*
|
|
5
|
+
* @param wallet - The SparkWallet instance
|
|
6
|
+
* @returns A Signer implementation
|
|
7
|
+
*/
|
|
8
|
+
export function createWalletSigner(wallet) {
|
|
9
|
+
return {
|
|
10
|
+
async signMessage(message) {
|
|
11
|
+
// @ts-expect-error - accessing internal wallet API
|
|
12
|
+
const signature = await wallet.config.signer.signMessageWithIdentityKey(message, true);
|
|
13
|
+
return signature;
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Example of a custom signer implementation using a private key
|
|
19
|
+
* This is just an example - users would implement their own signers
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* class PrivateKeySigner implements Signer {
|
|
24
|
+
* constructor(private privateKey: Uint8Array) {}
|
|
25
|
+
*
|
|
26
|
+
* async signMessage(message: Uint8Array): Promise<Uint8Array> {
|
|
27
|
+
* // Implementation would use the private key to sign the message
|
|
28
|
+
* // This is just a placeholder
|
|
29
|
+
* throw new Error("Not implemented - use your own signing library");
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
//# sourceMappingURL=signer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../../../src/utils/signer.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAChC,MAAuC;IAEvC,OAAO;QACL,KAAK,CAAC,WAAW,CAAC,OAAmB;YACnC,mDAAmD;YACnD,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,0BAA0B,CACrE,OAAO,EACP,IAAI,CACL,CAAC;YACF,OAAO,SAAS,CAAC;QACnB,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export type NetworkType = 'MAINNET' | 'TESTNET' | 'SIGNET' | 'REGTEST' | 'LOCAL';
|
|
2
|
+
declare const AddressNetworkPrefix: Record<NetworkType, string>;
|
|
3
|
+
export type SparkAddressFormat = `${(typeof AddressNetworkPrefix)[keyof typeof AddressNetworkPrefix]}1${string}`;
|
|
4
|
+
export interface SparkAddressData {
|
|
5
|
+
identityPublicKey: string;
|
|
6
|
+
network: NetworkType;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Encodes a public key and network into a Spark address
|
|
10
|
+
* @param payload Object containing hex public key and network type
|
|
11
|
+
* @returns Bech32m encoded Spark address
|
|
12
|
+
*/
|
|
13
|
+
export declare function encodeSparkAddress(payload: SparkAddressData): SparkAddressFormat;
|
|
14
|
+
/**
|
|
15
|
+
* Decodes a Spark address to extract the public key
|
|
16
|
+
* @param address Bech32m encoded Spark address
|
|
17
|
+
* @param network Expected network type (used to check prefix)
|
|
18
|
+
* @returns Hex-encoded public key
|
|
19
|
+
* @throws Error if address format, prefix, or decoded key is invalid
|
|
20
|
+
*/
|
|
21
|
+
export declare function decodeSparkAddress(address: string, network: NetworkType): string;
|
|
22
|
+
/**
|
|
23
|
+
* Attempts to determine the network type from a Spark address prefix.
|
|
24
|
+
* @param address The potential Spark address.
|
|
25
|
+
* @returns The NetworkType ('MAINNET', 'REGTEST', etc.) or null if the prefix is invalid.
|
|
26
|
+
*/
|
|
27
|
+
export declare function getNetworkFromAddress(address: string): NetworkType | null;
|
|
28
|
+
/**
|
|
29
|
+
* Checks if a string is a valid Spark address for *any* known network,
|
|
30
|
+
* and optionally validates against a specific network.
|
|
31
|
+
* @param address String to validate
|
|
32
|
+
* @param network Optional specific network type to check against
|
|
33
|
+
* @returns Boolean indicating validity
|
|
34
|
+
*/
|
|
35
|
+
export declare function isValidSparkAddress(address: string, network?: NetworkType): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Checks if a string looks like a valid hex-encoded public key (basic check).
|
|
38
|
+
* Does NOT validate point on curve here, use isValidPublicKey for that.
|
|
39
|
+
* @param key The potential public key hex string.
|
|
40
|
+
* @returns True if it matches the basic format, false otherwise.
|
|
41
|
+
*/
|
|
42
|
+
export declare function looksLikePublicKey(key: string): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Validates a secp256k1 public key format and curve point.
|
|
45
|
+
* @param publicKey Hex-encoded public key
|
|
46
|
+
* @throws Error if public key is invalid
|
|
47
|
+
*/
|
|
48
|
+
export declare function isValidPublicKey(publicKey: string): void;
|
|
49
|
+
/**
|
|
50
|
+
* Converts a Spark address to a specific network.
|
|
51
|
+
* If the address is already on the requested network, it returns the original address.
|
|
52
|
+
* Otherwise, it extracts the public key and creates a new address for the target network.
|
|
53
|
+
*
|
|
54
|
+
* @param sparkAddress The Spark address to convert
|
|
55
|
+
* @param targetNetwork The target network ('mainnet' or 'regtest')
|
|
56
|
+
* @returns The Spark address for the target network or null if conversion fails
|
|
57
|
+
*/
|
|
58
|
+
export declare function convertSparkAddressToNetwork(sparkAddress: string, targetNetwork: 'mainnet' | 'regtest'): string | null;
|
|
59
|
+
export {};
|
|
60
|
+
//# sourceMappingURL=spark-address.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spark-address.d.ts","sourceRoot":"","sources":["../../../src/utils/spark-address.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,WAAW,GACnB,SAAS,GACT,SAAS,GACT,QAAQ,GACR,SAAS,GACT,OAAO,CAAC;AAEZ,QAAA,MAAM,oBAAoB,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAM5C,CAAC;AASX,MAAM,MAAM,kBAAkB,GAC5B,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,OAAO,oBAAoB,CAAC,IAAI,MAAM,EAAE,CAAC;AAElF,MAAM,WAAW,gBAAgB;IAC/B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,OAAO,EAAE,WAAW,CAAC;CACtB;AA0DD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,gBAAgB,GACxB,kBAAkB,CAiBpB;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,WAAW,GACnB,MAAM,CAuBR;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAUzE;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CA+BT;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAKvD;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,QAYjD;AAED;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAC1C,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,SAAS,GAAG,SAAS,GACnC,MAAM,GAAG,IAAI,CAoCf"}
|