@canton-network/dapp-sdk 0.4.0 → 0.6.0

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.
@@ -1,13 +1,5 @@
1
- import * as dappAPI from '@canton-network/core-wallet-dapp-rpc-client';
2
1
  export * from '@canton-network/core-splice-provider';
3
- export declare enum ErrorCode {
4
- UserCancelled = 0,
5
- Other = 1
6
- }
7
- export type ConnectError = {
8
- status: 'error';
9
- error: ErrorCode;
10
- details: string;
11
- };
2
+ import * as dappAPI from '@canton-network/core-wallet-dapp-rpc-client';
3
+ export declare function open(): Promise<void>;
12
4
  export declare function connect(): Promise<dappAPI.ConnectResult>;
13
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connect/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,OAAO,MAAM,6CAA6C,CAAA;AAOtE,cAAc,sCAAsC,CAAA;AAqCpD,oBAAY,SAAS;IACjB,aAAa,IAAA;IACb,KAAK,IAAA;CACR;AAED,MAAM,MAAM,YAAY,GAAG;IACvB,MAAM,EAAE,OAAO,CAAA;IACf,KAAK,EAAE,SAAS,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,wBAAsB,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CA+B9D"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connect/index.ts"],"names":[],"mappings":"AASA,cAAc,sCAAsC,CAAA;AACpD,OAAO,KAAK,OAAO,MAAM,6CAA6C,CAAA;AAatE,wBAAsB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAY1C;AAED,wBAAsB,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CA8B9D"}
@@ -1,42 +1,29 @@
1
1
  // Copyright (c) 2025 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { discover, popupHref } from '@canton-network/core-wallet-ui-components';
4
- import { injectSpliceProvider, ProviderType, } from '@canton-network/core-splice-provider';
3
+ import { injectSpliceProvider } from '@canton-network/core-splice-provider';
4
+ import { discover } from '@canton-network/core-wallet-ui-components';
5
5
  import * as storage from '../storage';
6
- import { WalletEvent, } from '@canton-network/core-types';
6
+ import { openKernelUserUI, Provider } from '../provider';
7
7
  export * from '@canton-network/core-splice-provider';
8
- const injectProvider = ({ walletType, url }) => {
9
- if (walletType === 'remote') {
10
- return injectSpliceProvider(ProviderType.HTTP, new URL(url), storage.getKernelSession()?.sessionToken);
11
- }
12
- else {
13
- return injectSpliceProvider(ProviderType.WINDOW);
14
- }
8
+ import { ErrorCode } from '../index';
9
+ const injectProvider = (discovery) => {
10
+ return injectSpliceProvider(new Provider(discovery, storage.getKernelSession()?.sessionToken));
15
11
  };
16
12
  // On page load, restore and re-register the listener if needed
17
13
  const discovery = storage.getKernelDiscovery();
18
14
  if (discovery)
19
15
  injectProvider(discovery);
20
- const openKernelUserUI = (walletType, userUrl) => {
21
- switch (walletType) {
22
- case 'remote':
23
- popupHref(new URL(userUrl));
24
- break;
25
- case 'extension': {
26
- const msg = {
27
- type: WalletEvent.SPLICE_WALLET_EXT_OPEN,
28
- url: userUrl,
29
- };
30
- window.postMessage(msg, '*');
31
- break;
32
- }
16
+ export async function open() {
17
+ const discovery = storage.getKernelDiscovery();
18
+ if (!discovery) {
19
+ throw new Error('No previous discovery found');
33
20
  }
34
- };
35
- export var ErrorCode;
36
- (function (ErrorCode) {
37
- ErrorCode[ErrorCode["UserCancelled"] = 0] = "UserCancelled";
38
- ErrorCode[ErrorCode["Other"] = 1] = "Other";
39
- })(ErrorCode || (ErrorCode = {}));
21
+ const session = storage.getKernelSession();
22
+ if (!session) {
23
+ throw new Error('No previous session found');
24
+ }
25
+ openKernelUserUI(discovery.walletType, session.kernel.userUrl ?? '');
26
+ }
40
27
  export async function connect() {
41
28
  return discover()
42
29
  .then(async (result) => {
@@ -44,17 +31,18 @@ export async function connect() {
44
31
  storage.setKernelDiscovery(result);
45
32
  storage.removeKernelSession();
46
33
  const provider = injectProvider(result);
47
- // Listen for connected event from the provider
48
- // This will be triggered when the user connects to the wallet kernel
49
- provider.on('onConnected', (event) => {
50
- console.log('SDK: Store connection', event);
51
- storage.setKernelSession(event);
52
- });
53
34
  const response = await provider.request({
54
35
  method: 'connect',
55
36
  });
56
- if (!response.isConnected)
57
- openKernelUserUI(result.walletType, response.userUrl);
37
+ if (!response.isConnected) {
38
+ // TODO: error dialog
39
+ console.error('SDK: Not connected', response);
40
+ // openKernelUserUI(result.walletType, response.userUrl)
41
+ }
42
+ else {
43
+ console.log('SDK: Store connection', response);
44
+ storage.setKernelSession(response);
45
+ }
58
46
  return response;
59
47
  })
60
48
  .catch((err) => {
@@ -0,0 +1,33 @@
1
+ import { Status } from './typings.js';
2
+ import { Connect } from './typings.js';
3
+ import { DarsAvailable } from './typings.js';
4
+ import { PrepareReturn } from './typings.js';
5
+ import { PrepareExecute } from './typings.js';
6
+ import { LedgerApi } from './typings.js';
7
+ import { OnAccountsChanged } from './typings.js';
8
+ import { RequestAccounts } from './typings.js';
9
+ import { OnTxChanged } from './typings.js';
10
+ export type Methods = {
11
+ status: Status;
12
+ connect: Connect;
13
+ darsAvailable: DarsAvailable;
14
+ prepareReturn: PrepareReturn;
15
+ prepareExecute: PrepareExecute;
16
+ ledgerApi: LedgerApi;
17
+ onAccountsChanged: OnAccountsChanged;
18
+ requestAccounts: RequestAccounts;
19
+ onTxChanged: OnTxChanged;
20
+ };
21
+ declare function buildController(methods: Methods): {
22
+ status: Status;
23
+ connect: Connect;
24
+ darsAvailable: DarsAvailable;
25
+ prepareReturn: PrepareReturn;
26
+ prepareExecute: PrepareExecute;
27
+ ledgerApi: LedgerApi;
28
+ onAccountsChanged: OnAccountsChanged;
29
+ requestAccounts: RequestAccounts;
30
+ onTxChanged: OnTxChanged;
31
+ };
32
+ export default buildController;
33
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/dapp-api/rpc-gen/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE1C,MAAM,MAAM,OAAO,GAAG;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,OAAO,CAAA;IAChB,aAAa,EAAE,aAAa,CAAA;IAC5B,aAAa,EAAE,aAAa,CAAA;IAC5B,cAAc,EAAE,cAAc,CAAA;IAC9B,SAAS,EAAE,SAAS,CAAA;IACpB,iBAAiB,EAAE,iBAAiB,CAAA;IACpC,eAAe,EAAE,eAAe,CAAA;IAChC,WAAW,EAAE,WAAW,CAAA;CAC3B,CAAA;AAED,iBAAS,eAAe,CAAC,OAAO,EAAE,OAAO;;;;;;;;;;EAYxC;AAED,eAAe,eAAe,CAAA"}
@@ -0,0 +1,16 @@
1
+ // Copyright (c) 2025 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ function buildController(methods) {
4
+ return {
5
+ status: methods.status,
6
+ connect: methods.connect,
7
+ darsAvailable: methods.darsAvailable,
8
+ prepareReturn: methods.prepareReturn,
9
+ prepareExecute: methods.prepareExecute,
10
+ ledgerApi: methods.ledgerApi,
11
+ onAccountsChanged: methods.onAccountsChanged,
12
+ requestAccounts: methods.requestAccounts,
13
+ onTxChanged: methods.onTxChanged,
14
+ };
15
+ }
16
+ export default buildController;
@@ -0,0 +1,331 @@
1
+ /**
2
+ *
3
+ * Structure representing JS commands for transaction execution
4
+ *
5
+ */
6
+ export interface JsCommands {
7
+ [key: string]: any;
8
+ }
9
+ export type RequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE';
10
+ export type Resource = string;
11
+ export type Body = string;
12
+ /**
13
+ *
14
+ * The unique identifier of the Wallet Gateway.
15
+ *
16
+ */
17
+ export type Id = string;
18
+ /**
19
+ *
20
+ * The type of client that implements the Wallet Gateway.
21
+ *
22
+ */
23
+ export type ClientType = 'browser' | 'desktop' | 'mobile' | 'remote';
24
+ /**
25
+ *
26
+ * The URL of the Wallet Gateway.
27
+ *
28
+ */
29
+ export type Url = string;
30
+ /**
31
+ *
32
+ * A URL that points to a user interface.
33
+ *
34
+ */
35
+ export type UserUrl = string;
36
+ /**
37
+ *
38
+ * Represents a Wallet Gateway.
39
+ *
40
+ */
41
+ export interface KernelInfo {
42
+ id: Id;
43
+ clientType: ClientType;
44
+ url?: Url;
45
+ userUrl?: UserUrl;
46
+ [k: string]: any;
47
+ }
48
+ /**
49
+ *
50
+ * Whether or not a connection to a network is esablished.
51
+ *
52
+ */
53
+ export type IsConnected = boolean;
54
+ /**
55
+ *
56
+ * The network ID the wallet corresponds to.
57
+ *
58
+ */
59
+ export type ChainId = string;
60
+ /**
61
+ *
62
+ * JWT authentication token (if applicable).
63
+ *
64
+ */
65
+ export type SessionToken = string;
66
+ export type Dar = string;
67
+ export type Dars = Dar[];
68
+ /**
69
+ *
70
+ * The prepared transaction data.
71
+ *
72
+ */
73
+ export type PreparedTransaction = string;
74
+ /**
75
+ *
76
+ * The hash of the prepared transaction.
77
+ *
78
+ */
79
+ export type PreparedTransactionHash = string;
80
+ /**
81
+ *
82
+ * Structure representing the result of a prepareReturn call
83
+ *
84
+ */
85
+ export interface JsPrepareSubmissionResponse {
86
+ preparedTransaction?: PreparedTransaction;
87
+ preparedTransactionHash?: PreparedTransactionHash;
88
+ [k: string]: any;
89
+ }
90
+ /**
91
+ *
92
+ * The status of the transaction.
93
+ *
94
+ */
95
+ export type StatusExecuted = 'executed';
96
+ /**
97
+ *
98
+ * The unique identifier of the command associated with the transaction.
99
+ *
100
+ */
101
+ export type CommandId = string;
102
+ /**
103
+ *
104
+ * The update ID corresponding to the transaction.
105
+ *
106
+ */
107
+ export type UpdateId = string;
108
+ export type CompletionOffset = number;
109
+ /**
110
+ *
111
+ * Payload for the TxChangedExecutedEvent.
112
+ *
113
+ */
114
+ export interface TxChangedExecutedPayload {
115
+ updateId: UpdateId;
116
+ completionOffset: CompletionOffset;
117
+ }
118
+ /**
119
+ *
120
+ * Event emitted when a transaction is executed against the participant.
121
+ *
122
+ */
123
+ export interface TxChangedExecutedEvent {
124
+ status: StatusExecuted;
125
+ commandId: CommandId;
126
+ payload: TxChangedExecutedPayload;
127
+ }
128
+ export type Response = string;
129
+ /**
130
+ *
131
+ * Set as primary wallet for dApp usage.
132
+ *
133
+ */
134
+ export type Primary = boolean;
135
+ /**
136
+ *
137
+ * The party ID corresponding to the wallet.
138
+ *
139
+ */
140
+ export type PartyId = string;
141
+ /**
142
+ *
143
+ * The party hint and name of the wallet.
144
+ *
145
+ */
146
+ export type Hint = string;
147
+ /**
148
+ *
149
+ * The public key of the party.
150
+ *
151
+ */
152
+ export type PublicKey = string;
153
+ /**
154
+ *
155
+ * The namespace of the party.
156
+ *
157
+ */
158
+ export type Namespace = string;
159
+ /**
160
+ *
161
+ * The signing provider ID the wallet corresponds to.
162
+ *
163
+ */
164
+ export type SigningProviderId = string;
165
+ /**
166
+ *
167
+ * Structure representing a wallet
168
+ *
169
+ */
170
+ export interface Wallet {
171
+ primary: Primary;
172
+ partyId: PartyId;
173
+ hint: Hint;
174
+ publicKey: PublicKey;
175
+ namespace: Namespace;
176
+ chainId: ChainId;
177
+ signingProviderId: SigningProviderId;
178
+ [k: string]: any;
179
+ }
180
+ /**
181
+ *
182
+ * The status of the transaction.
183
+ *
184
+ */
185
+ export type StatusPending = 'pending';
186
+ /**
187
+ *
188
+ * Event emitted when a transaction is pending.
189
+ *
190
+ */
191
+ export interface TxChangedPendingEvent {
192
+ status: StatusPending;
193
+ commandId: CommandId;
194
+ }
195
+ /**
196
+ *
197
+ * The status of the transaction.
198
+ *
199
+ */
200
+ export type StatusSigned = 'signed';
201
+ /**
202
+ *
203
+ * The signature of the transaction.
204
+ *
205
+ */
206
+ export type Signature = string;
207
+ /**
208
+ *
209
+ * The identifier of the provider that signed the transaction.
210
+ *
211
+ */
212
+ export type SignedBy = string;
213
+ /**
214
+ *
215
+ * The party that signed the transaction.
216
+ *
217
+ */
218
+ export type Party = string;
219
+ /**
220
+ *
221
+ * Payload for the TxChangedSignedEvent.
222
+ *
223
+ */
224
+ export interface TxChangedSignedPayload {
225
+ signature: Signature;
226
+ signedBy: SignedBy;
227
+ party: Party;
228
+ }
229
+ /**
230
+ *
231
+ * Event emitted when a transaction has been signed.
232
+ *
233
+ */
234
+ export interface TxChangedSignedEvent {
235
+ status: StatusSigned;
236
+ commandId: CommandId;
237
+ payload: TxChangedSignedPayload;
238
+ }
239
+ /**
240
+ *
241
+ * The status of the transaction.
242
+ *
243
+ */
244
+ export type StatusFailed = 'failed';
245
+ /**
246
+ *
247
+ * Event emitted when a transaction has failed.
248
+ *
249
+ */
250
+ export interface TxChangedFailedEvent {
251
+ status: StatusFailed;
252
+ commandId: CommandId;
253
+ }
254
+ export interface PrepareReturnParams {
255
+ commands: JsCommands;
256
+ [k: string]: any;
257
+ }
258
+ export interface PrepareExecuteParams {
259
+ commands: JsCommands;
260
+ [k: string]: any;
261
+ }
262
+ export interface LedgerApiParams {
263
+ requestMethod: RequestMethod;
264
+ resource: Resource;
265
+ body?: Body;
266
+ [k: string]: any;
267
+ }
268
+ export interface StatusResult {
269
+ kernel: KernelInfo;
270
+ isConnected: IsConnected;
271
+ chainId?: ChainId;
272
+ [k: string]: any;
273
+ }
274
+ export interface ConnectResult {
275
+ kernel: KernelInfo;
276
+ isConnected: IsConnected;
277
+ chainId?: ChainId;
278
+ sessionToken: SessionToken;
279
+ [k: string]: any;
280
+ }
281
+ export interface DarsAvailableResult {
282
+ dars: Dars;
283
+ [k: string]: any;
284
+ }
285
+ export type PrepareReturnResult = any;
286
+ export interface PrepareExecuteResult {
287
+ tx: TxChangedExecutedEvent;
288
+ [k: string]: any;
289
+ }
290
+ /**
291
+ *
292
+ * Ledger Api configuration options
293
+ *
294
+ */
295
+ export interface LedgerApiResult {
296
+ response: Response;
297
+ [k: string]: any;
298
+ }
299
+ /**
300
+ *
301
+ * Event emitted when the user's accounts change.
302
+ *
303
+ */
304
+ export type AccountsChangedEvent = Wallet[];
305
+ /**
306
+ *
307
+ * An array of accounts that the user has authorized the dapp to access..
308
+ *
309
+ */
310
+ export type RequestAccountsResult = Wallet[];
311
+ /**
312
+ *
313
+ * Event emitted when a transaction changes.
314
+ *
315
+ */
316
+ export type TxChangedEvent = TxChangedPendingEvent | TxChangedSignedEvent | TxChangedExecutedEvent | TxChangedFailedEvent;
317
+ /**
318
+ *
319
+ * Generated! Represents an alias to any of the provided schemas
320
+ *
321
+ */
322
+ export type Status = () => Promise<StatusResult>;
323
+ export type Connect = () => Promise<ConnectResult>;
324
+ export type DarsAvailable = () => Promise<DarsAvailableResult>;
325
+ export type PrepareReturn = (params: PrepareReturnParams) => Promise<PrepareReturnResult>;
326
+ export type PrepareExecute = (params: PrepareExecuteParams) => Promise<PrepareExecuteResult>;
327
+ export type LedgerApi = (params: LedgerApiParams) => Promise<LedgerApiResult>;
328
+ export type OnAccountsChanged = () => Promise<AccountsChangedEvent>;
329
+ export type RequestAccounts = () => Promise<RequestAccountsResult>;
330
+ export type OnTxChanged = () => Promise<TxChangedEvent>;
331
+ //# sourceMappingURL=typings.d.ts.map
@@ -0,0 +1 @@
1
+ {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AAA;AAClD,MAAM,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,mBAAmB,CAAC,CAAA;AAC9D,MAAM,MAAM,aAAa,GAAG,CACxB,MAAM,EAAE,mBAAmB,KAC1B,OAAO,CAAC,mBAAmB,CAAC,CAAA;AACjC,MAAM,MAAM,cAAc,GAAG,CACzB,MAAM,EAAE,oBAAoB,KAC3B,OAAO,CAAC,oBAAoB,CAAC,CAAA;AAClC,MAAM,MAAM,SAAS,GAAG,CAAC,MAAM,EAAE,eAAe,KAAK,OAAO,CAAC,eAAe,CAAC,CAAA;AAC7E,MAAM,MAAM,iBAAiB,GAAG,MAAM,OAAO,CAAC,oBAAoB,CAAC,CAAA;AACnE,MAAM,MAAM,eAAe,GAAG,MAAM,OAAO,CAAC,qBAAqB,CAAC,CAAA;AAClE,MAAM,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,cAAc,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ // Copyright (c) 2025 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ export {};
package/dist/index.d.ts CHANGED
@@ -1,3 +1,13 @@
1
1
  export * from './connect';
2
2
  export * as dappAPI from '@canton-network/core-wallet-dapp-rpc-client';
3
+ export declare enum ErrorCode {
4
+ UserCancelled = 0,
5
+ Timeout = 1,
6
+ Other = 2
7
+ }
8
+ export type ConnectError = {
9
+ status: 'error';
10
+ error: ErrorCode;
11
+ details: string;
12
+ };
3
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,WAAW,CAAA;AACzB,OAAO,KAAK,OAAO,MAAM,6CAA6C,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,WAAW,CAAA;AACzB,OAAO,KAAK,OAAO,MAAM,6CAA6C,CAAA;AAEtE,oBAAY,SAAS;IACjB,aAAa,IAAA;IACb,OAAO,IAAA;IACP,KAAK,IAAA;CACR;AAED,MAAM,MAAM,YAAY,GAAG;IACvB,MAAM,EAAE,OAAO,CAAA;IACf,KAAK,EAAE,SAAS,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;CAClB,CAAA"}
package/dist/index.js CHANGED
@@ -2,3 +2,9 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  export * from './connect';
4
4
  export * as dappAPI from '@canton-network/core-wallet-dapp-rpc-client';
5
+ export var ErrorCode;
6
+ (function (ErrorCode) {
7
+ ErrorCode[ErrorCode["UserCancelled"] = 0] = "UserCancelled";
8
+ ErrorCode[ErrorCode["Timeout"] = 1] = "Timeout";
9
+ ErrorCode[ErrorCode["Other"] = 2] = "Other";
10
+ })(ErrorCode || (ErrorCode = {}));
@@ -0,0 +1,30 @@
1
+ import { SpliceProvider, EventListener } from '@canton-network/core-splice-provider';
2
+ import { DiscoverResult, RequestPayload } from '@canton-network/core-types';
3
+ /**
4
+ * The Provider class abstracts over the different types of SpliceProviders (Window and HTTP).
5
+ * It selects the appropriate provider based on the wallet type discovered during the connection process.
6
+ */
7
+ export declare class Provider implements SpliceProvider {
8
+ private providerType;
9
+ private httpProvider?;
10
+ private windowProvider?;
11
+ constructor({ walletType, url }: DiscoverResult, sessionToken?: string);
12
+ private getProvider;
13
+ request<T>(args: RequestPayload): Promise<T>;
14
+ on<T>(event: string, listener: EventListener<T>): SpliceProvider;
15
+ emit<T>(event: string, ...args: T[]): boolean;
16
+ removeListener<T>(event: string, listenerToRemove: EventListener<T>): SpliceProvider;
17
+ }
18
+ export declare const openKernelUserUI: (walletType: DiscoverResult["walletType"], userUrl: string) => void;
19
+ export declare const dappController: (provider: SpliceProvider) => {
20
+ status: import("./dapp-api/rpc-gen/typings").Status;
21
+ connect: import("./dapp-api/rpc-gen/typings").Connect;
22
+ darsAvailable: import("./dapp-api/rpc-gen/typings").DarsAvailable;
23
+ prepareReturn: import("./dapp-api/rpc-gen/typings").PrepareReturn;
24
+ prepareExecute: import("./dapp-api/rpc-gen/typings").PrepareExecute;
25
+ ledgerApi: import("./dapp-api/rpc-gen/typings").LedgerApi;
26
+ onAccountsChanged: import("./dapp-api/rpc-gen/typings").OnAccountsChanged;
27
+ requestAccounts: import("./dapp-api/rpc-gen/typings").RequestAccounts;
28
+ onTxChanged: import("./dapp-api/rpc-gen/typings").OnTxChanged;
29
+ };
30
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAGA,OAAO,EAEH,cAAc,EACd,aAAa,EAChB,MAAM,sCAAsC,CAAA;AAC7C,OAAO,EACH,cAAc,EACd,cAAc,EAGjB,MAAM,4BAA4B,CAAA;AAenC;;;GAGG;AACH,qBAAa,QAAS,YAAW,cAAc;IAC3C,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,YAAY,CAAC,CAAgB;IACrC,OAAO,CAAC,cAAc,CAAC,CAAgB;gBAE3B,EAAE,UAAU,EAAE,GAAG,EAAE,EAAE,cAAc,EAAE,YAAY,CAAC,EAAE,MAAM;IAetE,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC;IAmC5C,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,cAAc;IAIhE,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,CAAC,EAAE,GAAG,OAAO;IAI7C,cAAc,CAAC,CAAC,EACZ,KAAK,EAAE,MAAM,EACb,gBAAgB,EAAE,aAAa,CAAC,CAAC,CAAC,GACnC,cAAc;CAGpB;AAED,eAAO,MAAM,gBAAgB,GACzB,YAAY,cAAc,CAAC,YAAY,CAAC,EACxC,SAAS,MAAM,SAelB,CAAA;AAaD,eAAO,MAAM,cAAc,GAAI,UAAU,cAAc;;;;;;;;;;CA2FjD,CAAA"}
@@ -0,0 +1,165 @@
1
+ // Copyright (c) 2025 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { ProviderType, } from '@canton-network/core-splice-provider';
4
+ import { WalletEvent, } from '@canton-network/core-types';
5
+ import { popupHref } from '@canton-network/core-wallet-ui-components';
6
+ import { SpliceProviderHttp, SpliceProviderWindow, } from '@canton-network/core-splice-provider';
7
+ import buildController from './dapp-api/rpc-gen';
8
+ import { ErrorCode } from './index';
9
+ /**
10
+ * The Provider class abstracts over the different types of SpliceProviders (Window and HTTP).
11
+ * It selects the appropriate provider based on the wallet type discovered during the connection process.
12
+ */
13
+ export class Provider {
14
+ providerType;
15
+ httpProvider;
16
+ windowProvider;
17
+ constructor({ walletType, url }, sessionToken) {
18
+ if (walletType == 'extension') {
19
+ this.providerType = ProviderType.WINDOW;
20
+ this.windowProvider = new SpliceProviderWindow();
21
+ }
22
+ else if (walletType == 'remote') {
23
+ this.providerType = ProviderType.HTTP;
24
+ this.httpProvider = new SpliceProviderHttp(new URL(url), sessionToken);
25
+ }
26
+ else {
27
+ throw new Error(`Unsupported wallet type ${walletType}`);
28
+ }
29
+ }
30
+ getProvider() {
31
+ if (this.providerType === ProviderType.WINDOW)
32
+ return this.windowProvider;
33
+ return this.httpProvider;
34
+ }
35
+ request(args) {
36
+ if (this.providerType === ProviderType.WINDOW)
37
+ return this.getProvider().request(args);
38
+ const controller = dappController(this.getProvider());
39
+ switch (args.method) {
40
+ case 'status':
41
+ return controller.status();
42
+ case 'connect':
43
+ return controller.connect();
44
+ case 'darsAvailable':
45
+ return controller.darsAvailable();
46
+ case 'ledgerApi':
47
+ return controller.ledgerApi(args.params);
48
+ case 'prepareExecute':
49
+ return controller.prepareExecute(args.params);
50
+ case 'prepareReturn':
51
+ return controller.prepareReturn(args.params);
52
+ case 'requestAccounts':
53
+ return controller.requestAccounts();
54
+ case 'onAccountsChanged':
55
+ throw new Error('Only for events.');
56
+ case 'onTxChanged':
57
+ throw new Error('Only for events.');
58
+ default:
59
+ throw new Error('Unsupported method');
60
+ }
61
+ }
62
+ on(event, listener) {
63
+ return this.getProvider().on(event, listener);
64
+ }
65
+ emit(event, ...args) {
66
+ return this.getProvider().emit(event, args);
67
+ }
68
+ removeListener(event, listenerToRemove) {
69
+ return this.getProvider().removeListener(event, listenerToRemove);
70
+ }
71
+ }
72
+ export const openKernelUserUI = (walletType, userUrl) => {
73
+ switch (walletType) {
74
+ case 'remote':
75
+ popupHref(new URL(userUrl));
76
+ break;
77
+ case 'extension': {
78
+ const msg = {
79
+ type: WalletEvent.SPLICE_WALLET_EXT_OPEN,
80
+ url: userUrl,
81
+ };
82
+ window.postMessage(msg, '*');
83
+ break;
84
+ }
85
+ }
86
+ };
87
+ const withTimeout = (reject) => setTimeout(() => {
88
+ console.warn('SDK: Timeout waiting for connection');
89
+ reject({
90
+ status: 'error',
91
+ error: ErrorCode.Timeout,
92
+ details: 'Timeout waiting for connection',
93
+ });
94
+ }, 10 * 1000); // 10 seconds
95
+ // Remote dApp API Server which wraps the Remote-dApp API Server with promises
96
+ export const dappController = (provider) => buildController({
97
+ connect: async () => {
98
+ const response = await provider.request({
99
+ method: 'connect',
100
+ });
101
+ if (!response.isConnected)
102
+ openKernelUserUI('remote', response.userUrl);
103
+ const promise = new Promise((resolve, reject) => {
104
+ const timeout = withTimeout(reject);
105
+ provider.on('onConnected', (event) => {
106
+ clearTimeout(timeout);
107
+ const result = {
108
+ kernel: event.kernel,
109
+ isConnected: true,
110
+ chainId: event.chainId,
111
+ sessionToken: event.sessionToken ?? '',
112
+ userUrl: event.userUrl,
113
+ };
114
+ resolve(result);
115
+ });
116
+ });
117
+ return promise;
118
+ },
119
+ darsAvailable: async () => {
120
+ return provider.request({
121
+ method: 'darsAvailable',
122
+ });
123
+ },
124
+ ledgerApi: async (params) => provider.request({
125
+ method: 'ledgerApi',
126
+ params,
127
+ }),
128
+ prepareExecute: async (params) => {
129
+ const response = await provider.request({
130
+ method: 'prepareExecute',
131
+ params,
132
+ });
133
+ if (!response.isConnected)
134
+ openKernelUserUI('remote', response.userUrl);
135
+ const promise = new Promise((resolve, reject) => {
136
+ const timeout = withTimeout(reject);
137
+ provider.on('onTxChanged', (event) => {
138
+ console.log('SDK: TxChangedEvent', event);
139
+ clearTimeout(timeout);
140
+ if (event.status === 'executed') {
141
+ resolve({
142
+ tx: event,
143
+ });
144
+ }
145
+ });
146
+ });
147
+ return promise;
148
+ },
149
+ prepareReturn: async (params) => provider.request({
150
+ method: 'prepareReturn',
151
+ params,
152
+ }),
153
+ status: async () => {
154
+ return provider.request({ method: 'status' });
155
+ },
156
+ requestAccounts: async () => provider.request({
157
+ method: 'requestAccounts',
158
+ }),
159
+ onAccountsChanged: async () => {
160
+ throw new Error('Only for events.');
161
+ },
162
+ onTxChanged: async () => {
163
+ throw new Error('Only for events.');
164
+ },
165
+ });
package/dist/storage.d.ts CHANGED
@@ -2,7 +2,7 @@ import { DiscoverResult } from '@canton-network/core-types';
2
2
  import * as dappAPI from '@canton-network/core-wallet-dapp-rpc-client';
3
3
  export declare const getKernelDiscovery: () => DiscoverResult | undefined;
4
4
  export declare const setKernelDiscovery: (discovery: DiscoverResult) => void;
5
- export declare const getKernelSession: () => dappAPI.OnConnectedEvent | undefined;
6
- export declare const setKernelSession: (session: dappAPI.OnConnectedEvent) => void;
5
+ export declare const getKernelSession: () => dappAPI.ConnectResult | undefined;
6
+ export declare const setKernelSession: (session: dappAPI.ConnectResult) => void;
7
7
  export declare const removeKernelSession: () => void;
8
8
  //# sourceMappingURL=storage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,OAAO,MAAM,6CAA6C,CAAA;AAOtE,eAAO,MAAM,kBAAkB,QAAO,cAAc,GAAG,SAUtD,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,WAAW,cAAc,KAAG,IAK9D,CAAA;AAED,eAAO,MAAM,gBAAgB,QAAO,OAAO,CAAC,gBAAgB,GAAG,SAU9D,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,SAAS,OAAO,CAAC,gBAAgB,KAAG,IAEpE,CAAA;AAED,eAAO,MAAM,mBAAmB,QAAO,IAEtC,CAAA"}
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,OAAO,MAAM,6CAA6C,CAAA;AAOtE,eAAO,MAAM,kBAAkB,QAAO,cAAc,GAAG,SAUtD,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,WAAW,cAAc,KAAG,IAK9D,CAAA;AAED,eAAO,MAAM,gBAAgB,QAAO,OAAO,CAAC,aAAa,GAAG,SAU3D,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,SAAS,OAAO,CAAC,aAAa,KAAG,IAEjE,CAAA;AAED,eAAO,MAAM,mBAAmB,QAAO,IAEtC,CAAA"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@canton-network/dapp-sdk",
3
3
  "type": "module",
4
- "version": "0.4.0",
4
+ "version": "0.6.0",
5
5
  "description": "Browser SDK for dApp development on the Canton Network",
6
6
  "repository": "github:hyperledger-labs/splice-wallet-kernel",
7
7
  "license": "Apache-2.0",
@@ -15,10 +15,11 @@
15
15
  "test": "echo \"Warning: no test specified\""
16
16
  },
17
17
  "dependencies": {
18
- "@canton-network/core-splice-provider": "^0.4.0",
19
- "@canton-network/core-types": "^0.4.0",
20
- "@canton-network/core-wallet-dapp-rpc-client": "^0.1.0",
21
- "@canton-network/core-wallet-ui-components": "^0.4.0"
18
+ "@canton-network/core-splice-provider": "^0.6.0",
19
+ "@canton-network/core-types": "^0.6.0",
20
+ "@canton-network/core-wallet-dapp-remote-rpc-client": "^0.3.0",
21
+ "@canton-network/core-wallet-dapp-rpc-client": "^0.7.0",
22
+ "@canton-network/core-wallet-ui-components": "^0.6.0"
22
23
  },
23
24
  "devDependencies": {
24
25
  "typescript": "^5.8.3"