@zebec-network/exchange-card-sdk 1.10.1 → 1.11.0-dev.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/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/services/cantonService.d.ts +116 -0
- package/dist/services/cantonService.js +97 -103
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -1
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { type AuthTokenProvider, LedgerController, TokenStandardController, ValidatorController, type WalletSDK } from "@canton-network/wallet-sdk";
|
|
2
|
+
export declare const CANTON_NATIVE_INSTRUMENT_ID = "Amulet";
|
|
3
|
+
export declare const DEVNET_CANTON_NATIVE_INSTRUMENT_ADMIN = "DSO::1220be58c29e65de40bf273be1dc2b266d43a9a002ea5b18955aeef7aac881bb471a";
|
|
4
|
+
/**
|
|
5
|
+
* Wallet adapter interface — the frontend implements this to bridge the
|
|
6
|
+
* dApp wallet (e.g. Canton dApp SDK, browser extension) with CantonService.
|
|
7
|
+
*
|
|
8
|
+
* The service calls `executeTransaction` with the prepared command and
|
|
9
|
+
* disclosed contracts produced by the wallet-sdk; the adapter is responsible
|
|
10
|
+
* for signing and submitting them through whichever wallet integration the
|
|
11
|
+
* frontend uses.
|
|
12
|
+
*/
|
|
13
|
+
export interface CantonWalletAdapter {
|
|
14
|
+
/** The Daml party ID of the connected user. */
|
|
15
|
+
readonly partyId: string;
|
|
16
|
+
/**
|
|
17
|
+
* Sign and submit a transaction to the Canton ledger.
|
|
18
|
+
*
|
|
19
|
+
* @param command - The exercise command prepared by the wallet-sdk.
|
|
20
|
+
* @param disclosedContracts - Contracts that must be disclosed alongside
|
|
21
|
+
* the command for the transaction to succeed.
|
|
22
|
+
* @returns The submitted transaction / command ID.
|
|
23
|
+
*/
|
|
24
|
+
executeTransaction(command: {
|
|
25
|
+
ExerciseCommand: {
|
|
26
|
+
templateId: string;
|
|
27
|
+
contractId: string;
|
|
28
|
+
choice: string;
|
|
29
|
+
choiceArgument: unknown;
|
|
30
|
+
} | {
|
|
31
|
+
templateId: string;
|
|
32
|
+
contractId: string;
|
|
33
|
+
choice: string;
|
|
34
|
+
choiceArgument: unknown;
|
|
35
|
+
};
|
|
36
|
+
}, disclosedContracts: ({
|
|
37
|
+
templateId?: string;
|
|
38
|
+
contractId: string;
|
|
39
|
+
createdEventBlob: string;
|
|
40
|
+
synchronizerId: string;
|
|
41
|
+
} | {
|
|
42
|
+
templateId?: string;
|
|
43
|
+
contractId: string;
|
|
44
|
+
createdEventBlob: string;
|
|
45
|
+
synchronizerId: string;
|
|
46
|
+
})[]): Promise<string>;
|
|
47
|
+
}
|
|
48
|
+
export interface CantonConfig {
|
|
49
|
+
ledgerApiUrl: string;
|
|
50
|
+
validatorAppApiUrl: string;
|
|
51
|
+
/**
|
|
52
|
+
* Transfer-factory registry URL.
|
|
53
|
+
* Defaults to `localNetStaticConfig.LOCALNET_REGISTRY_API_URL` when omitted.
|
|
54
|
+
*/
|
|
55
|
+
registryApiUrl?: string | URL;
|
|
56
|
+
}
|
|
57
|
+
/** Parameters for transferring native Canton coin (Amulet). */
|
|
58
|
+
export interface NativeTransferParams {
|
|
59
|
+
amount: number | string;
|
|
60
|
+
/**
|
|
61
|
+
* The instrument admin party for the Amulet instrument on the target network
|
|
62
|
+
* (typically the DSO party).
|
|
63
|
+
*/
|
|
64
|
+
instrumentAdmin?: string;
|
|
65
|
+
memo?: string;
|
|
66
|
+
}
|
|
67
|
+
/** Parameters for transferring a CIP-0056 standard token. */
|
|
68
|
+
export interface TokenTransferParams {
|
|
69
|
+
amount: number | string;
|
|
70
|
+
/** The instrument / token identifier as registered in the token registry. */
|
|
71
|
+
instrumentId: string;
|
|
72
|
+
/** The admin party that governs this instrument. */
|
|
73
|
+
instrumentAdmin: string;
|
|
74
|
+
/**
|
|
75
|
+
* Override the registry URL for this specific token.
|
|
76
|
+
* Falls back to `CantonConfig.registryApiUrl` when omitted.
|
|
77
|
+
*/
|
|
78
|
+
registryApiUrl?: string | URL;
|
|
79
|
+
memo?: string;
|
|
80
|
+
}
|
|
81
|
+
export declare function createLedgerFactory(ledgerApiUrl: string): (userId: string, authTokenProvider: AuthTokenProvider, isAdmin: boolean) => LedgerController;
|
|
82
|
+
export declare function createValidatorFactory(validatorAppApiUrl: string): (userId: string, authTokenProvider: AuthTokenProvider) => ValidatorController;
|
|
83
|
+
export declare function createTokenStandardFactory(ledgerApiUrl: string, validatorAppApiUrl: string): (userId: string, authTokenProvider: AuthTokenProvider, isAdmin: boolean) => TokenStandardController;
|
|
84
|
+
export declare class CantonService {
|
|
85
|
+
readonly wallet: CantonWalletAdapter;
|
|
86
|
+
readonly cantonConfig: CantonConfig;
|
|
87
|
+
readonly cantonWalletSdk: WalletSDK;
|
|
88
|
+
private readonly apiService;
|
|
89
|
+
private readonly registryApiUrl;
|
|
90
|
+
constructor(wallet: CantonWalletAdapter, cantonConfig: CantonConfig, sdkOptions?: {
|
|
91
|
+
sandbox?: boolean;
|
|
92
|
+
});
|
|
93
|
+
connect(): Promise<void>;
|
|
94
|
+
fetchVault(symbol?: string): Promise<{
|
|
95
|
+
address: string;
|
|
96
|
+
tag?: string;
|
|
97
|
+
}>;
|
|
98
|
+
private getTokenStandard;
|
|
99
|
+
/**
|
|
100
|
+
* Transfer native Canton coin (Amulet) to the Zebec vault.
|
|
101
|
+
*
|
|
102
|
+
* 1. Resolves the vault address for the "CANTON" symbol.
|
|
103
|
+
* 2. Builds the transfer command via the wallet-sdk token-standard.
|
|
104
|
+
* 3. Delegates signing and submission to the wallet adapter.
|
|
105
|
+
*/
|
|
106
|
+
transferNative(params: NativeTransferParams): Promise<string>;
|
|
107
|
+
/**
|
|
108
|
+
* Transfer a CIP-0056 standard token to the Zebec vault.
|
|
109
|
+
*
|
|
110
|
+
* 1. Resolves the vault address for the given instrument symbol.
|
|
111
|
+
* 2. Configures the token-standard with the appropriate registry URL.
|
|
112
|
+
* 3. Builds the transfer command via the wallet-sdk token-standard.
|
|
113
|
+
* 4. Delegates signing and submission to the wallet adapter.
|
|
114
|
+
*/
|
|
115
|
+
transferToken(params: TokenTransferParams): Promise<string>;
|
|
116
|
+
}
|
|
@@ -1,103 +1,97 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
// [],
|
|
99
|
-
// memo,
|
|
100
|
-
// );
|
|
101
|
-
// return this.wallet.executeTransaction(transferCommand, disclosedContracts);
|
|
102
|
-
// }
|
|
103
|
-
// }
|
|
1
|
+
import { LedgerController, localNetStaticConfig, TokenStandardController, ValidatorController, WalletSDKImpl, } from "@canton-network/wallet-sdk";
|
|
2
|
+
import { ZebecCardAPIService } from "../helpers/apiHelpers";
|
|
3
|
+
export const CANTON_NATIVE_INSTRUMENT_ID = "Amulet";
|
|
4
|
+
export const DEVNET_CANTON_NATIVE_INSTRUMENT_ADMIN = "DSO::1220be58c29e65de40bf273be1dc2b266d43a9a002ea5b18955aeef7aac881bb471a";
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
// SDK factory helpers
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
export function createLedgerFactory(ledgerApiUrl) {
|
|
9
|
+
return (userId, authTokenProvider, isAdmin) => {
|
|
10
|
+
return new LedgerController(userId, new URL(ledgerApiUrl), undefined, isAdmin, authTokenProvider);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export function createValidatorFactory(validatorAppApiUrl) {
|
|
14
|
+
return (userId, authTokenProvider) => {
|
|
15
|
+
return new ValidatorController(userId, new URL(validatorAppApiUrl), authTokenProvider);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export function createTokenStandardFactory(ledgerApiUrl, validatorAppApiUrl) {
|
|
19
|
+
return (userId, authTokenProvider, isAdmin) => {
|
|
20
|
+
return new TokenStandardController(userId, new URL(ledgerApiUrl), new URL(validatorAppApiUrl), undefined, authTokenProvider, isAdmin);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// CantonService
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
export class CantonService {
|
|
27
|
+
wallet;
|
|
28
|
+
cantonConfig;
|
|
29
|
+
cantonWalletSdk;
|
|
30
|
+
apiService;
|
|
31
|
+
registryApiUrl;
|
|
32
|
+
constructor(wallet, cantonConfig, sdkOptions) {
|
|
33
|
+
this.wallet = wallet;
|
|
34
|
+
this.cantonConfig = cantonConfig;
|
|
35
|
+
this.apiService = new ZebecCardAPIService(sdkOptions?.sandbox ?? false);
|
|
36
|
+
this.registryApiUrl = cantonConfig.registryApiUrl
|
|
37
|
+
? new URL(cantonConfig.registryApiUrl.toString())
|
|
38
|
+
: localNetStaticConfig.LOCALNET_REGISTRY_API_URL;
|
|
39
|
+
this.cantonWalletSdk = new WalletSDKImpl().configure({
|
|
40
|
+
logger: console,
|
|
41
|
+
ledgerFactory: createLedgerFactory(cantonConfig.ledgerApiUrl),
|
|
42
|
+
validatorFactory: createValidatorFactory(cantonConfig.validatorAppApiUrl),
|
|
43
|
+
tokenStandardFactory: createTokenStandardFactory(cantonConfig.ledgerApiUrl, cantonConfig.validatorAppApiUrl),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
async connect() {
|
|
47
|
+
await this.cantonWalletSdk.connect();
|
|
48
|
+
}
|
|
49
|
+
async fetchVault(symbol = "CANTON") {
|
|
50
|
+
return this.apiService.fetchVault(symbol);
|
|
51
|
+
}
|
|
52
|
+
getTokenStandard() {
|
|
53
|
+
const ts = this.cantonWalletSdk.tokenStandard;
|
|
54
|
+
if (!ts) {
|
|
55
|
+
throw new Error("TokenStandardController is not initialized. Call connect() before transferring.");
|
|
56
|
+
}
|
|
57
|
+
return ts;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Transfer native Canton coin (Amulet) to the Zebec vault.
|
|
61
|
+
*
|
|
62
|
+
* 1. Resolves the vault address for the "CANTON" symbol.
|
|
63
|
+
* 2. Builds the transfer command via the wallet-sdk token-standard.
|
|
64
|
+
* 3. Delegates signing and submission to the wallet adapter.
|
|
65
|
+
*/
|
|
66
|
+
async transferNative(params) {
|
|
67
|
+
const vault = await this.fetchVault("CANTON");
|
|
68
|
+
const tokenStandard = this.getTokenStandard();
|
|
69
|
+
tokenStandard.setTransferFactoryRegistryUrl(this.registryApiUrl);
|
|
70
|
+
const [command, disclosedContracts] = await tokenStandard.createTransfer(this.wallet.partyId, vault.address, params.amount.toString(), {
|
|
71
|
+
instrumentId: CANTON_NATIVE_INSTRUMENT_ID,
|
|
72
|
+
instrumentAdmin: params.instrumentAdmin || DEVNET_CANTON_NATIVE_INSTRUMENT_ADMIN,
|
|
73
|
+
}, [], vault.tag ?? params.memo);
|
|
74
|
+
return this.wallet.executeTransaction(command, disclosedContracts);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Transfer a CIP-0056 standard token to the Zebec vault.
|
|
78
|
+
*
|
|
79
|
+
* 1. Resolves the vault address for the given instrument symbol.
|
|
80
|
+
* 2. Configures the token-standard with the appropriate registry URL.
|
|
81
|
+
* 3. Builds the transfer command via the wallet-sdk token-standard.
|
|
82
|
+
* 4. Delegates signing and submission to the wallet adapter.
|
|
83
|
+
*/
|
|
84
|
+
async transferToken(params) {
|
|
85
|
+
const vault = await this.fetchVault(params.instrumentId);
|
|
86
|
+
const tokenStandard = this.getTokenStandard();
|
|
87
|
+
const registryUrl = params.registryApiUrl
|
|
88
|
+
? new URL(params.registryApiUrl.toString())
|
|
89
|
+
: this.registryApiUrl;
|
|
90
|
+
tokenStandard.setTransferFactoryRegistryUrl(registryUrl);
|
|
91
|
+
const [command, disclosedContracts] = await tokenStandard.createTransfer(this.wallet.partyId, vault.address, params.amount.toString(), {
|
|
92
|
+
instrumentId: params.instrumentId,
|
|
93
|
+
instrumentAdmin: params.instrumentAdmin,
|
|
94
|
+
}, [], vault.tag ?? params.memo);
|
|
95
|
+
return this.wallet.executeTransaction(command, disclosedContracts);
|
|
96
|
+
}
|
|
97
|
+
}
|
package/dist/services/index.d.ts
CHANGED
package/dist/services/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from "./aleoService";
|
|
2
2
|
export * from "./algorandService";
|
|
3
3
|
export * from "./bobaService";
|
|
4
|
-
|
|
4
|
+
export * from "./cantonService";
|
|
5
5
|
export * from "./nearService";
|
|
6
6
|
export * from "./octaService";
|
|
7
7
|
export * from "./quaiService";
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Zebec Network | Ashish Sapkota",
|
|
3
3
|
"dependencies": {
|
|
4
|
+
"@canton-network/wallet-sdk": "^0.21.1",
|
|
4
5
|
"@near-js/crypto": "^2.5.1",
|
|
5
6
|
"@near-js/providers": "^2.5.1",
|
|
6
7
|
"@near-js/transactions": "^2.5.1",
|
|
@@ -63,5 +64,5 @@
|
|
|
63
64
|
},
|
|
64
65
|
"type": "module",
|
|
65
66
|
"types": "dist/index.d.ts",
|
|
66
|
-
"version": "1.
|
|
67
|
+
"version": "1.11.0-dev.1"
|
|
67
68
|
}
|