@canton-network/core-provider-dapp 0.1.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.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # provider-dapp
2
+
3
+ This package supplies a CIP-0103 implementation of a Provider for Canton dApps.
@@ -0,0 +1,14 @@
1
+ import { RpcTypes as DappAsyncRpcTypes } from '@canton-network/core-wallet-dapp-remote-rpc-client';
2
+ import { AbstractProvider } from '@canton-network/core-splice-provider';
3
+ import { RequestArgs } from '@canton-network/core-types';
4
+ export declare class DappAsyncProvider extends AbstractProvider<DappAsyncRpcTypes> {
5
+ private url;
6
+ private sessionToken?;
7
+ private client;
8
+ private status?;
9
+ private createClient;
10
+ private openSSE;
11
+ constructor(url: URL, sessionToken?: string);
12
+ request<M extends keyof DappAsyncRpcTypes>(args: RequestArgs<DappAsyncRpcTypes, M>): Promise<DappAsyncRpcTypes[M]['result']>;
13
+ }
14
+ //# sourceMappingURL=DappAsyncProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DappAsyncProvider.d.ts","sourceRoot":"","sources":["../src/DappAsyncProvider.ts"],"names":[],"mappings":"AAGA,OAAyC,EACrC,QAAQ,IAAI,iBAAiB,EAEhC,MAAM,oDAAoD,CAAA;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAA;AAEvE,OAAO,EAEH,WAAW,EAEd,MAAM,4BAA4B,CAAA;AAqBnC,qBAAa,iBAAkB,SAAQ,gBAAgB,CAAC,iBAAiB,CAAC;IA8DlE,OAAO,CAAC,GAAG;IA7Df,OAAO,CAAC,YAAY,CAAC,CAAQ;IAC7B,OAAO,CAAC,MAAM,CAAkC;IAChD,OAAO,CAAC,MAAM,CAAC,CAAqB;IAEpC,OAAO,CAAC,YAAY;IAOpB,OAAO,CAAC,OAAO;gBAkDH,GAAG,EAAE,GAAG,EAChB,YAAY,CAAC,EAAE,MAAM;IA8CZ,OAAO,CAAC,CAAC,SAAS,MAAM,iBAAiB,EAClD,IAAI,EAAE,WAAW,CAAC,iBAAiB,EAAE,CAAC,CAAC,GACxC,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;CAG7C"}
@@ -0,0 +1,10 @@
1
+ import { RpcTypes as DappRpcTypes } from '@canton-network/core-wallet-dapp-rpc-client';
2
+ import { AbstractProvider } from '@canton-network/core-splice-provider';
3
+ import { RequestArgs } from '@canton-network/core-types';
4
+ import { RpcTransport } from '@canton-network/core-rpc-transport';
5
+ export declare class DappSyncProvider extends AbstractProvider<DappRpcTypes> {
6
+ private client;
7
+ constructor(transport?: RpcTransport);
8
+ request<M extends keyof DappRpcTypes>(args: RequestArgs<DappRpcTypes, M>): Promise<DappRpcTypes[M]['result']>;
9
+ }
10
+ //# sourceMappingURL=DappSyncProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DappSyncProvider.d.ts","sourceRoot":"","sources":["../src/DappSyncProvider.ts"],"names":[],"mappings":"AAGA,OAAmC,EAC/B,QAAQ,IAAI,YAAY,EAC3B,MAAM,6CAA6C,CAAA;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAA;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,EACH,YAAY,EAEf,MAAM,oCAAoC,CAAA;AAE3C,qBAAa,gBAAiB,SAAQ,gBAAgB,CAAC,YAAY,CAAC;IAChE,OAAO,CAAC,MAAM,CAA4B;gBAE9B,SAAS,CAAC,EAAE,YAAY;IAOvB,OAAO,CAAC,CAAC,SAAS,MAAM,YAAY,EAC7C,IAAI,EAAE,WAAW,CAAC,YAAY,EAAE,CAAC,CAAC,GACnC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;CAGxC"}
package/dist/index.cjs ADDED
@@ -0,0 +1,132 @@
1
+ 'use strict';
2
+
3
+ var SpliceWalletJSONRPCDAppAPI = require('@canton-network/core-wallet-dapp-rpc-client');
4
+ var coreSpliceProvider = require('@canton-network/core-splice-provider');
5
+ var coreRpcTransport = require('@canton-network/core-rpc-transport');
6
+ var SpliceWalletJSONRPCRemoteDAppAPI = require('@canton-network/core-wallet-dapp-remote-rpc-client');
7
+ var coreTypes = require('@canton-network/core-types');
8
+
9
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
+
11
+ var SpliceWalletJSONRPCDAppAPI__default = /*#__PURE__*/_interopDefault(SpliceWalletJSONRPCDAppAPI);
12
+ var SpliceWalletJSONRPCRemoteDAppAPI__default = /*#__PURE__*/_interopDefault(SpliceWalletJSONRPCRemoteDAppAPI);
13
+
14
+ var __defProp = Object.defineProperty;
15
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
16
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
17
+ var DappSyncProvider = class extends coreSpliceProvider.AbstractProvider {
18
+ constructor(transport) {
19
+ super();
20
+ __publicField(this, "client");
21
+ this.client = new SpliceWalletJSONRPCDAppAPI__default.default(
22
+ transport ?? new coreRpcTransport.WindowTransport(window)
23
+ );
24
+ }
25
+ async request(args) {
26
+ return await this.client.request(args);
27
+ }
28
+ };
29
+ var connection = null;
30
+ function parseSSEData(data) {
31
+ try {
32
+ const parsed = JSON.parse(data);
33
+ return Array.isArray(parsed) ? parsed : [parsed];
34
+ } catch {
35
+ return [data];
36
+ }
37
+ }
38
+ var DappAsyncProvider = class extends coreSpliceProvider.AbstractProvider {
39
+ constructor(url, sessionToken) {
40
+ super();
41
+ this.url = url;
42
+ __publicField(this, "sessionToken");
43
+ __publicField(this, "client");
44
+ __publicField(this, "status");
45
+ if (sessionToken) {
46
+ this.sessionToken = sessionToken;
47
+ this.openSSE(url, sessionToken);
48
+ }
49
+ this.client = this.createClient(sessionToken);
50
+ window.addEventListener("message", async (event) => {
51
+ if (!coreTypes.isSpliceMessageEvent(event)) return;
52
+ if (event.data.type === coreTypes.WalletEvent.SPLICE_WALLET_IDP_AUTH_SUCCESS) {
53
+ this.sessionToken = event.data.token;
54
+ this.client = this.createClient(this.sessionToken);
55
+ this.openSSE(this.url, event.data.token);
56
+ this.request({ method: "status" }).then((status) => {
57
+ if (JSON.stringify(status.session) !== JSON.stringify(this.status)) {
58
+ this.emit("statusChanged", status);
59
+ this.status = status.session;
60
+ }
61
+ }).catch((err) => {
62
+ console.error(
63
+ "Error requesting status after auth:",
64
+ err
65
+ );
66
+ });
67
+ }
68
+ });
69
+ }
70
+ createClient(sessionToken) {
71
+ const transport = new coreRpcTransport.HttpTransport(this.url, sessionToken);
72
+ return new SpliceWalletJSONRPCRemoteDAppAPI__default.default(transport);
73
+ }
74
+ openSSE(url, token) {
75
+ const sseUrl = new URL("events", url.toString().replace(/\/?$/, "/"));
76
+ sseUrl.searchParams.set("token", token);
77
+ const sseUrlString = sseUrl.toString();
78
+ if (connection && (token !== connection.token || sseUrlString !== connection.url)) {
79
+ connection.eventSource.close();
80
+ connection = null;
81
+ }
82
+ if (!connection) {
83
+ const eventSource = new EventSource(sseUrlString);
84
+ eventSource.onmessage = (event) => this.emit("message", ...parseSSEData(event.data));
85
+ const emitEvent = (name) => (event) => this.emit(name, ...parseSSEData(event.data));
86
+ eventSource.addEventListener(
87
+ "accountsChanged",
88
+ emitEvent("accountsChanged")
89
+ );
90
+ eventSource.addEventListener(
91
+ "statusChanged",
92
+ emitEvent("statusChanged")
93
+ );
94
+ eventSource.addEventListener("connected", emitEvent("connected"));
95
+ eventSource.addEventListener("txChanged", emitEvent("txChanged"));
96
+ eventSource.onerror = () => {
97
+ if (connection?.url === sseUrlString) {
98
+ connection.eventSource.close();
99
+ connection = null;
100
+ }
101
+ };
102
+ connection = {
103
+ eventSource,
104
+ url: sseUrlString,
105
+ token
106
+ };
107
+ }
108
+ }
109
+ async request(args) {
110
+ return await this.client.request(args);
111
+ }
112
+ };
113
+
114
+ // src/index.ts
115
+ var ProviderType = /* @__PURE__ */ ((ProviderType2) => {
116
+ ProviderType2[ProviderType2["WINDOW"] = 0] = "WINDOW";
117
+ ProviderType2[ProviderType2["HTTP"] = 1] = "HTTP";
118
+ return ProviderType2;
119
+ })(ProviderType || {});
120
+ function injectProvider(provider) {
121
+ if (window.canton !== void 0) return window.canton;
122
+ window.canton = provider;
123
+ console.log("Splice provider injected successfully.");
124
+ return window.canton;
125
+ }
126
+
127
+ exports.DappAsyncProvider = DappAsyncProvider;
128
+ exports.DappSyncProvider = DappSyncProvider;
129
+ exports.ProviderType = ProviderType;
130
+ exports.injectProvider = injectProvider;
131
+ //# sourceMappingURL=index.cjs.map
132
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/DappSyncProvider.ts","../src/DappAsyncProvider.ts","../src/index.ts"],"names":["AbstractProvider","SpliceWalletJSONRPCDAppAPI","WindowTransport","isSpliceMessageEvent","WalletEvent","HttpTransport","SpliceWalletJSONRPCRemoteDAppAPI","ProviderType"],"mappings":";;;;;;;;;;;;;;;;AAaO,IAAM,gBAAA,GAAN,cAA+BA,mCAAA,CAA+B;AAAA,EAGjE,YAAY,SAAA,EAA0B;AAClC,IAAA,KAAA,EAAM;AAHV,IAAA,aAAA,CAAA,IAAA,EAAQ,QAAA,CAAA;AAIJ,IAAA,IAAA,CAAK,SAAS,IAAIC,2CAAA;AAAA,MACd,SAAA,IAAa,IAAIC,gCAAA,CAAgB,MAAM;AAAA,KAC3C;AAAA,EACJ;AAAA,EAEA,MAAa,QACT,IAAA,EACkC;AAClC,IAAA,OAAO,MAAM,IAAA,CAAK,MAAA,CAAO,OAAA,CAAW,IAAI,CAAA;AAAA,EAC5C;AACJ;ACLA,IAAI,UAAA,GAAyB,IAAA;AAE7B,SAAS,aAAa,IAAA,EAAyB;AAC3C,EAAA,IAAI;AACA,IAAA,MAAM,MAAA,GAAS,IAAA,CAAK,KAAA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AAA;AAFQ,EAAA,OAAAA,aAAAA;AAAA,CAAA,EAAA,YAAA,IAAA,EAAA;AAKL,SAAS,eACZ,QAAA,EACqB;AAErB,EAAA,IAAI,MAAA,CAAO,MAAA,KAAW,MAAA,EAAW,OAAO,MAAA,CAAO,MAAA;AAG/C,EAAA,MAAA,CAAO,MAAA,GAAS,QAAA;AAEhB,EAAA,OAAA,CAAQ,IAAI,wCAAwC,CAAA;AACpD,EAAA,OAAO,MAAA,CAAO,MAAA;AAClB","file":"index.cjs","sourcesContent":["// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport SpliceWalletJSONRPCDAppAPI, {\n RpcTypes as DappRpcTypes,\n} from '@canton-network/core-wallet-dapp-rpc-client'\nimport { AbstractProvider } from '@canton-network/core-splice-provider'\nimport { RequestArgs } from '@canton-network/core-types'\nimport {\n RpcTransport,\n WindowTransport,\n} from '@canton-network/core-rpc-transport'\n\nexport class DappSyncProvider extends AbstractProvider<DappRpcTypes> {\n private client: SpliceWalletJSONRPCDAppAPI\n\n constructor(transport?: RpcTransport) {\n super()\n this.client = new SpliceWalletJSONRPCDAppAPI(\n transport ?? new WindowTransport(window)\n )\n }\n\n public async request<M extends keyof DappRpcTypes>(\n args: RequestArgs<DappRpcTypes, M>\n ): Promise<DappRpcTypes[M]['result']> {\n return await this.client.request<M>(args)\n }\n}\n","// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport SpliceWalletJSONRPCRemoteDAppAPI, {\n RpcTypes as DappAsyncRpcTypes,\n Session,\n} from '@canton-network/core-wallet-dapp-remote-rpc-client'\nimport { AbstractProvider } from '@canton-network/core-splice-provider'\nimport { HttpTransport } from '@canton-network/core-rpc-transport'\nimport {\n isSpliceMessageEvent,\n RequestArgs,\n WalletEvent,\n} from '@canton-network/core-types'\n\n// Maintain a global SSE connection in-memory to avoid multiple connections\n// per DappAsyncProvider instance.\ntype GatewaySSE = {\n url: string\n token: string\n eventSource: EventSource\n} | null\n\nlet connection: GatewaySSE = null\n\nfunction parseSSEData(data: string): unknown[] {\n try {\n const parsed = JSON.parse(data)\n return Array.isArray(parsed) ? parsed : [parsed]\n } catch {\n return [data]\n }\n}\n\nexport class DappAsyncProvider extends AbstractProvider<DappAsyncRpcTypes> {\n private sessionToken?: string\n private client: SpliceWalletJSONRPCRemoteDAppAPI\n private status?: Session | undefined\n\n private createClient(\n sessionToken?: string\n ): SpliceWalletJSONRPCRemoteDAppAPI {\n const transport = new HttpTransport(this.url, sessionToken)\n return new SpliceWalletJSONRPCRemoteDAppAPI(transport)\n }\n\n private openSSE(url: URL, token: string): void {\n const sseUrl = new URL('events', url.toString().replace(/\\/?$/, '/'))\n sseUrl.searchParams.set('token', token)\n const sseUrlString = sseUrl.toString()\n\n // Reconnect if the URL or token has changed\n if (\n connection &&\n (token !== connection.token || sseUrlString !== connection.url)\n ) {\n connection.eventSource.close()\n connection = null\n }\n\n if (!connection) {\n const eventSource = new EventSource(sseUrlString)\n\n eventSource.onmessage = (event) =>\n this.emit('message', ...parseSSEData(event.data))\n\n const emitEvent = (name: string) => (event: MessageEvent) =>\n this.emit(name, ...parseSSEData(event.data))\n\n eventSource.addEventListener(\n 'accountsChanged',\n emitEvent('accountsChanged')\n )\n eventSource.addEventListener(\n 'statusChanged',\n emitEvent('statusChanged')\n )\n eventSource.addEventListener('connected', emitEvent('connected'))\n eventSource.addEventListener('txChanged', emitEvent('txChanged'))\n\n eventSource.onerror = () => {\n if (connection?.url === sseUrlString) {\n connection.eventSource.close()\n connection = null\n }\n }\n\n connection = {\n eventSource,\n url: sseUrlString,\n token,\n }\n }\n }\n\n constructor(\n private url: URL,\n sessionToken?: string\n ) {\n super()\n\n if (sessionToken) {\n this.sessionToken = sessionToken\n this.openSSE(url, sessionToken)\n }\n\n this.client = this.createClient(sessionToken)\n\n // Listen for the auth success event sent from the WK UI popup to the SDK running in the parent window.\n window.addEventListener('message', async (event) => {\n if (!isSpliceMessageEvent(event)) return\n\n if (\n event.data.type === WalletEvent.SPLICE_WALLET_IDP_AUTH_SUCCESS\n ) {\n this.sessionToken = event.data.token\n this.client = this.createClient(this.sessionToken)\n this.openSSE(this.url, event.data.token)\n\n // We requery the status explicitly here, as it's not guaranteed that the socket will be open & authenticated\n // before the `statusChanged` event is fired from the `addSession` RPC call. The dappApi.StatusResult and\n // dappApi.StatusEvent are mapped manually to avoid dependency.\n this.request({ method: 'status' })\n .then((status) => {\n //for some reason comparing the objects directly dosent work as intended\n if (\n JSON.stringify(status.session) !==\n JSON.stringify(this.status)\n ) {\n this.emit('statusChanged', status)\n this.status = status.session\n }\n })\n .catch((err) => {\n console.error(\n 'Error requesting status after auth:',\n err\n )\n })\n }\n })\n }\n\n public async request<M extends keyof DappAsyncRpcTypes>(\n args: RequestArgs<DappAsyncRpcTypes, M>\n ): Promise<DappAsyncRpcTypes[M]['result']> {\n return await this.client.request<M>(args)\n }\n}\n","// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { RpcTypes as DappSyncRpc } from '@canton-network/core-wallet-dapp-rpc-client'\nimport { Provider } from '@canton-network/core-splice-provider'\n\ndeclare global {\n interface Window {\n // we assume that we will always use a full DappProvider in the browser context\n canton?: Provider<DappSyncRpc> | undefined\n }\n}\n\nexport enum ProviderType {\n WINDOW,\n HTTP,\n}\n\nexport function injectProvider(\n provider: Provider<DappSyncRpc>\n): Provider<DappSyncRpc> {\n // Check if the provider is already injected\n if (window.canton !== undefined) return window.canton\n\n // Inject the Provider instance\n window.canton = provider\n\n console.log('Splice provider injected successfully.')\n return window.canton\n}\n\nexport * from './DappSyncProvider'\nexport * from './DappAsyncProvider'\n"]}
@@ -0,0 +1,15 @@
1
+ import { RpcTypes as DappSyncRpc } from '@canton-network/core-wallet-dapp-rpc-client';
2
+ import { Provider } from '@canton-network/core-splice-provider';
3
+ declare global {
4
+ interface Window {
5
+ canton?: Provider<DappSyncRpc> | undefined;
6
+ }
7
+ }
8
+ export declare enum ProviderType {
9
+ WINDOW = 0,
10
+ HTTP = 1
11
+ }
12
+ export declare function injectProvider(provider: Provider<DappSyncRpc>): Provider<DappSyncRpc>;
13
+ export * from './DappSyncProvider';
14
+ export * from './DappAsyncProvider';
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,IAAI,WAAW,EAAE,MAAM,6CAA6C,CAAA;AACrF,OAAO,EAAE,QAAQ,EAAE,MAAM,sCAAsC,CAAA;AAE/D,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM;QAEZ,MAAM,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,SAAS,CAAA;KAC7C;CACJ;AAED,oBAAY,YAAY;IACpB,MAAM,IAAA;IACN,IAAI,IAAA;CACP;AAED,wBAAgB,cAAc,CAC1B,QAAQ,EAAE,QAAQ,CAAC,WAAW,CAAC,GAChC,QAAQ,CAAC,WAAW,CAAC,CASvB;AAED,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,122 @@
1
+ import SpliceWalletJSONRPCDAppAPI from '@canton-network/core-wallet-dapp-rpc-client';
2
+ import { AbstractProvider } from '@canton-network/core-splice-provider';
3
+ import { WindowTransport, HttpTransport } from '@canton-network/core-rpc-transport';
4
+ import SpliceWalletJSONRPCRemoteDAppAPI from '@canton-network/core-wallet-dapp-remote-rpc-client';
5
+ import { isSpliceMessageEvent, WalletEvent } from '@canton-network/core-types';
6
+
7
+ var __defProp = Object.defineProperty;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
10
+ var DappSyncProvider = class extends AbstractProvider {
11
+ constructor(transport) {
12
+ super();
13
+ __publicField(this, "client");
14
+ this.client = new SpliceWalletJSONRPCDAppAPI(
15
+ transport ?? new WindowTransport(window)
16
+ );
17
+ }
18
+ async request(args) {
19
+ return await this.client.request(args);
20
+ }
21
+ };
22
+ var connection = null;
23
+ function parseSSEData(data) {
24
+ try {
25
+ const parsed = JSON.parse(data);
26
+ return Array.isArray(parsed) ? parsed : [parsed];
27
+ } catch {
28
+ return [data];
29
+ }
30
+ }
31
+ var DappAsyncProvider = class extends AbstractProvider {
32
+ constructor(url, sessionToken) {
33
+ super();
34
+ this.url = url;
35
+ __publicField(this, "sessionToken");
36
+ __publicField(this, "client");
37
+ __publicField(this, "status");
38
+ if (sessionToken) {
39
+ this.sessionToken = sessionToken;
40
+ this.openSSE(url, sessionToken);
41
+ }
42
+ this.client = this.createClient(sessionToken);
43
+ window.addEventListener("message", async (event) => {
44
+ if (!isSpliceMessageEvent(event)) return;
45
+ if (event.data.type === WalletEvent.SPLICE_WALLET_IDP_AUTH_SUCCESS) {
46
+ this.sessionToken = event.data.token;
47
+ this.client = this.createClient(this.sessionToken);
48
+ this.openSSE(this.url, event.data.token);
49
+ this.request({ method: "status" }).then((status) => {
50
+ if (JSON.stringify(status.session) !== JSON.stringify(this.status)) {
51
+ this.emit("statusChanged", status);
52
+ this.status = status.session;
53
+ }
54
+ }).catch((err) => {
55
+ console.error(
56
+ "Error requesting status after auth:",
57
+ err
58
+ );
59
+ });
60
+ }
61
+ });
62
+ }
63
+ createClient(sessionToken) {
64
+ const transport = new HttpTransport(this.url, sessionToken);
65
+ return new SpliceWalletJSONRPCRemoteDAppAPI(transport);
66
+ }
67
+ openSSE(url, token) {
68
+ const sseUrl = new URL("events", url.toString().replace(/\/?$/, "/"));
69
+ sseUrl.searchParams.set("token", token);
70
+ const sseUrlString = sseUrl.toString();
71
+ if (connection && (token !== connection.token || sseUrlString !== connection.url)) {
72
+ connection.eventSource.close();
73
+ connection = null;
74
+ }
75
+ if (!connection) {
76
+ const eventSource = new EventSource(sseUrlString);
77
+ eventSource.onmessage = (event) => this.emit("message", ...parseSSEData(event.data));
78
+ const emitEvent = (name) => (event) => this.emit(name, ...parseSSEData(event.data));
79
+ eventSource.addEventListener(
80
+ "accountsChanged",
81
+ emitEvent("accountsChanged")
82
+ );
83
+ eventSource.addEventListener(
84
+ "statusChanged",
85
+ emitEvent("statusChanged")
86
+ );
87
+ eventSource.addEventListener("connected", emitEvent("connected"));
88
+ eventSource.addEventListener("txChanged", emitEvent("txChanged"));
89
+ eventSource.onerror = () => {
90
+ if (connection?.url === sseUrlString) {
91
+ connection.eventSource.close();
92
+ connection = null;
93
+ }
94
+ };
95
+ connection = {
96
+ eventSource,
97
+ url: sseUrlString,
98
+ token
99
+ };
100
+ }
101
+ }
102
+ async request(args) {
103
+ return await this.client.request(args);
104
+ }
105
+ };
106
+
107
+ // src/index.ts
108
+ var ProviderType = /* @__PURE__ */ ((ProviderType2) => {
109
+ ProviderType2[ProviderType2["WINDOW"] = 0] = "WINDOW";
110
+ ProviderType2[ProviderType2["HTTP"] = 1] = "HTTP";
111
+ return ProviderType2;
112
+ })(ProviderType || {});
113
+ function injectProvider(provider) {
114
+ if (window.canton !== void 0) return window.canton;
115
+ window.canton = provider;
116
+ console.log("Splice provider injected successfully.");
117
+ return window.canton;
118
+ }
119
+
120
+ export { DappAsyncProvider, DappSyncProvider, ProviderType, injectProvider };
121
+ //# sourceMappingURL=index.js.map
122
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/DappSyncProvider.ts","../src/DappAsyncProvider.ts","../src/index.ts"],"names":["AbstractProvider","ProviderType"],"mappings":";;;;;;;;;AAaO,IAAM,gBAAA,GAAN,cAA+B,gBAAA,CAA+B;AAAA,EAGjE,YAAY,SAAA,EAA0B;AAClC,IAAA,KAAA,EAAM;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,QACT,WAAA;AAAA,QACA,GAAA,EAAK,YAAA;AAAA,QACL;AAAA,OACJ;AAAA,IACJ;AAAA,EACJ;AAAA,EAkDA,MAAa,QACT,IAAA,EACuC;AACvC,IAAA,OAAO,MAAM,IAAA,CAAK,MAAA,CAAO,OAAA,CAAW,IAAI,CAAA;AAAA,EAC5C;AACJ;;;ACvIO,IAAK,YAAA,qBAAAC,aAAAA,KAAL;AACH,EAAAA,aAAAA,CAAAA,aAAAA,CAAA,QAAA,CAAA,GAAA,CAAA,CAAA,GAAA,QAAA;AACA,EAAAA,aAAAA,CAAAA,aAAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAA;AAFQ,EAAA,OAAAA,aAAAA;AAAA,CAAA,EAAA,YAAA,IAAA,EAAA;AAKL,SAAS,eACZ,QAAA,EACqB;AAErB,EAAA,IAAI,MAAA,CAAO,MAAA,KAAW,MAAA,EAAW,OAAO,MAAA,CAAO,MAAA;AAG/C,EAAA,MAAA,CAAO,MAAA,GAAS,QAAA;AAEhB,EAAA,OAAA,CAAQ,IAAI,wCAAwC,CAAA;AACpD,EAAA,OAAO,MAAA,CAAO,MAAA;AAClB","file":"index.js","sourcesContent":["// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport SpliceWalletJSONRPCDAppAPI, {\n RpcTypes as DappRpcTypes,\n} from '@canton-network/core-wallet-dapp-rpc-client'\nimport { AbstractProvider } from '@canton-network/core-splice-provider'\nimport { RequestArgs } from '@canton-network/core-types'\nimport {\n RpcTransport,\n WindowTransport,\n} from '@canton-network/core-rpc-transport'\n\nexport class DappSyncProvider extends AbstractProvider<DappRpcTypes> {\n private client: SpliceWalletJSONRPCDAppAPI\n\n constructor(transport?: RpcTransport) {\n super()\n this.client = new SpliceWalletJSONRPCDAppAPI(\n transport ?? new WindowTransport(window)\n )\n }\n\n public async request<M extends keyof DappRpcTypes>(\n args: RequestArgs<DappRpcTypes, M>\n ): Promise<DappRpcTypes[M]['result']> {\n return await this.client.request<M>(args)\n }\n}\n","// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport SpliceWalletJSONRPCRemoteDAppAPI, {\n RpcTypes as DappAsyncRpcTypes,\n Session,\n} from '@canton-network/core-wallet-dapp-remote-rpc-client'\nimport { AbstractProvider } from '@canton-network/core-splice-provider'\nimport { HttpTransport } from '@canton-network/core-rpc-transport'\nimport {\n isSpliceMessageEvent,\n RequestArgs,\n WalletEvent,\n} from '@canton-network/core-types'\n\n// Maintain a global SSE connection in-memory to avoid multiple connections\n// per DappAsyncProvider instance.\ntype GatewaySSE = {\n url: string\n token: string\n eventSource: EventSource\n} | null\n\nlet connection: GatewaySSE = null\n\nfunction parseSSEData(data: string): unknown[] {\n try {\n const parsed = JSON.parse(data)\n return Array.isArray(parsed) ? parsed : [parsed]\n } catch {\n return [data]\n }\n}\n\nexport class DappAsyncProvider extends AbstractProvider<DappAsyncRpcTypes> {\n private sessionToken?: string\n private client: SpliceWalletJSONRPCRemoteDAppAPI\n private status?: Session | undefined\n\n private createClient(\n sessionToken?: string\n ): SpliceWalletJSONRPCRemoteDAppAPI {\n const transport = new HttpTransport(this.url, sessionToken)\n return new SpliceWalletJSONRPCRemoteDAppAPI(transport)\n }\n\n private openSSE(url: URL, token: string): void {\n const sseUrl = new URL('events', url.toString().replace(/\\/?$/, '/'))\n sseUrl.searchParams.set('token', token)\n const sseUrlString = sseUrl.toString()\n\n // Reconnect if the URL or token has changed\n if (\n connection &&\n (token !== connection.token || sseUrlString !== connection.url)\n ) {\n connection.eventSource.close()\n connection = null\n }\n\n if (!connection) {\n const eventSource = new EventSource(sseUrlString)\n\n eventSource.onmessage = (event) =>\n this.emit('message', ...parseSSEData(event.data))\n\n const emitEvent = (name: string) => (event: MessageEvent) =>\n this.emit(name, ...parseSSEData(event.data))\n\n eventSource.addEventListener(\n 'accountsChanged',\n emitEvent('accountsChanged')\n )\n eventSource.addEventListener(\n 'statusChanged',\n emitEvent('statusChanged')\n )\n eventSource.addEventListener('connected', emitEvent('connected'))\n eventSource.addEventListener('txChanged', emitEvent('txChanged'))\n\n eventSource.onerror = () => {\n if (connection?.url === sseUrlString) {\n connection.eventSource.close()\n connection = null\n }\n }\n\n connection = {\n eventSource,\n url: sseUrlString,\n token,\n }\n }\n }\n\n constructor(\n private url: URL,\n sessionToken?: string\n ) {\n super()\n\n if (sessionToken) {\n this.sessionToken = sessionToken\n this.openSSE(url, sessionToken)\n }\n\n this.client = this.createClient(sessionToken)\n\n // Listen for the auth success event sent from the WK UI popup to the SDK running in the parent window.\n window.addEventListener('message', async (event) => {\n if (!isSpliceMessageEvent(event)) return\n\n if (\n event.data.type === WalletEvent.SPLICE_WALLET_IDP_AUTH_SUCCESS\n ) {\n this.sessionToken = event.data.token\n this.client = this.createClient(this.sessionToken)\n this.openSSE(this.url, event.data.token)\n\n // We requery the status explicitly here, as it's not guaranteed that the socket will be open & authenticated\n // before the `statusChanged` event is fired from the `addSession` RPC call. The dappApi.StatusResult and\n // dappApi.StatusEvent are mapped manually to avoid dependency.\n this.request({ method: 'status' })\n .then((status) => {\n //for some reason comparing the objects directly dosent work as intended\n if (\n JSON.stringify(status.session) !==\n JSON.stringify(this.status)\n ) {\n this.emit('statusChanged', status)\n this.status = status.session\n }\n })\n .catch((err) => {\n console.error(\n 'Error requesting status after auth:',\n err\n )\n })\n }\n })\n }\n\n public async request<M extends keyof DappAsyncRpcTypes>(\n args: RequestArgs<DappAsyncRpcTypes, M>\n ): Promise<DappAsyncRpcTypes[M]['result']> {\n return await this.client.request<M>(args)\n }\n}\n","// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { RpcTypes as DappSyncRpc } from '@canton-network/core-wallet-dapp-rpc-client'\nimport { Provider } from '@canton-network/core-splice-provider'\n\ndeclare global {\n interface Window {\n // we assume that we will always use a full DappProvider in the browser context\n canton?: Provider<DappSyncRpc> | undefined\n }\n}\n\nexport enum ProviderType {\n WINDOW,\n HTTP,\n}\n\nexport function injectProvider(\n provider: Provider<DappSyncRpc>\n): Provider<DappSyncRpc> {\n // Check if the provider is already injected\n if (window.canton !== undefined) return window.canton\n\n // Inject the Provider instance\n window.canton = provider\n\n console.log('Splice provider injected successfully.')\n return window.canton\n}\n\nexport * from './DappSyncProvider'\nexport * from './DappAsyncProvider'\n"]}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@canton-network/core-provider-dapp",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "CIP-0103 provider for web dApps, covering both Sync and Async APIs.",
6
+ "license": "Apache-2.0",
7
+ "author": "Alex Matson <alex.matson@digitalasset.com>",
8
+ "packageManager": "yarn@4.9.4",
9
+ "main": "./dist/index.cjs",
10
+ "module": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js",
16
+ "require": "./dist/index.cjs",
17
+ "default": "./dist/index.js"
18
+ }
19
+ },
20
+ "scripts": {
21
+ "build": "tsup && tsc -p tsconfig.types.json",
22
+ "dev": "tsup --watch --onSuccess \"tsc -p tsconfig.types.json\"",
23
+ "flatpack": "yarn pack --out \"$FLATPACK_OUTDIR\"",
24
+ "clean": "tsc -b --clean; rm -rf dist"
25
+ },
26
+ "devDependencies": {
27
+ "tsup": "^8.5.1",
28
+ "typescript": "^5.9.3"
29
+ },
30
+ "dependencies": {
31
+ "@canton-network/core-rpc-transport": "^0.5.0",
32
+ "@canton-network/core-splice-provider": "^0.25.0",
33
+ "@canton-network/core-types": "^0.19.0",
34
+ "@canton-network/core-wallet-dapp-remote-rpc-client": "^0.18.0",
35
+ "@canton-network/core-wallet-dapp-rpc-client": "^0.24.0"
36
+ },
37
+ "files": [
38
+ "dist/**"
39
+ ],
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "git+https://github.com/hyperledger-labs/splice-wallet-kernel.git",
46
+ "directory": "core/provider-dapp"
47
+ }
48
+ }