@thesingularitynetwork/darkswap-sdk 0.1.0 → 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.
Files changed (53) hide show
  1. package/dist/src/config/chain.d.ts +9 -0
  2. package/dist/src/config/config.d.ts +4 -0
  3. package/dist/src/config/contractConfig.d.ts +12 -0
  4. package/dist/src/darkSwap.d.ts +9 -0
  5. package/dist/src/entities/error.d.ts +3 -0
  6. package/dist/src/entities/index.d.ts +3 -0
  7. package/dist/src/entities/token.d.ts +8 -0
  8. package/dist/src/entities/types.d.ts +6 -0
  9. package/dist/src/index.d.ts +4 -0
  10. package/dist/src/proof/baseProofService.d.ts +6 -0
  11. package/dist/src/proof/basic/depositProof.d.ts +13 -0
  12. package/dist/src/proof/basic/joinProof.d.ts +17 -0
  13. package/dist/src/proof/basic/tripleJoinProof.d.ts +21 -0
  14. package/dist/src/proof/basic/withdrawProof.d.ts +13 -0
  15. package/dist/src/proof/keyService.d.ts +2 -0
  16. package/dist/src/proof/noteService.d.ts +9 -0
  17. package/dist/src/proof/pro/orders/cancelOrderProof.d.ts +15 -0
  18. package/dist/src/proof/pro/orders/createOrderProof.d.ts +16 -0
  19. package/dist/src/proof/pro/orders/swapProof.d.ts +23 -0
  20. package/dist/src/proof/retail/cancelOrderProof.d.ts +11 -0
  21. package/dist/src/proof/retail/depositOrderProof.d.ts +14 -0
  22. package/dist/src/proof/retail/swapProof.d.ts +19 -0
  23. package/dist/src/services/BaseService.d.ts +19 -0
  24. package/dist/src/services/EventService.d.ts +3 -0
  25. package/dist/src/services/base/deposit.d.ts +29 -0
  26. package/dist/src/services/base/index.d.ts +4 -0
  27. package/dist/src/services/base/join.d.ts +29 -0
  28. package/dist/src/services/base/tripleJoin.d.ts +32 -0
  29. package/dist/src/services/base/withdraw.d.ts +29 -0
  30. package/dist/src/services/index.d.ts +5 -0
  31. package/dist/src/services/merkletree.d.ts +18 -0
  32. package/dist/src/services/noteService.d.ts +8 -0
  33. package/dist/src/services/pro/cancelOrder.d.ts +29 -0
  34. package/dist/src/services/pro/createOrder.d.ts +40 -0
  35. package/dist/src/services/pro/index.d.ts +1 -0
  36. package/dist/src/services/pro/proSwap.d.ts +36 -0
  37. package/dist/src/services/retail/cancelAndWithdrawOrder.d.ts +22 -0
  38. package/dist/src/services/retail/depositAndCreateOrder.d.ts +32 -0
  39. package/dist/src/services/retail/index.d.ts +2 -0
  40. package/dist/src/types.d.ts +53 -0
  41. package/dist/src/utils/constants.d.ts +2 -0
  42. package/dist/src/utils/encoders.d.ts +1 -0
  43. package/dist/src/utils/formatters.d.ts +3 -0
  44. package/dist/src/utils/mimc.d.ts +1 -0
  45. package/dist/src/utils/proofUtils.d.ts +4 -0
  46. package/dist/src/utils/util.d.ts +4 -0
  47. package/dist/test/proof/depositProof.test.d.ts +1 -0
  48. package/dist/test/proof/keyService.test.d.ts +1 -0
  49. package/dist/test/proof/retail/cancelOrderProof.test.d.ts +1 -0
  50. package/dist/test/proof/retail/createOrderProof.test.d.ts +1 -0
  51. package/dist/test/services/depositService.test.d.ts +1 -0
  52. package/dist/test/utils/helpers.d.ts +5 -0
  53. package/package.json +4 -1
@@ -0,0 +1,9 @@
1
+ export declare enum ChainId {
2
+ HARDHAT = 31337,
3
+ HARDHAT_ARBITRUM = 31338,
4
+ HARDHAT_BASE = 31339,
5
+ MAINNET = 1,
6
+ SEPOLIA = 11155111,
7
+ ARBITRUM_ONE = 42161,
8
+ BASE = 8453
9
+ }
@@ -0,0 +1,4 @@
1
+ export declare const legacyTokenConfig: {
2
+ [chainId: number]: string[];
3
+ };
4
+ export declare const FEE_RATIO = 300n;
@@ -0,0 +1,12 @@
1
+ export type ContractConfiguartion = {
2
+ priceOracle: string;
3
+ ethAddress: string;
4
+ nativeWrapper: string;
5
+ merkleTreeOperator: string;
6
+ darkSwapAssetManager: string;
7
+ darkSwapFeeAssetManager: string;
8
+ drakpoolSubgraphUrl: string;
9
+ };
10
+ export declare const contractConfig: {
11
+ [chainId: number]: ContractConfiguartion;
12
+ };
@@ -0,0 +1,9 @@
1
+ import { ethers } from 'ethers';
2
+ import { ContractConfiguartion } from './config/contractConfig';
3
+ export declare class DarkSwap {
4
+ signer: ethers.Signer;
5
+ provider: ethers.Provider;
6
+ chainId: number;
7
+ contracts: ContractConfiguartion;
8
+ constructor(signer: ethers.Signer, chainId: number, contracts?: ContractConfiguartion);
9
+ }
@@ -0,0 +1,3 @@
1
+ export declare class DarkSwapError extends Error {
2
+ constructor(message: string);
3
+ }
@@ -0,0 +1,3 @@
1
+ export * from './error';
2
+ export * from './token';
3
+ export * from './types';
@@ -0,0 +1,8 @@
1
+ export type SimpleToken = {
2
+ address: string;
3
+ decimals: number;
4
+ };
5
+ export type Token = SimpleToken & {
6
+ symbol: string;
7
+ name: string;
8
+ };
@@ -0,0 +1,6 @@
1
+ export declare enum NoteOnChainStatus {
2
+ ACTIVE = "ACTIVE",
3
+ SPENT = "SPENT",
4
+ LOCKED = "LOCKED",
5
+ UNKNOWN = "UNKNOWN"
6
+ }
@@ -0,0 +1,4 @@
1
+ export * from './services';
2
+ export * from './entities';
3
+ export * from './darkSwap';
4
+ export * from './utils/util';
@@ -0,0 +1,6 @@
1
+ import { Fr } from "@aztec/foundation/fields";
2
+ export declare function generateProof(circuit: any, inputs: any): Promise<{
3
+ proof: string;
4
+ verifyInputs: string[];
5
+ }>;
6
+ export declare function signMessage(message: string, fuzkPriKey: Fr): Promise<Buffer<ArrayBufferLike>>;
@@ -0,0 +1,13 @@
1
+ import { BaseProofParam, BaseProofResult, DarkSwapNote } from "../../types";
2
+ export type DepositProofParam = BaseProofParam & {
3
+ merkleRoot: string;
4
+ merkleIndex: number[];
5
+ merklePath: string[];
6
+ oldBalanceNote: DarkSwapNote;
7
+ newBalanceNote: DarkSwapNote;
8
+ };
9
+ export type DepositProofResult = BaseProofResult & {
10
+ oldBalanceNullifier: string;
11
+ newBalanceFooter: string;
12
+ };
13
+ export declare function generateDepositProof(param: DepositProofParam): Promise<DepositProofResult>;
@@ -0,0 +1,17 @@
1
+ import { BaseProofParam, BaseProofResult, DarkSwapNote } from "../../types";
2
+ export type JoinProofParam = BaseProofParam & {
3
+ merkleRoot: string;
4
+ inMerkleIndex1: number[];
5
+ inMerkleIndex2: number[];
6
+ inMerklePath1: string[];
7
+ inMerklePath2: string[];
8
+ inNote1: DarkSwapNote;
9
+ inNote2: DarkSwapNote;
10
+ outNote: DarkSwapNote;
11
+ };
12
+ export type JoinProofResult = BaseProofResult & {
13
+ inNullifier1: string;
14
+ inNullifier2: string;
15
+ outNoteFooter: string;
16
+ };
17
+ export declare function generateJoinProof(param: JoinProofParam): Promise<JoinProofResult>;
@@ -0,0 +1,21 @@
1
+ import { BaseProofParam, BaseProofResult, DarkSwapNote } from "../../types";
2
+ export type TripleJoinProofParam = BaseProofParam & {
3
+ merkleRoot: string;
4
+ inMerkleIndex1: number[];
5
+ inMerkleIndex2: number[];
6
+ inMerkleIndex3: number[];
7
+ inMerklePath1: string[];
8
+ inMerklePath2: string[];
9
+ inMerklePath3: string[];
10
+ inNote1: DarkSwapNote;
11
+ inNote2: DarkSwapNote;
12
+ inNote3: DarkSwapNote;
13
+ outNote: DarkSwapNote;
14
+ };
15
+ export type TripleJoinProofResult = BaseProofResult & {
16
+ inNullifier1: string;
17
+ inNullifier2: string;
18
+ inNullifier3: string;
19
+ outNoteFooter: string;
20
+ };
21
+ export declare function generateTripleJoinProof(param: TripleJoinProofParam): Promise<TripleJoinProofResult>;
@@ -0,0 +1,13 @@
1
+ import { BaseProofParam, BaseProofResult, DarkSwapNote } from "../../types";
2
+ export type WithdrawProofParam = BaseProofParam & {
3
+ merkleRoot: string;
4
+ merkleIndex: number[];
5
+ merklePath: string[];
6
+ oldBalance: DarkSwapNote;
7
+ newBalance: DarkSwapNote;
8
+ };
9
+ export type WithdrawProofResult = BaseProofResult & {
10
+ oldBalanceNullifier: string;
11
+ newBalanceFooter: string;
12
+ };
13
+ export declare function generateWithdrawProof(param: WithdrawProofParam): Promise<WithdrawProofResult>;
@@ -0,0 +1,2 @@
1
+ import { Fr } from "@aztec/foundation/fields";
2
+ export declare function generateKeyPair(signature: string): Promise<[[Fr, Fr], Fr]>;
@@ -0,0 +1,9 @@
1
+ import { Fr } from "@aztec/foundation/fields";
2
+ import { DarkSwapNote, DarkSwapNoteExt, DarkSwapOrderNote } from "../types.js";
3
+ export declare const DOMAIN_NOTE = 2n;
4
+ export declare const DOMAIN_ORDER_NOTE = 3n;
5
+ export declare const EMPTY_NOTE: DarkSwapNote;
6
+ export declare function createNote(address: string, asset: string, amount: bigint, fuzkPubKey: [Fr, Fr]): DarkSwapNoteExt;
7
+ export declare function getNoteFooter(rho: bigint, publicKey: [Fr, Fr]): bigint;
8
+ export declare function calcNullifier(rho: bigint, fuzkPubKey: [Fr, Fr]): bigint;
9
+ export declare function createOrderNoteExt(address: string, asset: string, amount: bigint, feeRatio: bigint, fuzkPubKey: [Fr, Fr]): DarkSwapOrderNote;
@@ -0,0 +1,15 @@
1
+ import { BaseProofParam, BaseProofResult, DarkSwapNote, DarkSwapOrderNote } from "../../../types";
2
+ export type ProCancelOrderProofParam = BaseProofParam & {
3
+ merkleRoot: string;
4
+ merkleIndex: number[];
5
+ merklePath: string[];
6
+ orderNote: DarkSwapOrderNote;
7
+ oldBalanceNote: DarkSwapNote;
8
+ newBalanceNote: DarkSwapNote;
9
+ };
10
+ export type ProCancelOrderProofResult = BaseProofResult & {
11
+ orderNullifier: string;
12
+ oldBalanceNullifier: string;
13
+ newBalanceNoteFooter: string;
14
+ };
15
+ export declare function generateProCancelOrderProof(param: ProCancelOrderProofParam): Promise<ProCancelOrderProofResult>;
@@ -0,0 +1,16 @@
1
+ import { BaseProofParam, BaseProofResult, DarkSwapNote, DarkSwapOrderNote } from "../../../types";
2
+ export type ProCreateOrderProofParam = BaseProofParam & {
3
+ merkleRoot: string;
4
+ merkleIndex: number[];
5
+ merklePath: string[];
6
+ oldBalanceNote: DarkSwapNote;
7
+ newBalanceNote: DarkSwapNote;
8
+ orderNote: DarkSwapOrderNote;
9
+ inNote: DarkSwapNote;
10
+ };
11
+ export type ProCreateOrderProofResult = BaseProofResult & {
12
+ oldBalanceNullifier: string;
13
+ newBalanceFooter: string;
14
+ orderNoteFooter: string;
15
+ };
16
+ export declare function generateProCreateOrderProof(param: ProCreateOrderProofParam): Promise<ProCreateOrderProofResult>;
@@ -0,0 +1,23 @@
1
+ import { BaseProofResult, DarkSwapMessage, DarkSwapNote, DarkSwapOrderNote } from "../../../types";
2
+ export type ProSwapProofParam = {
3
+ merkleRoot: string;
4
+ aliceMerkleIndex: number[];
5
+ aliceMerklePath: string[];
6
+ aliceAddress: string;
7
+ aliceOrderNote: DarkSwapOrderNote;
8
+ aliceInNote: DarkSwapNote;
9
+ aliceChangeNote: DarkSwapNote;
10
+ aliceSignedMessage: string;
11
+ bobMerkleIndex: number[];
12
+ bobMerklePath: string[];
13
+ bobAddress: string;
14
+ bobMessage: DarkSwapMessage;
15
+ };
16
+ export type ProSwapProofResult = BaseProofResult & {
17
+ aliceOutNullifier: string;
18
+ aliceInNoteFooter: string;
19
+ aliceChangeNoteFooter: string;
20
+ bobOutNullifier: string;
21
+ bobInNoteFooter: string;
22
+ };
23
+ export declare function generateProSwapProof(param: ProSwapProofParam): Promise<ProSwapProofResult>;
@@ -0,0 +1,11 @@
1
+ import { BaseProofParam, BaseProofResult, DarkSwapOrderNote } from "../../types";
2
+ export type RetailCancelOrderProofParam = BaseProofParam & {
3
+ merkleRoot: string;
4
+ merkleIndex: number[];
5
+ merklePath: string[];
6
+ orderNote: DarkSwapOrderNote;
7
+ };
8
+ export type RetailCancelOrderProofResult = BaseProofResult & {
9
+ nullifier: string;
10
+ };
11
+ export declare function generateRetailCancelOrderProof(param: RetailCancelOrderProofParam): Promise<RetailCancelOrderProofResult>;
@@ -0,0 +1,14 @@
1
+ import { BaseProofParam, BaseProofResult, DarkSwapMessage, DarkSwapNote, DarkSwapOrderNote } from "../../types";
2
+ import { Fr } from "@aztec/foundation/fields";
3
+ export type RetailCreateOrderProofParam = BaseProofParam & {
4
+ depositNote: DarkSwapOrderNote;
5
+ swapInNote: DarkSwapNote;
6
+ feeAmount: bigint;
7
+ };
8
+ export type RetailCreateOrderProofResult = BaseProofResult & {
9
+ depositNullifier: string;
10
+ depositFooter: string;
11
+ swapInNoteFooter: string;
12
+ };
13
+ export declare function generateRetailSwapMessage(address: string, orderNote: DarkSwapOrderNote, swapInNote: DarkSwapNote, pubKey: [Fr, Fr], privKey: Fr): Promise<DarkSwapMessage>;
14
+ export declare function generateRetailCreateOrderProof(param: RetailCreateOrderProofParam): Promise<RetailCreateOrderProofResult>;
@@ -0,0 +1,19 @@
1
+ import { BaseProofResult, DarkSwapMessage } from "../../types";
2
+ export type RetailSwapProofParam = {
3
+ merkleRoot: string;
4
+ aliceMerkleIndex: number[];
5
+ aliceMerklePath: string[];
6
+ aliceAddress: string;
7
+ aliceMessage: DarkSwapMessage;
8
+ bobMerkleIndex: number[];
9
+ bobMerklePath: string[];
10
+ bobAddress: string;
11
+ bobMessage: DarkSwapMessage;
12
+ };
13
+ export type RetailSwapProofResult = BaseProofResult & {
14
+ aliceOrderNullifier: string;
15
+ aliceInNoteFooter: string;
16
+ bobOrderNullifier: string;
17
+ bobInNoteFooter: string;
18
+ };
19
+ export declare function generateRetailSwapProof(param: RetailSwapProofParam): Promise<RetailSwapProofResult>;
@@ -0,0 +1,19 @@
1
+ import { DarkSwap } from '../darkSwap';
2
+ export declare class BaseContext {
3
+ private _address?;
4
+ private _signature;
5
+ private _merkleRoot?;
6
+ private _tx?;
7
+ constructor(signature: string);
8
+ set address(address: string | undefined);
9
+ get address(): string | undefined;
10
+ get signature(): string;
11
+ set merkleRoot(merkleRoot: string | undefined);
12
+ get merkleRoot(): string | undefined;
13
+ set tx(tx: string | undefined);
14
+ get tx(): string | undefined;
15
+ }
16
+ export declare abstract class BaseContractService {
17
+ protected _darkSwap: DarkSwap;
18
+ constructor(_darkSwap: DarkSwap);
19
+ }
@@ -0,0 +1,3 @@
1
+ import { ethers } from 'ethers';
2
+ import { DarkSwap } from '../darkSwap';
3
+ export declare function getOutEvent(tx: string, abi: any, eventTopic: string, darkSwap: DarkSwap): Promise<ethers.LogDescription | null>;
@@ -0,0 +1,29 @@
1
+ import { DarkSwap } from '../../darkSwap';
2
+ import { DepositProofResult } from '../../proof/basic/depositProof';
3
+ import { DarkSwapNote } from '../../types';
4
+ import { BaseContext, BaseContractService } from '../BaseService';
5
+ export declare class DepositContext extends BaseContext {
6
+ private _currentBalance?;
7
+ private _newBalance?;
8
+ private _proof?;
9
+ private _depositAmount?;
10
+ constructor(signature: string);
11
+ set currentBalance(currentBalance: DarkSwapNote | undefined);
12
+ get currentBalance(): DarkSwapNote | undefined;
13
+ set newBalance(newBalance: DarkSwapNote | undefined);
14
+ get newBalance(): DarkSwapNote | undefined;
15
+ set proof(proof: DepositProofResult | undefined);
16
+ get proof(): DepositProofResult | undefined;
17
+ set depositAmount(depositAmount: bigint | undefined);
18
+ get depositAmount(): bigint | undefined;
19
+ }
20
+ export declare class DepositService extends BaseContractService {
21
+ constructor(_darkSwap: DarkSwap);
22
+ prepare(currentBalance: DarkSwapNote, depositAsset: string, depositAmount: bigint, walletAddress: string, signature: string): Promise<{
23
+ context: DepositContext;
24
+ newBalanceNote: DarkSwapNote;
25
+ }>;
26
+ private generateProof;
27
+ execute(context: DepositContext): Promise<string>;
28
+ protected allowance(context: DepositContext): Promise<void>;
29
+ }
@@ -0,0 +1,4 @@
1
+ export * from './deposit';
2
+ export * from './withdraw';
3
+ export * from './join';
4
+ export * from './tripleJoin';
@@ -0,0 +1,29 @@
1
+ import { JoinProofResult } from '../../proof/basic/joinProof';
2
+ import { DarkSwapNote } from '../../types';
3
+ import { BaseContext, BaseContractService } from '../BaseService';
4
+ import { DarkSwap } from '../../darkSwap';
5
+ declare class JoinContext extends BaseContext {
6
+ private _inNote1?;
7
+ private _inNote2?;
8
+ private _outNote?;
9
+ private _proof?;
10
+ constructor(signature: string);
11
+ set inNote1(note: DarkSwapNote | undefined);
12
+ get inNote1(): DarkSwapNote | undefined;
13
+ set inNote2(note: DarkSwapNote | undefined);
14
+ get inNote2(): DarkSwapNote | undefined;
15
+ set outNote(note: DarkSwapNote | undefined);
16
+ get outNote(): DarkSwapNote | undefined;
17
+ set proof(proof: JoinProofResult | undefined);
18
+ get proof(): JoinProofResult | undefined;
19
+ }
20
+ export declare class JoinService extends BaseContractService {
21
+ constructor(_darkSwap: DarkSwap);
22
+ prepare(address: string, inNote1: DarkSwapNote, inNote2: DarkSwapNote, signature: string): Promise<{
23
+ context: JoinContext;
24
+ outNotes: DarkSwapNote[];
25
+ }>;
26
+ private generateProof;
27
+ execute(context: JoinContext): Promise<string>;
28
+ }
29
+ export {};
@@ -0,0 +1,32 @@
1
+ import { DarkSwap } from '../../darkSwap';
2
+ import { TripleJoinProofResult } from '../../proof/basic/tripleJoinProof';
3
+ import { DarkSwapNote } from '../../types';
4
+ import { BaseContext, BaseContractService } from '../BaseService';
5
+ declare class TripleJoinContext extends BaseContext {
6
+ private _inNote1?;
7
+ private _inNote2?;
8
+ private _inNote3?;
9
+ private _outNote?;
10
+ private _proof?;
11
+ constructor(signature: string);
12
+ set inNote1(note: DarkSwapNote | undefined);
13
+ get inNote1(): DarkSwapNote | undefined;
14
+ set inNote2(note: DarkSwapNote | undefined);
15
+ get inNote2(): DarkSwapNote | undefined;
16
+ set inNote3(note: DarkSwapNote | undefined);
17
+ get inNote3(): DarkSwapNote | undefined;
18
+ set outNote(note: DarkSwapNote | undefined);
19
+ get outNote(): DarkSwapNote | undefined;
20
+ set proof(proof: TripleJoinProofResult | undefined);
21
+ get proof(): TripleJoinProofResult | undefined;
22
+ }
23
+ export declare class TripleJoinService extends BaseContractService {
24
+ constructor(_darkSwap: DarkSwap);
25
+ prepare(address: string, inNote1: DarkSwapNote, inNote2: DarkSwapNote, inNote3: DarkSwapNote, signature: string): Promise<{
26
+ context: TripleJoinContext;
27
+ outNotes: DarkSwapNote[];
28
+ }>;
29
+ private generateProof;
30
+ execute(context: TripleJoinContext): Promise<string>;
31
+ }
32
+ export {};
@@ -0,0 +1,29 @@
1
+ import { DarkSwap } from '../../darkSwap';
2
+ import { WithdrawProofResult } from '../../proof/basic/withdrawProof';
3
+ import { DarkSwapNote } from '../../types';
4
+ import { BaseContext, BaseContractService } from '../BaseService';
5
+ declare class WithdrawContext extends BaseContext {
6
+ private _currentBalance?;
7
+ private _newBalance?;
8
+ private _withdrawAmount?;
9
+ private _proof?;
10
+ constructor(signature: string);
11
+ set currentBalance(note: DarkSwapNote | undefined);
12
+ get currentBalance(): DarkSwapNote | undefined;
13
+ set newBalance(note: DarkSwapNote | undefined);
14
+ get newBalance(): DarkSwapNote | undefined;
15
+ set withdrawAmount(amount: bigint | undefined);
16
+ get withdrawAmount(): bigint | undefined;
17
+ set proof(proof: WithdrawProofResult | undefined);
18
+ get proof(): WithdrawProofResult | undefined;
19
+ }
20
+ export declare class WithdrawService extends BaseContractService {
21
+ constructor(_darkSwap: DarkSwap);
22
+ prepare(address: string, currentBalance: DarkSwapNote, withdrawAmount: bigint, signature: string): Promise<{
23
+ context: WithdrawContext;
24
+ outNotes: DarkSwapNote[];
25
+ }>;
26
+ private generateProof;
27
+ execute(context: WithdrawContext): Promise<string>;
28
+ }
29
+ export {};
@@ -0,0 +1,5 @@
1
+ export * from './noteService';
2
+ export * from './base';
3
+ export * from './pro';
4
+ export * from './retail';
5
+ export * from './merkletree';
@@ -0,0 +1,18 @@
1
+ import { DarkSwap } from '../darkSwap';
2
+ export interface MerklePath {
3
+ noteCommitment: bigint;
4
+ path: string[];
5
+ index: number[];
6
+ root: string;
7
+ }
8
+ export declare const EMPTY_PATH: {
9
+ path: any[];
10
+ index: any[];
11
+ root: string;
12
+ };
13
+ export declare function getMerklePathAndRoot(note: bigint, darkSwap: DarkSwap): Promise<{
14
+ path: any;
15
+ index: any;
16
+ root: any;
17
+ }>;
18
+ export declare function multiGetMerklePathAndRoot(notes: bigint[], darkSwap: DarkSwap): Promise<MerklePath[]>;
@@ -0,0 +1,8 @@
1
+ import { NoteOnChainStatus } from '../entities';
2
+ import { DarkSwap } from '../darkSwap';
3
+ import { DarkSwapNote } from '../types';
4
+ import { Fr } from '@aztec/foundation/fields';
5
+ export declare function getNoteOnChainStatusByPublicKey(darkSwap: DarkSwap, note: DarkSwapNote, publicKey: [Fr, Fr]): Promise<NoteOnChainStatus>;
6
+ export declare function isNoteActive(darkSwap: DarkSwap, note: DarkSwapNote, publicKey: [Fr, Fr]): Promise<boolean>;
7
+ export declare function isNoteSpent(darkSwap: DarkSwap, note: DarkSwapNote, publicKey: [Fr, Fr]): Promise<boolean>;
8
+ export declare function isNoteValid(darkSwap: DarkSwap, note: DarkSwapNote, publicKey: [Fr, Fr]): Promise<boolean>;
@@ -0,0 +1,29 @@
1
+ import { DarkSwap } from '../../darkSwap';
2
+ import { ProCancelOrderProofResult } from '../../proof/pro/orders/cancelOrderProof';
3
+ import { DarkSwapNote, DarkSwapOrderNote } from '../../types';
4
+ import { BaseContext, BaseContractService } from '../BaseService';
5
+ declare class ProCancelOrderContext extends BaseContext {
6
+ private _orderNote?;
7
+ private _oldBalance?;
8
+ private _newBalance?;
9
+ private _proof?;
10
+ constructor(signature: string);
11
+ set orderNote(orderNote: DarkSwapOrderNote | undefined);
12
+ get orderNote(): DarkSwapOrderNote | undefined;
13
+ set oldBalance(oldBalance: DarkSwapNote | undefined);
14
+ get oldBalance(): DarkSwapNote | undefined;
15
+ set newBalance(newBalance: DarkSwapNote | undefined);
16
+ get newBalance(): DarkSwapNote | undefined;
17
+ set proof(proof: ProCancelOrderProofResult | undefined);
18
+ get proof(): ProCancelOrderProofResult | undefined;
19
+ }
20
+ export declare class ProCancelOrderService extends BaseContractService {
21
+ constructor(_darkSwap: DarkSwap);
22
+ prepare(address: string, orderNote: DarkSwapOrderNote, balanceNote: DarkSwapNote, signature: string): Promise<{
23
+ context: ProCancelOrderContext;
24
+ newBalance: DarkSwapNote;
25
+ }>;
26
+ private generateProof;
27
+ execute(context: ProCancelOrderContext): Promise<string>;
28
+ }
29
+ export {};
@@ -0,0 +1,40 @@
1
+ import { DarkSwap } from '../../darkSwap';
2
+ import { ProCreateOrderProofResult } from '../../proof/pro/orders/createOrderProof';
3
+ import { DarkSwapMessage, DarkSwapNote, DarkSwapOrderNote } from '../../types';
4
+ import { BaseContext, BaseContractService } from '../BaseService';
5
+ declare class ProCreateOrderContext extends BaseContext {
6
+ private _orderNote?;
7
+ private _oldBalance?;
8
+ private _newBalance?;
9
+ private _swapInNote?;
10
+ private _proof?;
11
+ private _feeAmount?;
12
+ private _swapMessage?;
13
+ constructor(signature: string);
14
+ set orderNote(orderNote: DarkSwapOrderNote | undefined);
15
+ get orderNote(): DarkSwapOrderNote | undefined;
16
+ set swapInNote(swapInNote: DarkSwapNote | undefined);
17
+ get swapInNote(): DarkSwapNote | undefined;
18
+ set oldBalance(oldBalance: DarkSwapNote | undefined);
19
+ get oldBalance(): DarkSwapNote | undefined;
20
+ set newBalance(newBalance: DarkSwapNote | undefined);
21
+ get newBalance(): DarkSwapNote | undefined;
22
+ set feeAmount(feeAmount: bigint | undefined);
23
+ get feeAmount(): bigint | undefined;
24
+ set proof(proof: ProCreateOrderProofResult | undefined);
25
+ get proof(): ProCreateOrderProofResult | undefined;
26
+ set swapMessage(swapMessage: DarkSwapMessage | undefined);
27
+ get swapMessage(): DarkSwapMessage | undefined;
28
+ }
29
+ export declare class ProCreateOrderService extends BaseContractService {
30
+ constructor(_darkSwap: DarkSwap);
31
+ prepare(address: string, depositAsset: string, depositAmount: bigint, swapInAsset: string, swapInAmount: bigint, balanceNote: DarkSwapNote, signature: string): Promise<{
32
+ context: ProCreateOrderContext;
33
+ orderNote: DarkSwapOrderNote;
34
+ swapInNote: DarkSwapNote;
35
+ newBalance: DarkSwapNote;
36
+ }>;
37
+ private generateProof;
38
+ execute(context: ProCreateOrderContext): Promise<string>;
39
+ }
40
+ export {};
@@ -0,0 +1 @@
1
+ export * from './createOrder';
@@ -0,0 +1,36 @@
1
+ import { DarkSwap } from '../../darkSwap';
2
+ import { ProSwapProofResult } from '../../proof/pro/orders/swapProof';
3
+ import { DarkSwapMessage, DarkSwapNote, DarkSwapOrderNote } from '../../types';
4
+ import { BaseContext, BaseContractService } from '../BaseService';
5
+ declare class ProSwapContext extends BaseContext {
6
+ private _orderNote?;
7
+ private _changeNote?;
8
+ private _swapInNote?;
9
+ private _proof?;
10
+ private _bobAddress?;
11
+ private _bobSwapMessage?;
12
+ constructor(signature: string);
13
+ set orderNote(orderNote: DarkSwapOrderNote | undefined);
14
+ get orderNote(): DarkSwapOrderNote | undefined;
15
+ set changeNote(changeNote: DarkSwapNote | undefined);
16
+ get changeNote(): DarkSwapNote | undefined;
17
+ set swapInNote(swapInNote: DarkSwapNote | undefined);
18
+ get swapInNote(): DarkSwapNote | undefined;
19
+ set proof(proof: ProSwapProofResult | undefined);
20
+ get proof(): ProSwapProofResult | undefined;
21
+ set bobSwapMessage(bobSwapMessage: DarkSwapMessage | undefined);
22
+ get bobSwapMessage(): DarkSwapMessage | undefined;
23
+ set bobAddress(bobAddress: string | undefined);
24
+ get bobAddress(): string | undefined;
25
+ }
26
+ export declare class ProSwapService extends BaseContractService {
27
+ constructor(_darkSwap: DarkSwap);
28
+ prepare(address: string, orderNote: DarkSwapOrderNote, swapOutAmount: bigint, swapInAmount: bigint, bobAddress: string, bobSwapMessage: DarkSwapMessage, signature: string): Promise<{
29
+ context: ProSwapContext;
30
+ swapInNote: DarkSwapNote;
31
+ changeNote: DarkSwapNote;
32
+ }>;
33
+ private generateProof;
34
+ execute(context: ProSwapContext): Promise<string>;
35
+ }
36
+ export {};
@@ -0,0 +1,22 @@
1
+ import { DarkSwap } from '../../darkSwap';
2
+ import { RetailCancelOrderProofResult } from '../../proof/retail/cancelOrderProof';
3
+ import { DarkSwapOrderNote } from '../../types';
4
+ import { BaseContext, BaseContractService } from '../BaseService';
5
+ declare class RetailCancelOrderContext extends BaseContext {
6
+ private _orderNote?;
7
+ private _proof?;
8
+ constructor(signature: string);
9
+ set orderNote(orderNote: DarkSwapOrderNote | undefined);
10
+ get orderNote(): DarkSwapOrderNote | undefined;
11
+ set proof(proof: RetailCancelOrderProofResult | undefined);
12
+ get proof(): RetailCancelOrderProofResult | undefined;
13
+ }
14
+ export declare class RetailCancelOrderService extends BaseContractService {
15
+ constructor(_darkSwap: DarkSwap);
16
+ prepare(address: string, orderNote: DarkSwapOrderNote, signature: string): Promise<{
17
+ context: RetailCancelOrderContext;
18
+ }>;
19
+ private generateProof;
20
+ execute(context: RetailCancelOrderContext): Promise<string>;
21
+ }
22
+ export {};
@@ -0,0 +1,32 @@
1
+ import { DarkSwap } from '../../darkSwap';
2
+ import { RetailCreateOrderProofResult } from '../../proof/retail/depositOrderProof';
3
+ import { DarkSwapMessage, DarkSwapNote, DarkSwapOrderNote } from '../../types';
4
+ import { BaseContext, BaseContractService } from '../BaseService';
5
+ declare class RetailCreateOrderContext extends BaseContext {
6
+ private _orderNote?;
7
+ private _swapInNote?;
8
+ private _proof?;
9
+ private _feeAmount?;
10
+ private _swapMessage?;
11
+ constructor(signature: string);
12
+ set orderNote(orderNote: DarkSwapOrderNote | undefined);
13
+ get orderNote(): DarkSwapOrderNote | undefined;
14
+ set swapInNote(swapInNote: DarkSwapNote | undefined);
15
+ get swapInNote(): DarkSwapNote | undefined;
16
+ set feeAmount(feeAmount: bigint | undefined);
17
+ get feeAmount(): bigint | undefined;
18
+ set proof(proof: RetailCreateOrderProofResult | undefined);
19
+ get proof(): RetailCreateOrderProofResult | undefined;
20
+ set swapMessage(swapMessage: DarkSwapMessage | undefined);
21
+ get swapMessage(): DarkSwapMessage | undefined;
22
+ }
23
+ export declare class RetailCreateOrderService extends BaseContractService {
24
+ constructor(_darkSwap: DarkSwap);
25
+ prepare(address: string, depositAsset: string, depositAmount: bigint, swapInAsset: string, swapInAmount: bigint, signature: string): Promise<{
26
+ context: RetailCreateOrderContext;
27
+ swapMessage: DarkSwapMessage;
28
+ }>;
29
+ private generateProof;
30
+ execute(context: RetailCreateOrderContext): Promise<string>;
31
+ }
32
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from './cancelAndWithdrawOrder';
2
+ export * from './depositAndCreateOrder';
@@ -0,0 +1,53 @@
1
+ import { Fr } from "@aztec/foundation/fields";
2
+ export type Hex = `0x${string}`;
3
+ export declare enum PROOF_DOMAIN {
4
+ DEPOSIT = 10001,
5
+ WITHDRAW = 10002,
6
+ RETAIL_CREATE_ORDER = 10003,
7
+ PRO_CREATE_ORDER = 10004,
8
+ PRO_SWAP = 10005,
9
+ PRO_CANCEL_ORDER = 10006,
10
+ RETAIL_CANCEL_ORDER = 10007,
11
+ JOIN = 10008,
12
+ TRIPLE_JOIN = 10009,
13
+ RETAIL_SWAP = 10010
14
+ }
15
+ export declare const EMPTY_NULLIFIER = 0n;
16
+ export declare const EMPTY_FOOTER = 0n;
17
+ export declare const FEE_RATIO_PRECISION = 1000000n;
18
+ export declare class DarkSwapProofError extends Error {
19
+ constructor(message: string);
20
+ }
21
+ export type DarkSwapNote = CreateNoteParam & {
22
+ note: bigint;
23
+ };
24
+ export type DarkSwapOrderNote = DarkSwapNote & {
25
+ feeRatio: bigint;
26
+ };
27
+ export type CreateNoteParam = {
28
+ rho: bigint;
29
+ amount: bigint;
30
+ asset: string;
31
+ };
32
+ export type DarkSwapNoteExt = DarkSwapNote & {
33
+ footer: bigint;
34
+ };
35
+ export type BaseProofParam = {
36
+ address: string;
37
+ signedMessage: string;
38
+ };
39
+ export type BaseProofResult = {
40
+ proof: string;
41
+ verifyInputs: string[];
42
+ };
43
+ export type BaseProofInput = {
44
+ address: string;
45
+ pub_key: [string, string];
46
+ signature: any;
47
+ };
48
+ export type DarkSwapMessage = {
49
+ orderNote: DarkSwapOrderNote;
50
+ inNote: DarkSwapNote;
51
+ publicKey: [Fr, Fr];
52
+ signature: any;
53
+ };
@@ -0,0 +1,2 @@
1
+ export declare const P: bigint;
2
+ export declare const MAX_ALLOWANCE: bigint;
@@ -0,0 +1 @@
1
+ export declare function encodeAddress(address: string): bigint;
@@ -0,0 +1,3 @@
1
+ export declare function bn_to_hex(n: bigint): string;
2
+ export declare function bn_to_0xhex(n: bigint): string;
3
+ export declare function bn_to_0xAddress(n: bigint): string;
@@ -0,0 +1 @@
1
+ export declare function mimc_bn254(array: bigint[]): bigint;
@@ -0,0 +1,4 @@
1
+ export declare function mergeUnit8Array(arr1: Uint8Array, arr2: Uint8Array): number[];
2
+ export declare function signatureToHexString(sig: [Uint8Array, Uint8Array]): string;
3
+ export declare function hexStringToSignature(hex: string): Uint8Array;
4
+ export declare function uint8ArrayToNumberArray(uint8Array: Uint8Array): number[];
@@ -0,0 +1,4 @@
1
+ export declare function isNativeAsset(asset: string): boolean;
2
+ export declare function isAddressEquals(address1: string, address2: string): boolean;
3
+ export declare function hexlify32(value: bigint | number): string;
4
+ export declare function isHexEquals(hex1: string, hex2: string): boolean;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { ethers } from "ethers";
2
+ import { DarkSwap } from "../../src";
3
+ export declare function getAliceWallet(): ethers.Wallet;
4
+ export declare function getAliceSignature(): Promise<string>;
5
+ export declare function getDarkSwapForAlice(): DarkSwap;
package/package.json CHANGED
@@ -1,12 +1,14 @@
1
1
  {
2
2
  "name": "@thesingularitynetwork/darkswap-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
7
  "description": "DarkSwap SDK for browser and Node.js",
8
8
  "type": "module",
9
9
  "main": "dist/index.js",
10
+ "types": "dist/index.d.ts",
11
+ "module": "dist/index.esm.js",
10
12
  "files": [
11
13
  "dist",
12
14
  "src"
@@ -37,6 +39,7 @@
37
39
  "eslint": "^9.27.0",
38
40
  "prettier": "^3.5.3",
39
41
  "rollup": "^4.41.1",
42
+ "rollup-plugin-dts": "^6.2.1",
40
43
  "rollup-plugin-typescript2": "^0.36.0",
41
44
  "ts-node": "^10.9.2",
42
45
  "typescript": "^5.8.3",