@silentswap/sdk 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/sdk.d.ts ADDED
@@ -0,0 +1,161 @@
1
+ import type { Base64, SignInMessage } from './types/core.js';
2
+ import type { QuoteResponse } from './types/api.js';
3
+ import type { Hex } from 'viem';
4
+ /**
5
+ * Creates a SIWE message for authentication with SilentSwap
6
+ * @param user - user's EVM address
7
+ * @param nonce - nonce from the server (base58)
8
+ * @returns SIWE message
9
+ */
10
+ export declare function createSignInMessage(user: Hex, nonce: string): SignInMessage;
11
+ /**
12
+ * Creates an EIP-712 document for a SilentSwap order
13
+ * @param quote - quote response
14
+ * @returns EIP-712 document
15
+ */
16
+ export declare function createEip712DocForOrder(quote: QuoteResponse): {
17
+ types: {
18
+ readonly EIP712Domain: readonly [{
19
+ readonly name: "name";
20
+ readonly type: "string";
21
+ }, {
22
+ readonly name: "version";
23
+ readonly type: "string";
24
+ }, {
25
+ readonly name: "chainId";
26
+ readonly type: "uint256";
27
+ }];
28
+ readonly Order: readonly [{
29
+ readonly name: "quoteId";
30
+ readonly type: "string";
31
+ }, {
32
+ readonly name: "quote";
33
+ readonly type: "Quote";
34
+ }];
35
+ readonly Quote: readonly [{
36
+ readonly name: "signer";
37
+ readonly type: "address";
38
+ }, {
39
+ readonly name: "nonce";
40
+ readonly type: "uint256";
41
+ }, {
42
+ readonly name: "privacy";
43
+ readonly type: "string";
44
+ }, {
45
+ readonly name: "deposit";
46
+ readonly type: "uint256";
47
+ }, {
48
+ readonly name: "fee";
49
+ readonly type: "uint256";
50
+ }, {
51
+ readonly name: "outputs";
52
+ readonly type: "Output[]";
53
+ }, {
54
+ readonly name: "metadata";
55
+ readonly type: "Metadata";
56
+ }];
57
+ readonly Output: readonly [{
58
+ readonly name: "method";
59
+ readonly type: "string";
60
+ }, {
61
+ readonly name: "asset";
62
+ readonly type: "string";
63
+ }, {
64
+ readonly name: "facilitatorPublicKeys";
65
+ readonly type: "Facilitator[]";
66
+ }, {
67
+ readonly name: "recipient";
68
+ readonly type: "string";
69
+ }, {
70
+ readonly name: "value";
71
+ readonly type: "uint256";
72
+ }, {
73
+ readonly name: "extra";
74
+ readonly type: "string";
75
+ }];
76
+ readonly Facilitator: readonly [{
77
+ readonly name: "coinType";
78
+ readonly type: "string";
79
+ }, {
80
+ readonly name: "keyType";
81
+ readonly type: "string";
82
+ }, {
83
+ readonly name: "publicKeyBytes";
84
+ readonly type: "bytes";
85
+ }];
86
+ readonly Metadata: readonly [{
87
+ readonly name: "notaryContract";
88
+ readonly type: "NotaryContract";
89
+ }];
90
+ readonly NotaryContract: readonly [{
91
+ readonly name: "chainId";
92
+ readonly type: "string";
93
+ }, {
94
+ readonly name: "contractAddress";
95
+ readonly type: "string";
96
+ }, {
97
+ readonly name: "encryptionPk33";
98
+ readonly type: "string";
99
+ }, {
100
+ readonly name: "signerAddress";
101
+ readonly type: "address";
102
+ }, {
103
+ readonly name: "sessionProof";
104
+ readonly type: "string";
105
+ }];
106
+ };
107
+ domain: {
108
+ readonly name: "SilentSwap v2";
109
+ readonly version: "1";
110
+ readonly chainId: 43114;
111
+ };
112
+ primaryType: "Order";
113
+ message: {
114
+ quoteId: string;
115
+ quote: {
116
+ nonce: string;
117
+ signer: Hex;
118
+ privacy: import("./order.js").PrivacySetting;
119
+ deposit: import("./types/core.js").IntStr;
120
+ fee: import("./types/core.js").IntStr;
121
+ outputs: Array<import("./order.js").OrderOutputArg>;
122
+ metadata: import("./order.js").OrderMetadata;
123
+ };
124
+ };
125
+ };
126
+ /**
127
+ * Creates an EIP-712 document for a SilentSwap wallet generator
128
+ * @param token - token to generate a wallet for
129
+ * @returns EIP-712 document
130
+ */
131
+ export declare function createEip712DocForWalletGeneration(token: string): {
132
+ types: {
133
+ readonly EIP712Domain: readonly [{
134
+ readonly name: "name";
135
+ readonly type: "string";
136
+ }, {
137
+ readonly name: "version";
138
+ readonly type: "string";
139
+ }, {
140
+ readonly name: "chainId";
141
+ readonly type: "uint256";
142
+ }];
143
+ readonly WalletGeneration: readonly [{
144
+ readonly name: "description";
145
+ readonly type: "string";
146
+ }, {
147
+ readonly name: "token";
148
+ readonly type: "string";
149
+ }];
150
+ };
151
+ domain: {
152
+ readonly name: "SilentSwap v2";
153
+ readonly version: "1";
154
+ readonly chainId: 43114;
155
+ };
156
+ primaryType: "WalletGeneration";
157
+ message: {
158
+ description: "Securely create a temporary, anonymous wallet for SilentSwap use only.";
159
+ token: Base64;
160
+ };
161
+ };
package/dist/sdk.js ADDED
@@ -0,0 +1,57 @@
1
+ import { createSiweMessage } from 'viem/siwe';
2
+ import { EIP712_DOMAIN_ORDER_DEFAULT, EIP712_TYPES_ORDER, EIP712_TYPES_WALLET_GENERATION } from './order.js';
3
+ /**
4
+ * Creates a SIWE message for authentication with SilentSwap
5
+ * @param user - user's EVM address
6
+ * @param nonce - nonce from the server (base58)
7
+ * @returns SIWE message
8
+ */
9
+ export function createSignInMessage(user, nonce) {
10
+ // create params
11
+ const params = {
12
+ domain: 'app.silentswap.com',
13
+ address: user,
14
+ statement: 'Sign in with Ethereum to SilentSwap',
15
+ uri: 'https://app.silentswap.com',
16
+ version: '1',
17
+ chainId: 1, // always Ethereum mainnet
18
+ nonce: nonce,
19
+ };
20
+ // prepare and return the message for signing
21
+ return {
22
+ params,
23
+ message: createSiweMessage(params),
24
+ };
25
+ }
26
+ /**
27
+ * Creates an EIP-712 document for a SilentSwap order
28
+ * @param quote - quote response
29
+ * @returns EIP-712 document
30
+ */
31
+ export function createEip712DocForOrder(quote) {
32
+ return {
33
+ types: EIP712_TYPES_ORDER,
34
+ domain: EIP712_DOMAIN_ORDER_DEFAULT,
35
+ primaryType: 'Order',
36
+ message: {
37
+ quoteId: quote.quoteId,
38
+ quote: { ...quote.quote },
39
+ },
40
+ };
41
+ }
42
+ /**
43
+ * Creates an EIP-712 document for a SilentSwap wallet generator
44
+ * @param token - token to generate a wallet for
45
+ * @returns EIP-712 document
46
+ */
47
+ export function createEip712DocForWalletGeneration(token) {
48
+ return {
49
+ types: EIP712_TYPES_WALLET_GENERATION,
50
+ domain: EIP712_DOMAIN_ORDER_DEFAULT,
51
+ primaryType: 'WalletGeneration',
52
+ message: {
53
+ description: 'Securely create a temporary, anonymous wallet for SilentSwap use only.',
54
+ token: token,
55
+ },
56
+ };
57
+ }
@@ -0,0 +1,16 @@
1
+ import type { EvmTransaction } from '../types/core.js';
2
+ import type { Account, Client, PrepareTransactionRequestParameters, PublicActions, WalletActions } from 'viem';
3
+ import type { EvmSigner } from '../types/sdk.js';
4
+ /**
5
+ * Creates an EvmSigner from a viem Account and Client.
6
+ * @param account the viem Account
7
+ * @param client the viem Client (must implement {@link PublicActions} and {@link WalletActions})
8
+ * @returns an {@link EvmSigner}
9
+ */
10
+ export declare function createViemSigner(account: Account, client: Client & PublicActions & WalletActions): EvmSigner;
11
+ /**
12
+ * Parses an EvmTransaction into a viem .
13
+ * @param tx the EvmTransaction to parse
14
+ * @returns a viem PrepareTransactionRequestParameters
15
+ */
16
+ export declare function parseTransactionRequestForViem(tx: EvmTransaction): PrepareTransactionRequestParameters<undefined, Account, undefined, undefined>;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Creates an EvmSigner from a viem Account and Client.
3
+ * @param account the viem Account
4
+ * @param client the viem Client (must implement {@link PublicActions} and {@link WalletActions})
5
+ * @returns an {@link EvmSigner}
6
+ */
7
+ export function createViemSigner(account, client) {
8
+ return {
9
+ address: account.address,
10
+ getTransactionCount: async () => client.getTransactionCount({ address: account.address }),
11
+ signEip191Message: message => client.signMessage({ account, message }),
12
+ signEip712TypedData: data => client.signTypedData({ account, ...data }),
13
+ };
14
+ }
15
+ /**
16
+ * Parses an EvmTransaction into a viem .
17
+ * @param tx the EvmTransaction to parse
18
+ * @returns a viem PrepareTransactionRequestParameters
19
+ */
20
+ export function parseTransactionRequestForViem(tx) {
21
+ return {
22
+ chainId: Number(tx.chainId),
23
+ to: tx.target,
24
+ data: tx.data,
25
+ nonce: tx.nonce,
26
+ value: BigInt(tx.value ?? 0),
27
+ maxPriorityFeePerGas: tx.maxPriorityFeePerGas ? BigInt(tx.maxPriorityFeePerGas) : undefined,
28
+ maxFeePerGas: tx.maxFeePerGas ? BigInt(tx.maxFeePerGas) : undefined,
29
+ };
30
+ }
@@ -0,0 +1,145 @@
1
+ import type { Hex } from 'viem';
2
+ import type { Base58, Base64, EvmTransaction, IntStr } from './core.js';
3
+ import type { AuthorizationInstruction, AuthorizationReply, FacilitatorInstruction, FacilitatorReply, OrderOutputArg, PrivacySetting, Quote } from '../order.js';
4
+ /**
5
+ * API response schema for /nonce endpoint
6
+ */
7
+ export type NonceResponse = {
8
+ readonly nonce: Base64;
9
+ };
10
+ /**
11
+ * API request body schema for /authenticate endpoint
12
+ */
13
+ export type AuthRequest = {
14
+ /**
15
+ * SIWE message and signature
16
+ */
17
+ siwe: {
18
+ message: string;
19
+ signature: Hex;
20
+ };
21
+ };
22
+ /**
23
+ * API response schema for /authenticate endpoint
24
+ */
25
+ export type AuthResponse = {
26
+ /**
27
+ * Signer address
28
+ */
29
+ readonly address: Hex;
30
+ /**
31
+ * Token to be used for generating a secret seed
32
+ */
33
+ readonly secretToken: Base64;
34
+ /**
35
+ * Denotes when the SIWE signature expires
36
+ */
37
+ readonly authExpires: number;
38
+ };
39
+ /**
40
+ * API request body schema for /quote endpoint
41
+ */
42
+ export type QuoteRequest = {
43
+ /**
44
+ * Address of the quote signer
45
+ */
46
+ signer: Hex;
47
+ /**
48
+ * Privacy setting
49
+ */
50
+ privacy?: PrivacySetting;
51
+ /**
52
+ * If ommitted, computes sum of `.outputs[i].value` and adds fees
53
+ */
54
+ deposit?: IntStr;
55
+ /**
56
+ * Optional 33-byte or 65-byte public key to use when deriving shared session secret
57
+ */
58
+ trustPublicKeyBytes?: Base64;
59
+ /**
60
+ * Output specifications
61
+ */
62
+ outputs: OrderOutputArg[];
63
+ };
64
+ /**
65
+ * API response schema for /quote endpoint
66
+ */
67
+ export type QuoteResponse = {
68
+ /**
69
+ * Quote ID required when placing an order
70
+ */
71
+ readonly quoteId: Base64;
72
+ /**
73
+ * Quote object contains details of the quote
74
+ */
75
+ readonly quote: Quote;
76
+ /**
77
+ * Array of authorizations required to be signed before placing an order
78
+ */
79
+ readonly authorizations: Array<AuthorizationInstruction>;
80
+ /**
81
+ * Array of facilitator instructions required to be signed before placing an order
82
+ */
83
+ readonly facilitators: Array<FacilitatorInstruction>;
84
+ };
85
+ /**
86
+ * API request body schema for /order endpoint
87
+ */
88
+ export type OrderRequest = Omit<QuoteResponse, 'authorizations' | 'facilitators'> & {
89
+ /**
90
+ * EIP-712 domain
91
+ */
92
+ eip712Domain: {
93
+ name: 'SilentSwap v2';
94
+ version?: IntStr;
95
+ chainId: number;
96
+ verifyingContract?: Hex;
97
+ };
98
+ /**
99
+ * Signature of the EIP-712 order document
100
+ */
101
+ signature: Hex;
102
+ /**
103
+ * Array of signed authorizations
104
+ */
105
+ authorizations: Array<AuthorizationReply>;
106
+ /**
107
+ * Array of signed facilitator instructions
108
+ */
109
+ facilitators: Array<FacilitatorReply>;
110
+ };
111
+ /**
112
+ * Parameters for the deposit transaction
113
+ */
114
+ export type DepositParams<B extends bigint | IntStr = bigint> = {
115
+ signer: Hex;
116
+ orderId: Hex;
117
+ notary: Hex;
118
+ approver: Hex;
119
+ orderApproval: Hex;
120
+ approvalExpiration: B;
121
+ duration: B;
122
+ domainSepHash: Hex;
123
+ payloadHash: Hex;
124
+ typedDataSignature: Hex;
125
+ receiveAuthorization: Hex;
126
+ };
127
+ /**
128
+ * API response schema for /order endpoint
129
+ */
130
+ export interface OrderResponse {
131
+ /**
132
+ * Deposit transaction
133
+ */
134
+ transaction: EvmTransaction<DepositParams<IntStr>>;
135
+ /**
136
+ * Order response object
137
+ */
138
+ response: {
139
+ approver: Hex;
140
+ orderApproval: Hex;
141
+ approvalExpiration: number;
142
+ orderId: Base58;
143
+ order: Quote;
144
+ };
145
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,245 @@
1
+ import type { Hex } from 'viem';
2
+ import type { Base64, IntStr, Json } from './core.js';
3
+ import type { AbiFunction, TypedDataDomain } from 'abitype';
4
+ /**
5
+ * For including the `entry_required` matcher
6
+ */
7
+ type IncludeRequired<M extends object> = M & {
8
+ entry_optional?: boolean;
9
+ };
10
+ /**
11
+ * Matches any value
12
+ */
13
+ export type MatcherAny = IncludeRequired<{
14
+ any_type: 'any' | 'boolean' | 'uint32' | 'uint256' | 'string' | 'array' | 'struct';
15
+ }> | {
16
+ entry_absent: true;
17
+ };
18
+ /**
19
+ * Matches a boolean
20
+ */
21
+ export type MatcherBoolean = MatcherAny | IncludeRequired<{
22
+ boolean_const: boolean;
23
+ }>;
24
+ /**
25
+ * Matches a uint32
26
+ */
27
+ export type MatcherUint32<L extends number = number> = MatcherAny | IncludeRequired<{
28
+ uint32_const: L;
29
+ } | {
30
+ uint32_enum: L[];
31
+ } | {
32
+ uint32_range: readonly [L, L | 'MAX'];
33
+ }>;
34
+ /**
35
+ * Matches a string
36
+ */
37
+ export type MatcherString<S extends string = string> = MatcherAny | IncludeRequired<{
38
+ string_const: S;
39
+ } | {
40
+ string_enum: S[];
41
+ }>;
42
+ /**
43
+ * Matches a uint128
44
+ */
45
+ export type MatcherUint128 = MatcherAny | IncludeRequired<{
46
+ uint128_const: IntStr;
47
+ } | {
48
+ uint128_enum: IntStr[];
49
+ } | {
50
+ uint128_range: readonly [IntStr, IntStr | 'MAX'];
51
+ }>;
52
+ /**
53
+ * Matches a uint256
54
+ */
55
+ export type MatcherUint256 = MatcherAny | IncludeRequired<{
56
+ uint256_const: IntStr;
57
+ } | {
58
+ uint256_enum: IntStr[];
59
+ } | {
60
+ uint256_range: readonly [IntStr, IntStr | 'MAX'];
61
+ }>;
62
+ /**
63
+ * Matches an Amino array
64
+ */
65
+ export type MatcherAminoArray = MatcherAny | IncludeRequired<({
66
+ array_unordered?: boolean;
67
+ array_items: {
68
+ item_optional?: boolean;
69
+ item_match: UnionAminoValue;
70
+ }[];
71
+ } | {
72
+ array_json: MatcherString<Json>;
73
+ })>;
74
+ /**
75
+ * Matches an Amino struct
76
+ */
77
+ export type MatcherAminoStruct = IncludeRequired<{
78
+ struct_entries: Record<string, UnionAminoValue>;
79
+ } | {
80
+ struct_json: MatcherString<Json>;
81
+ }>;
82
+ /**
83
+ * Union of matchers available to Amino
84
+ */
85
+ export type UnionAminoValue = MatcherBoolean | MatcherString | MatcherUint32 | MatcherUint128 | MatcherAminoArray | MatcherAminoStruct;
86
+ /**
87
+ * Matches an EVM address
88
+ */
89
+ export type MatcherEvmAddress = {
90
+ address_0x: MatcherString<Hex>;
91
+ };
92
+ /**
93
+ * Matches an EVM bytes
94
+ */
95
+ export type MatcherEvmBytes<L extends number = number> = {
96
+ bytes_len: MatcherUint32<L>;
97
+ bytes_hex: MatcherString;
98
+ };
99
+ /**
100
+ * Matches an EVM struct
101
+ */
102
+ export type MatcherEvmStruct<S extends Record<string, object> = Record<string, UnionEvmValue>> = {
103
+ struct_entries: S;
104
+ } | {
105
+ struct_json: MatcherString<Json>;
106
+ };
107
+ /**
108
+ * Union of matchers available to EVM
109
+ */
110
+ export type UnionEvmValuePrimitives = MatcherString | MatcherUint256 | MatcherEvmAddress | MatcherEvmBytes;
111
+ /**
112
+ * Union of matchers available to EVM
113
+ */
114
+ export type UnionEvmValue = UnionEvmValuePrimitives | MatcherEvmStruct<Record<string, UnionEvmValuePrimitives>>;
115
+ /**
116
+ * Helper utility type to vaidate a declared matcher type for JSON arrays
117
+ */
118
+ type ImplementsMatcherAminoArray<S extends MatcherAminoArray> = S;
119
+ /**
120
+ * Helper utility type to vaidate a declared matcher type for JSON structs
121
+ */
122
+ type ImplementsMatcherAminoStruct<S extends MatcherAminoStruct> = S;
123
+ /**
124
+ * Arbitrary Cosmos Amino
125
+ */
126
+ export type ProxyAuthMsgCosmosAmino = {
127
+ type: 'cosmos/amino-stdsigndoc';
128
+ signdoc: {
129
+ chain_id: MatcherString;
130
+ account_number: MatcherUint128;
131
+ sequence: MatcherUint128;
132
+ msgs: ImplementsMatcherAminoArray<{
133
+ array_unordered?: boolean;
134
+ array_items: {
135
+ item_optional?: boolean;
136
+ item_match: {
137
+ struct_entries: {
138
+ type: MatcherString;
139
+ value: MatcherAminoStruct;
140
+ };
141
+ };
142
+ }[];
143
+ } | {
144
+ array_json: MatcherString<Json>;
145
+ }>;
146
+ fee: ImplementsMatcherAminoStruct<{
147
+ struct_entries: {
148
+ amount: {
149
+ array_unordered?: false;
150
+ array_items: {
151
+ item_optional?: boolean;
152
+ item_match: {
153
+ struct_entries: {
154
+ denom: MatcherString;
155
+ amount: MatcherUint128;
156
+ };
157
+ };
158
+ }[];
159
+ };
160
+ gas: MatcherUint128;
161
+ };
162
+ } | {
163
+ struct_json: MatcherString<Json>;
164
+ }>;
165
+ memo: MatcherString;
166
+ };
167
+ metadata?: undefined | {
168
+ secret_wasm_seed?: Base64;
169
+ secret_wasm_nonce?: Base64;
170
+ };
171
+ };
172
+ /**
173
+ * EVM transaction
174
+ */
175
+ export type ProxyAuthMsgEvmTx = {
176
+ type: 'evm/tx';
177
+ to: MatcherEvmAddress;
178
+ value: MatcherUint256;
179
+ chainId: MatcherUint256;
180
+ nonce: MatcherUint256;
181
+ data: MatcherEvmBytes | {
182
+ functionAbi: Omit<AbiFunction, 'constant' | 'gas' | 'outputs' | 'payable' | 'stateMutability'>;
183
+ arguments: MatcherEvmStruct;
184
+ };
185
+ gas: {
186
+ type0: {
187
+ gasLimit: MatcherUint256;
188
+ gasPrice: MatcherUint256;
189
+ };
190
+ } | {
191
+ type2: {
192
+ gasLimit: MatcherUint256;
193
+ maxFeePerGas: MatcherUint256;
194
+ maxPriorityFeePerGas: MatcherUint256;
195
+ };
196
+ };
197
+ };
198
+ /**
199
+ * EVM EIP-712 typed data
200
+ */
201
+ export type ProxyAuthMsgEvmEip712 = {
202
+ type: 'evm/eip712';
203
+ domain: MatcherEvmStruct<{
204
+ name?: MatcherString;
205
+ version?: MatcherString;
206
+ chainId?: MatcherUint256;
207
+ verifyingContract?: MatcherEvmAddress;
208
+ salt?: MatcherEvmBytes<32>;
209
+ }>;
210
+ types: MatcherEvmStruct<{
211
+ EIP712Domain: object;
212
+ } & Record<string, object>>;
213
+ primaryType?: MatcherString;
214
+ message: MatcherEvmStruct;
215
+ };
216
+ export type ProxyAuthMsg = ProxyAuthMsgCosmosAmino | ProxyAuthMsgEvmTx | ProxyAuthMsgEvmEip712;
217
+ export type ProxyAuthContent = {
218
+ description?: undefined | string;
219
+ facilitator_pk: Hex;
220
+ executor_pk33: Base64;
221
+ message: ProxyAuthMsg;
222
+ };
223
+ export type ProxyAuthInstruction = {
224
+ id: Base64;
225
+ content: ProxyAuthContent;
226
+ };
227
+ export type ProxyAuthReply = ProxyAuthInstruction & {
228
+ signature: Hex;
229
+ };
230
+ export type ProxyAuthWrapper = {
231
+ content: ProxyAuthContent;
232
+ signatures: {
233
+ facilitator: Hex;
234
+ executor: Base64;
235
+ };
236
+ };
237
+ export type ProxyStructEvmEip712Config = {
238
+ domain: TypedDataDomain;
239
+ };
240
+ export type ProxyStructCosmWasmFeeConfig = {
241
+ denom: string;
242
+ gasPrice: number;
243
+ maxGasLimit: bigint;
244
+ };
245
+ export {};
@@ -0,0 +1 @@
1
+ export {};