@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.
@@ -0,0 +1,50 @@
1
+ import type { SiweMessage } from 'viem/siwe';
2
+ import type { Hex } from 'viem';
3
+ export type PromiseOrValue<T> = Promise<T> | T;
4
+ export type IntStr = `${bigint}`;
5
+ export type Base58 = string;
6
+ export type Base64 = string;
7
+ export type Json = string;
8
+ export type Bytesish = string | Hex | bigint | Uint8Array;
9
+ export type CoinTypeStr = '*' | IntStr;
10
+ export type SuiAddress = `${Hex}::${string}::${string}`;
11
+ export type Caip2NsBip122 = 'bip122';
12
+ export type Caip2NsEip155 = 'eip155';
13
+ export type Caip2NsCosmos = 'cosmos';
14
+ export type Caip2NsSolana = 'solana';
15
+ export type Caip2NsSui = 'sui';
16
+ export type Caip2NsStellar = 'stellar';
17
+ export type Caip2Ns = Caip2NsBip122 | Caip2NsEip155 | Caip2NsCosmos | Caip2NsSolana | Caip2NsSui | Caip2NsStellar;
18
+ export type Caip2Bip122 = `${Caip2NsBip122}:${string}`;
19
+ export type Caip2Eip155 = `${Caip2NsEip155}:${IntStr}`;
20
+ export type Caip2Cosmos = `${Caip2NsCosmos}:${string}`;
21
+ export type Caip2Solana = `${Caip2NsSolana}:${string}`;
22
+ export type Caip2Sui = `${Caip2NsSui}:${'mainnet' | 'testnet' | 'devnet'}`;
23
+ export type Caip2Stellar = `${Caip2NsStellar}:${string}`;
24
+ export type Caip2 = Caip2Bip122 | Caip2Eip155 | Caip2Cosmos | Caip2Solana | Caip2Sui | Caip2Stellar;
25
+ export type Caip19NsEip155 = `erc${bigint}:${Hex}`;
26
+ export type Caip19NsIcs20 = `ics20:${string}`;
27
+ export type Caip19NsSolana = `solana:${Base58}/token:${Base58}`;
28
+ export type Caip20 = `slip44:${bigint}`;
29
+ export type Caip19Asset = Caip19NsEip155 | Caip19NsIcs20 | Caip19NsSolana | Caip20;
30
+ export type Caip19 = `${Caip2}/${Caip19Asset}`;
31
+ export interface EvmTransaction<P extends Record<string, unknown> = Record<string, unknown>> {
32
+ chainId: IntStr;
33
+ target: Hex;
34
+ data: Hex;
35
+ nonce?: undefined | number;
36
+ value: IntStr;
37
+ gasLimit?: undefined | IntStr;
38
+ maxPriorityFeePerGas?: undefined | IntStr;
39
+ maxFeePerGas?: undefined | IntStr;
40
+ metadata?: {
41
+ description?: string;
42
+ contract?: Hex;
43
+ method?: string;
44
+ params?: P;
45
+ };
46
+ }
47
+ export interface SignInMessage {
48
+ params: SiweMessage;
49
+ message: string;
50
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,33 @@
1
+ import type { TypedDataDomain } from 'abitype';
2
+ import type { Hex } from 'viem';
3
+ import type { PromiseOrValue, Bytesish } from './core.js';
4
+ export interface TypedDataDocument<D extends TypedDataDomain = TypedDataDomain> {
5
+ domain: D;
6
+ types: Record<string, ReadonlyArray<{
7
+ name: string;
8
+ type: string;
9
+ }>>;
10
+ primaryType: string;
11
+ message: Record<string, unknown>;
12
+ }
13
+ export interface EvmSigner {
14
+ address: Hex;
15
+ getTransactionCount(chainId: 43114 | 43113): PromiseOrValue<number>;
16
+ signEip191Message(message: string): PromiseOrValue<Hex>;
17
+ signEip712TypedData(arg: TypedDataDocument): PromiseOrValue<Hex>;
18
+ }
19
+ export interface ErrorResponse {
20
+ type: string;
21
+ error: string;
22
+ }
23
+ export type ResponseWrapper<D> = [
24
+ error: ErrorResponse | undefined,
25
+ result?: D | undefined
26
+ ];
27
+ export interface EncryptSecretKeyArgs {
28
+ proxyPublicKey: Bytesish;
29
+ }
30
+ export interface ExportedFacilitator {
31
+ wrappedKey: string;
32
+ encryptionPublicKey: string;
33
+ }
@@ -0,0 +1 @@
1
+ export {};
package/dist/util.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import type { Bytesish } from './types/core.js';
2
+ /**
3
+ * Normalizes a bytes argument
4
+ * @param bytesIn
5
+ * @returns
6
+ */
7
+ export declare function normalizeBytesish(bytesIn: Bytesish): Uint8Array;
8
+ /**
9
+ * Normalizes a JSON value
10
+ * @param value
11
+ * @returns
12
+ */
13
+ export declare function normalizeJson(value: unknown): unknown;
package/dist/util.js ADDED
@@ -0,0 +1,55 @@
1
+ import { hexToBytes, toBytes } from 'viem';
2
+ /**
3
+ * Normalizes a bytes argument
4
+ * @param bytesIn
5
+ * @returns
6
+ */
7
+ export function normalizeBytesish(bytesIn) {
8
+ // prep bytes
9
+ let bytesOut;
10
+ // bigint
11
+ if (typeof bytesIn === 'bigint') {
12
+ bytesOut = toBytes(bytesIn);
13
+ }
14
+ // string argument
15
+ else if (typeof bytesIn === 'string') {
16
+ // "0x..." bytes
17
+ if (bytesIn.startsWith('0x')) {
18
+ bytesOut = hexToBytes(bytesIn);
19
+ }
20
+ // base64
21
+ else {
22
+ bytesOut = Uint8Array.from(atob(bytesIn), c => c.charCodeAt(0));
23
+ }
24
+ }
25
+ // bytes
26
+ else if (bytesIn instanceof Uint8Array) {
27
+ bytesOut = bytesIn;
28
+ }
29
+ // wasn't set
30
+ if (!bytesOut) {
31
+ throw new TypeError('Invalid bytes; must be a "0x..." bytes string, bigint, or Uint8Array');
32
+ }
33
+ return bytesOut;
34
+ }
35
+ ;
36
+ /**
37
+ * Normalizes a JSON value
38
+ * @param value
39
+ * @returns
40
+ */
41
+ export function normalizeJson(value) {
42
+ if (typeof value !== 'object') {
43
+ if (Array.isArray(value)) {
44
+ return value.map(normalizeJson);
45
+ }
46
+ else if (value && value.constructor === Object) {
47
+ const sorted = Object.fromEntries(Object.entries(value).sort((a, b) => a[0] < b[0] ? -1 : 1));
48
+ for (const key in sorted) {
49
+ sorted[key] = normalizeJson(sorted[key]);
50
+ }
51
+ return sorted;
52
+ }
53
+ }
54
+ return value;
55
+ }
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@silentswap/sdk",
3
+ "type": "module",
4
+ "version": "0.0.1",
5
+ "license": "MIT",
6
+ "main": "dist/index.js",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc"
12
+ },
13
+ "dependencies": {
14
+ "@cosmjs/amino": "^0.33.1",
15
+ "@cosmjs/crypto": "^0.33.1",
16
+ "@cosmjs/encoding": "^0.33.1",
17
+ "@solar-republic/wasm-secp256k1": "^0.6.1",
18
+ "bignumber.js": "^9.3.0",
19
+ "siwe": "^3.0.0",
20
+ "viem": "^2.31.4"
21
+ },
22
+ "devDependencies": {
23
+ "@eslint/js": "^9.30.0",
24
+ "@stylistic/eslint-plugin": "^4.4.1",
25
+ "@tsconfig/node24": "^24.0.1",
26
+ "@types/node": "^24.0.7",
27
+ "@types/web": "^0.0.243",
28
+ "@typescript-eslint/parser": "^8.35.0",
29
+ "abitype": "^1.0.8",
30
+ "eslint": "^9.30.0",
31
+ "eslint-import-resolver-typescript": "^4.4.4",
32
+ "eslint-plugin-import-x": "^4.16.1",
33
+ "typescript": "^5.8.3",
34
+ "typescript-eslint": "^8.35.0"
35
+ }
36
+ }