Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.DS_Store
node_modules
dist
coverage
.idea
yarn.lock

Expand Down
214 changes: 212 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
"build": "rm -rf dist && bunchee",
"build:umd": "bunchee --runtime browser --format umd --output dist/mixin-node-sdk.umd.js",
"test": "vitest run",
"test:coverage": "vitest run --coverage",
"test:integration": "MIXIN_INTEGRATION_TESTS=1 vitest run",
"test:watch": "vitest",
"lint": "eslint 'src/**' && prettier --check .",
"format": "prettier --write .",
Expand Down Expand Up @@ -82,6 +84,7 @@
"@types/ws": "^8.18.1",
"@typescript-eslint/eslint-plugin": "^8.69.0",
"@typescript-eslint/parser": "^8.69.0",
"@vitest/coverage-v8": "^4.1.11",
"buffer": "^6.0.3",
"bunchee": "^6.12.2",
"eslint": "^10.10.0",
Expand Down
9 changes: 5 additions & 4 deletions src/client/circle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,20 @@ export const CircleKeystoreClient = (axiosInstance: AxiosInstance) => ({
delete: (circleID: string): Promise<any> => axiosInstance.post<unknown, any>(`/circles/${circleID}/delete`),

/** Add the user to a circle */
addUser: (userID: string, circleID: string): Promise<CircleResponse[]> => axiosInstance.post<unknown, CircleResponse[]>(`/users/${userID}/circles`, { circleID, action: 'ADD' }),
addUser: (userID: string, circleID: string): Promise<CircleResponse[]> =>
axiosInstance.post<unknown, CircleResponse[]>(`/users/${userID}/circles`, { circle_id: circleID, action: 'ADD' }),

/** Remove the user from a circle */
removeUser: (userID: string, circleID: string): Promise<CircleResponse[]> =>
axiosInstance.post<unknown, CircleResponse[]>(`/users/${userID}/circles`, { circleID, action: 'REMOVE' }),
axiosInstance.post<unknown, CircleResponse[]>(`/users/${userID}/circles`, { circle_id: circleID, action: 'REMOVE' }),

/** Add the group from a certain circle */
addConversation: (conversationID: string, circleID: string): Promise<CircleResponse[]> =>
axiosInstance.post<unknown, CircleResponse[]>(`/conversations/${conversationID}/circles`, { circleID, action: 'ADD' }),
axiosInstance.post<unknown, CircleResponse[]>(`/conversations/${conversationID}/circles`, { circle_id: circleID, action: 'ADD' }),

/** Remove the group from a certain circle */
removeConversation: (conversation_id: string, circleID: string): Promise<CircleResponse[]> =>
axiosInstance.post<unknown, CircleResponse[]>(`/conversations/${conversation_id}/circles`, { circleID, action: 'REMOVE' }),
axiosInstance.post<unknown, CircleResponse[]>(`/conversations/${conversation_id}/circles`, { circle_id: circleID, action: 'REMOVE' }),
});

export const CircleClient = buildClient(CircleKeystoreClient);
Expand Down
6 changes: 3 additions & 3 deletions src/client/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { ResponseError } from './error';
import { signAccessToken } from './utils/auth';

export function http(keystore?: Keystore, config?: RequestConfig): AxiosInstance {
const timeout = config?.timeout || 3000;
const retries = config?.retry || 5;
const timeout = config?.timeout ?? 3000;
const retries = config?.retry ?? 5;

const ins = axios.create({
baseURL: 'https://api.mixin.one',
Expand All @@ -32,7 +32,7 @@ export function http(keystore?: Keystore, config?: RequestConfig): AxiosInstance
const requestID = uuid();
config.headers['X-Request-Id'] = requestID;
const jwtToken = signAccessToken(method, url, data, requestID, keystore);
config.headers.Authorization = `Bearer ${jwtToken}`;
if (jwtToken) config.headers.Authorization = `Bearer ${jwtToken}`;
}

return config;
Expand Down
6 changes: 4 additions & 2 deletions src/client/types/mixin_transaction.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
export interface MintData {
group: string;
batch: bigint;
amount: number;
/** Use a decimal string for exact amounts. Decoding always returns a string. */
amount: string | number;
}

export interface DepositData {
chain: string;
asset: string;
transaction: string;
index: bigint;
amount: number;
/** Use a decimal string for exact amounts. Decoding always returns a string. */
amount: string | number;
}

export interface WithdrawData {
Expand Down
3 changes: 2 additions & 1 deletion src/client/types/nfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface NFOMemo {
chain?: string /** chain uuid */;
class?: string /** contract address */;
collection?: string /** collection uuid */;
token?: number;
/** Exact token ID as a decimal integer string. */
token?: string;
extra: string;
}
2 changes: 1 addition & 1 deletion src/client/utils/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const getMixAddressBuffer = (ma: MixAddress) => {
if (members.length > 255) {
throw new Error(`invalid members length: ${members.length}`);
}
if (ma.threshold === 0 || ma.threshold > members.length) {
if (!Number.isInteger(ma.threshold) || ma.threshold < 1 || ma.threshold > members.length) {
throw new Error(`invalid threshold: ${ma.threshold}`);
}

Expand Down
Loading
Loading