@canton-network/core-provider-dapp 1.15.0 → 1.17.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/dist/index.cjs +7 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +6 -12
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
2
|
+
// \0rolldown/runtime.js
|
|
3
3
|
var __create = Object.create;
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -20,7 +20,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
20
20
|
value: mod,
|
|
21
21
|
enumerable: true
|
|
22
22
|
}) : target, mod));
|
|
23
|
-
//#endregion
|
|
24
23
|
let _canton_network_core_wallet_dapp_rpc_client = require("@canton-network/core-wallet-dapp-rpc-client");
|
|
25
24
|
_canton_network_core_wallet_dapp_rpc_client = __toESM(_canton_network_core_wallet_dapp_rpc_client, 1);
|
|
26
25
|
let _canton_network_core_splice_provider = require("@canton-network/core-splice-provider");
|
|
@@ -28,7 +27,7 @@ let _canton_network_core_rpc_transport = require("@canton-network/core-rpc-trans
|
|
|
28
27
|
let _canton_network_core_wallet_dapp_remote_rpc_client = require("@canton-network/core-wallet-dapp-remote-rpc-client");
|
|
29
28
|
_canton_network_core_wallet_dapp_remote_rpc_client = __toESM(_canton_network_core_wallet_dapp_remote_rpc_client, 1);
|
|
30
29
|
let _canton_network_core_types = require("@canton-network/core-types");
|
|
31
|
-
|
|
30
|
+
// \0@oxc-project+runtime@0.156.0/helpers/esm/typeof.js
|
|
32
31
|
function _typeof(o) {
|
|
33
32
|
"@babel/helpers - typeof";
|
|
34
33
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -37,8 +36,7 @@ function _typeof(o) {
|
|
|
37
36
|
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
38
37
|
}, _typeof(o);
|
|
39
38
|
}
|
|
40
|
-
|
|
41
|
-
//#region \0@oxc-project+runtime@0.154.0/helpers/esm/toPrimitive.js
|
|
39
|
+
// \0@oxc-project+runtime@0.156.0/helpers/esm/toPrimitive.js
|
|
42
40
|
function toPrimitive(t, r) {
|
|
43
41
|
if ("object" != _typeof(t) || !t) return t;
|
|
44
42
|
var e = t[Symbol.toPrimitive];
|
|
@@ -49,14 +47,12 @@ function toPrimitive(t, r) {
|
|
|
49
47
|
}
|
|
50
48
|
return ("string" === r ? String : Number)(t);
|
|
51
49
|
}
|
|
52
|
-
|
|
53
|
-
//#region \0@oxc-project+runtime@0.154.0/helpers/esm/toPropertyKey.js
|
|
50
|
+
// \0@oxc-project+runtime@0.156.0/helpers/esm/toPropertyKey.js
|
|
54
51
|
function toPropertyKey(t) {
|
|
55
52
|
var i = toPrimitive(t, "string");
|
|
56
53
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
57
54
|
}
|
|
58
|
-
|
|
59
|
-
//#region \0@oxc-project+runtime@0.154.0/helpers/esm/defineProperty.js
|
|
55
|
+
// \0@oxc-project+runtime@0.156.0/helpers/esm/defineProperty.js
|
|
60
56
|
function _defineProperty(e, r, t) {
|
|
61
57
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
62
58
|
value: t,
|
|
@@ -65,8 +61,7 @@ function _defineProperty(e, r, t) {
|
|
|
65
61
|
writable: !0
|
|
66
62
|
}) : e[r] = t, e;
|
|
67
63
|
}
|
|
68
|
-
|
|
69
|
-
//#region src/DappSyncProvider.ts
|
|
64
|
+
// src/DappSyncProvider.ts
|
|
70
65
|
var DappSyncProvider = class extends _canton_network_core_splice_provider.AbstractProvider {
|
|
71
66
|
constructor(transport) {
|
|
72
67
|
super();
|
|
@@ -81,8 +76,7 @@ var DappSyncProvider = class extends _canton_network_core_splice_provider.Abstra
|
|
|
81
76
|
return await this.client.request(args);
|
|
82
77
|
}
|
|
83
78
|
};
|
|
84
|
-
|
|
85
|
-
//#region src/DappAsyncProvider.ts
|
|
79
|
+
// src/DappAsyncProvider.ts
|
|
86
80
|
let connection = null;
|
|
87
81
|
function parseSSEData(data) {
|
|
88
82
|
try {
|
|
@@ -170,7 +164,6 @@ var DappAsyncProvider = class extends _canton_network_core_splice_provider.Abstr
|
|
|
170
164
|
return await this.client.request(args);
|
|
171
165
|
}
|
|
172
166
|
};
|
|
173
|
-
//#endregion
|
|
174
167
|
exports.DappAsyncProvider = DappAsyncProvider;
|
|
175
168
|
exports.DappSyncProvider = DappSyncProvider;
|
|
176
169
|
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["AbstractProvider","WindowTransport","SpliceWalletJSONRPCDAppAPI","AbstractProvider","HttpTransport","SpliceWalletJSONRPCRemoteDAppAPI","isSpliceMessageEvent","WalletEvent"],"sources":["../src/DappSyncProvider.ts","../src/DappAsyncProvider.ts"],"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 type RpcTypes as DappRpcTypes,\n} from '@canton-network/core-wallet-dapp-rpc-client'\nimport { AbstractProvider } from '@canton-network/core-splice-provider'\nimport type { RequestArgs } from '@canton-network/core-types'\nimport {\n type 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 const rpcTransport = transport ?? new WindowTransport(window)\n this.client = new SpliceWalletJSONRPCDAppAPI(rpcTransport)\n // CIP-103 events (txChanged, accountsChanged, statusChanged,\n // connected) arrive as wallet-pushed notifications on the window\n // transport; bridge them into the AbstractProvider listener map so\n // provider.on(event, listener) delivers them as the CIP requires.\n if (rpcTransport instanceof WindowTransport) {\n rpcTransport.onNotification((method, params) => {\n this.emit(method, params)\n })\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 type RpcTypes as DappAsyncRpcTypes,\n type 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 type 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 listeners: Set<(event: string, args: unknown[]) => void>\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 url: URL\n private client: SpliceWalletJSONRPCRemoteDAppAPI\n private status?: Session | undefined\n private readonly sseForwarder = (event: string, args: unknown[]) => {\n this.emit(event, ...args)\n }\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 const dispatchToProviders =\n (eventName: string) => (event: MessageEvent) => {\n const args = parseSSEData(event.data)\n connection?.listeners.forEach((listener) => {\n listener(eventName, args)\n })\n }\n\n eventSource.onmessage = dispatchToProviders('message')\n\n eventSource.addEventListener(\n 'accountsChanged',\n dispatchToProviders('accountsChanged')\n )\n eventSource.addEventListener(\n 'statusChanged',\n dispatchToProviders('statusChanged')\n )\n eventSource.addEventListener(\n 'connected',\n dispatchToProviders('connected')\n )\n eventSource.addEventListener(\n 'txChanged',\n dispatchToProviders('txChanged')\n )\n eventSource.addEventListener(\n 'messageSignature',\n dispatchToProviders('messageSignature')\n )\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 listeners: new Set(),\n }\n }\n\n connection.listeners.add(this.sseForwarder)\n }\n\n constructor(url: URL | string, sessionToken?: string) {\n super()\n this.url = typeof url === 'string' ? new URL(url) : url\n\n if (sessionToken) {\n this.sessionToken = sessionToken\n this.openSSE(this.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 // TODO this is not ideal as it's possible for same object to have different keys order after stringify\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,IAAa,mBAAb,cAAsCA,qCAAAA,iBAA+B;CAGjE,YAAY,WAA0B;EAClC,MAAM;EAHF,gBAAA,MAAA,UAAA,KAAA,CAAA;EAIJ,MAAM,eAAe,aAAa,IAAIC,mCAAAA,gBAAgB,MAAM;EAC5D,KAAK,SAAS,IAAIC,4CAAAA,QAA2B,YAAY;EAKzD,IAAI,wBAAwBD,mCAAAA,iBACxB,aAAa,gBAAgB,QAAQ,WAAW;GAC5C,KAAK,KAAK,QAAQ,MAAM;EAC5B,CAAC;CAET;CAEA,MAAa,QACT,MACkC;EAClC,OAAO,MAAM,KAAK,OAAO,QAAW,IAAI;CAC5C;AACJ;;;ACZA,IAAI,aAAyB;AAE7B,SAAS,aAAa,MAAyB;CAC3C,IAAI;EACA,MAAM,SAAS,KAAK,MAAM,IAAI;EAC9B,OAAO,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,MAAM;CACnD,QAAQ;EACJ,OAAO,CAAC,IAAI;CAChB;AACJ;AAEA,IAAa,oBAAb,cAAuCE,qCAAAA,iBAAoC;CASvE,aACI,cACgC;EAChC,MAAM,YAAY,IAAIC,mCAAAA,cAAc,KAAK,KAAK,YAAY;EAC1D,OAAO,IAAIC,mDAAAA,QAAiC,SAAS;CACzD;CAEA,QAAgB,KAAU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AAQ,WAAW,IAAI,IAAI,GAAG,IAAI;EAEpD,IAAI,cAAc;GACd,KAAK,eAAe;GACpB,KAAK,QAAQ,KAAK,KAAK,YAAY;EACvC;EAEA,KAAK,SAAS,KAAK,aAAa,YAAY;EAG5C,OAAO,iBAAiB,WAAW,OAAO,UAAU;GAChD,IAAI,EAAA,GAACC,2BAAAA,qBAAAA,CAAqB,KAAK,GAAG;GAElC,IACI,MAAM,KAAK,SAASC,2BAAAA,YAAY,gCAClC;IACE,KAAK,eAAe,MAAM,KAAK;IAC/B,KAAK,SAAS,KAAK,aAAa,KAAK,YAAY;IACjD,KAAK,QAAQ,KAAK,KAAK,MAAM,KAAK,KAAK;IAKvC,KAAK,QAAQ,EAAE,QAAQ,SAAS,CAAC,CAAC,CAC7B,MAAM,WAAW;KAEd,IAEI,KAAK,UAAU,OAAO,OAAO,MAC7B,KAAK,UAAU,KAAK,MAAM,GAC5B;MACE,KAAK,KAAK,iBAAiB,MAAM;MACjC,KAAK,SAAS,OAAO;KACzB;IACJ,CAAC,CAAC,CACD,OAAO,QAAQ;KACZ,QAAQ,MACJ,uCACA,GACJ;IACJ,CAAC;GACT;EACJ,CAAC;CACL;CAEA,MAAa,QACT,MACuC;EACvC,OAAO,MAAM,KAAK,OAAO,QAAW,IAAI;CAC5C;AACJ"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["AbstractProvider","WindowTransport","SpliceWalletJSONRPCDAppAPI","AbstractProvider","HttpTransport","SpliceWalletJSONRPCRemoteDAppAPI","isSpliceMessageEvent","WalletEvent"],"sources":["../src/DappSyncProvider.ts","../src/DappAsyncProvider.ts"],"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 type RpcTypes as DappRpcTypes,\n} from '@canton-network/core-wallet-dapp-rpc-client'\nimport { AbstractProvider } from '@canton-network/core-splice-provider'\nimport type { RequestArgs } from '@canton-network/core-types'\nimport {\n type 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 const rpcTransport = transport ?? new WindowTransport(window)\n this.client = new SpliceWalletJSONRPCDAppAPI(rpcTransport)\n // CIP-103 events (txChanged, accountsChanged, statusChanged,\n // connected) arrive as wallet-pushed notifications on the window\n // transport; bridge them into the AbstractProvider listener map so\n // provider.on(event, listener) delivers them as the CIP requires.\n if (rpcTransport instanceof WindowTransport) {\n rpcTransport.onNotification((method, params) => {\n this.emit(method, params)\n })\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 type RpcTypes as DappAsyncRpcTypes,\n type 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 type 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 listeners: Set<(event: string, args: unknown[]) => void>\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 url: URL\n private client: SpliceWalletJSONRPCRemoteDAppAPI\n private status?: Session | undefined\n private readonly sseForwarder = (event: string, args: unknown[]) => {\n this.emit(event, ...args)\n }\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 const dispatchToProviders =\n (eventName: string) => (event: MessageEvent) => {\n const args = parseSSEData(event.data)\n connection?.listeners.forEach((listener) => {\n listener(eventName, args)\n })\n }\n\n eventSource.onmessage = dispatchToProviders('message')\n\n eventSource.addEventListener(\n 'accountsChanged',\n dispatchToProviders('accountsChanged')\n )\n eventSource.addEventListener(\n 'statusChanged',\n dispatchToProviders('statusChanged')\n )\n eventSource.addEventListener(\n 'connected',\n dispatchToProviders('connected')\n )\n eventSource.addEventListener(\n 'txChanged',\n dispatchToProviders('txChanged')\n )\n eventSource.addEventListener(\n 'messageSignature',\n dispatchToProviders('messageSignature')\n )\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 listeners: new Set(),\n }\n }\n\n connection.listeners.add(this.sseForwarder)\n }\n\n constructor(url: URL | string, sessionToken?: string) {\n super()\n this.url = typeof url === 'string' ? new URL(url) : url\n\n if (sessionToken) {\n this.sessionToken = sessionToken\n this.openSSE(this.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 // TODO this is not ideal as it's possible for same object to have different keys order after stringify\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,IAAa,mBAAb,cAAsCA,qCAAAA,iBAA+B;CAGjE,YAAY,WAA0B;EAClC,MAAM;EAHF,gBAAA,MAAA,UAAA,KAAA,CAAA;EAIJ,MAAM,eAAe,aAAa,IAAIC,mCAAAA,gBAAgB,MAAM;EAC5D,KAAK,SAAS,IAAIC,4CAAAA,QAA2B,YAAY;EAKzD,IAAI,wBAAwBD,mCAAAA,iBACxB,aAAa,gBAAgB,QAAQ,WAAW;GAC5C,KAAK,KAAK,QAAQ,MAAM;EAC5B,CAAC;CAET;CAEA,MAAa,QACT,MACkC;EAClC,OAAO,MAAM,KAAK,OAAO,QAAW,IAAI;CAC5C;AACJ;;ACZA,IAAI,aAAyB;AAE7B,SAAS,aAAa,MAAyB;CAC3C,IAAI;EACA,MAAM,SAAS,KAAK,MAAM,IAAI;EAC9B,OAAO,MAAM,QAAQ,M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EAjFF,gBAAA,MAAA,gBAAA,KAAA,CAAA;EACA,gBAAA,MAAA,OAAA,KAAA,CAAA;EACA,gBAAA,MAAA,UAAA,KAAA,CAAA;EACA,gBAAA,MAAA,UAAA,KAAA,CAAA;EACS,gBAAA,MAAA,iBAAgB,OAAe,SAAoB;GAChE,KAAK,KAAK,OAAO,GAAG,IAAI;EAC5B,CAAA;EA4EI,KAAK,MAAM,OAAO,QAAQ,WAAW,IAAI,IAAI,GAAG,IAAI;EAEpD,IAAI,cAAc;GACd,KAAK,eAAe;GACpB,KAAK,QAAQ,KAAK,KAAK,YAAY;EACvC;EAEA,KAAK,SAAS,KAAK,aAAa,YAAY;EAG5C,OAAO,iBAAiB,WAAW,OAAO,UAAU;GAChD,IAAI,EAAA,GAACC,2BAAAA,qBAAAA,CAAqB,KAAK,GAAG;GAElC,IACI,MAAM,KAAK,SAASC,2BAAAA,YAAY,gCAClC;IACE,KAAK,eAAe,MAAM,KAAK;IAC/B,KAAK,SAAS,KAAK,aAAa,KAAK,YAAY;IACjD,KAAK,QAAQ,KAAK,KAAK,MAAM,KAAK,KAAK;IAKvC,KAAK,QAAQ,EAAE,QAAQ,SAAS,CAAC,CAAC,CAC7B,MAAM,WAAW;KAEd,IAEI,KAAK,UAAU,OAAO,OAAO,MAC7B,KAAK,UAAU,KAAK,MAAM,GAC5B;MACE,KAAK,KAAK,iBAAiB,MAAM;MACjC,KAAK,SAAS,OAAO;KACzB;IACJ,CAAC,CAAC,CACD,OAAO,QAAQ;KACZ,QAAQ,MACJ,uCACA,GACJ;IACJ,CAAC;GACT;EACJ,CAAC;CACL;CAEA,MAAa,QACT,MACuC;EACvC,OAAO,MAAM,KAAK,OAAO,QAAW,IAAI;CAC5C;AACJ"}
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { AbstractProvider } from "@canton-network/core-splice-provider";
|
|
|
3
3
|
import { HttpTransport, WindowTransport } from "@canton-network/core-rpc-transport";
|
|
4
4
|
import SpliceWalletJSONRPCRemoteDAppAPI from "@canton-network/core-wallet-dapp-remote-rpc-client";
|
|
5
5
|
import { WalletEvent, isSpliceMessageEvent } from "@canton-network/core-types";
|
|
6
|
-
|
|
6
|
+
// \0@oxc-project+runtime@0.156.0/helpers/esm/typeof.js
|
|
7
7
|
function _typeof(o) {
|
|
8
8
|
"@babel/helpers - typeof";
|
|
9
9
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -12,8 +12,7 @@ function _typeof(o) {
|
|
|
12
12
|
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
13
13
|
}, _typeof(o);
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
//#region \0@oxc-project+runtime@0.154.0/helpers/esm/toPrimitive.js
|
|
15
|
+
// \0@oxc-project+runtime@0.156.0/helpers/esm/toPrimitive.js
|
|
17
16
|
function toPrimitive(t, r) {
|
|
18
17
|
if ("object" != _typeof(t) || !t) return t;
|
|
19
18
|
var e = t[Symbol.toPrimitive];
|
|
@@ -24,14 +23,12 @@ function toPrimitive(t, r) {
|
|
|
24
23
|
}
|
|
25
24
|
return ("string" === r ? String : Number)(t);
|
|
26
25
|
}
|
|
27
|
-
|
|
28
|
-
//#region \0@oxc-project+runtime@0.154.0/helpers/esm/toPropertyKey.js
|
|
26
|
+
// \0@oxc-project+runtime@0.156.0/helpers/esm/toPropertyKey.js
|
|
29
27
|
function toPropertyKey(t) {
|
|
30
28
|
var i = toPrimitive(t, "string");
|
|
31
29
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
32
30
|
}
|
|
33
|
-
|
|
34
|
-
//#region \0@oxc-project+runtime@0.154.0/helpers/esm/defineProperty.js
|
|
31
|
+
// \0@oxc-project+runtime@0.156.0/helpers/esm/defineProperty.js
|
|
35
32
|
function _defineProperty(e, r, t) {
|
|
36
33
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
37
34
|
value: t,
|
|
@@ -40,8 +37,7 @@ function _defineProperty(e, r, t) {
|
|
|
40
37
|
writable: !0
|
|
41
38
|
}) : e[r] = t, e;
|
|
42
39
|
}
|
|
43
|
-
|
|
44
|
-
//#region src/DappSyncProvider.ts
|
|
40
|
+
// src/DappSyncProvider.ts
|
|
45
41
|
var DappSyncProvider = class extends AbstractProvider {
|
|
46
42
|
constructor(transport) {
|
|
47
43
|
super();
|
|
@@ -56,8 +52,7 @@ var DappSyncProvider = class extends AbstractProvider {
|
|
|
56
52
|
return await this.client.request(args);
|
|
57
53
|
}
|
|
58
54
|
};
|
|
59
|
-
|
|
60
|
-
//#region src/DappAsyncProvider.ts
|
|
55
|
+
// src/DappAsyncProvider.ts
|
|
61
56
|
let connection = null;
|
|
62
57
|
function parseSSEData(data) {
|
|
63
58
|
try {
|
|
@@ -145,7 +140,6 @@ var DappAsyncProvider = class extends AbstractProvider {
|
|
|
145
140
|
return await this.client.request(args);
|
|
146
141
|
}
|
|
147
142
|
};
|
|
148
|
-
//#endregion
|
|
149
143
|
export { DappAsyncProvider, DappSyncProvider };
|
|
150
144
|
|
|
151
145
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/DappSyncProvider.ts","../src/DappAsyncProvider.ts"],"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 type RpcTypes as DappRpcTypes,\n} from '@canton-network/core-wallet-dapp-rpc-client'\nimport { AbstractProvider } from '@canton-network/core-splice-provider'\nimport type { RequestArgs } from '@canton-network/core-types'\nimport {\n type 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 const rpcTransport = transport ?? new WindowTransport(window)\n this.client = new SpliceWalletJSONRPCDAppAPI(rpcTransport)\n // CIP-103 events (txChanged, accountsChanged, statusChanged,\n // connected) arrive as wallet-pushed notifications on the window\n // transport; bridge them into the AbstractProvider listener map so\n // provider.on(event, listener) delivers them as the CIP requires.\n if (rpcTransport instanceof WindowTransport) {\n rpcTransport.onNotification((method, params) => {\n this.emit(method, params)\n })\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 type RpcTypes as DappAsyncRpcTypes,\n type 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 type 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 listeners: Set<(event: string, args: unknown[]) => void>\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 url: URL\n private client: SpliceWalletJSONRPCRemoteDAppAPI\n private status?: Session | undefined\n private readonly sseForwarder = (event: string, args: unknown[]) => {\n this.emit(event, ...args)\n }\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 const dispatchToProviders =\n (eventName: string) => (event: MessageEvent) => {\n const args = parseSSEData(event.data)\n connection?.listeners.forEach((listener) => {\n listener(eventName, args)\n })\n }\n\n eventSource.onmessage = dispatchToProviders('message')\n\n eventSource.addEventListener(\n 'accountsChanged',\n dispatchToProviders('accountsChanged')\n )\n eventSource.addEventListener(\n 'statusChanged',\n dispatchToProviders('statusChanged')\n )\n eventSource.addEventListener(\n 'connected',\n dispatchToProviders('connected')\n )\n eventSource.addEventListener(\n 'txChanged',\n dispatchToProviders('txChanged')\n )\n eventSource.addEventListener(\n 'messageSignature',\n dispatchToProviders('messageSignature')\n )\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 listeners: new Set(),\n }\n }\n\n connection.listeners.add(this.sseForwarder)\n }\n\n constructor(url: URL | string, sessionToken?: string) {\n super()\n this.url = typeof url === 'string' ? new URL(url) : url\n\n if (sessionToken) {\n this.sessionToken = sessionToken\n this.openSSE(this.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 // TODO this is not ideal as it's possible for same object to have different keys order after stringify\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,IAAa,mBAAb,cAAsC,iBAA+B;CAGjE,YAAY,WAA0B;EAClC,MAAM;EAHF,gBAAA,MAAA,UAAA,KAAA,CAAA;EAIJ,MAAM,eAAe,aAAa,IAAI,gBAAgB,MAAM;EAC5D,KAAK,SAAS,IAAI,2BAA2B,YAAY;EAKzD,IAAI,wBAAwB,iBACxB,aAAa,gBAAgB,QAAQ,WAAW;GAC5C,KAAK,KAAK,QAAQ,MAAM;EAC5B,CAAC;CAET;CAEA,MAAa,QACT,MACkC;EAClC,OAAO,MAAM,KAAK,OAAO,QAAW,IAAI;CAC5C;AACJ;;;ACZA,IAAI,aAAyB;AAE7B,SAAS,aAAa,MAAyB;CAC3C,IAAI;EACA,MAAM,SAAS,KAAK,MAAM,IAAI;EAC9B,OAAO,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,MAAM;CACnD,QAAQ;EACJ,OAAO,CAAC,IAAI;CAChB;AACJ;AAEA,IAAa,oBAAb,cAAuC,iBAAoC;CASvE,aACI,cACgC;EAChC,MAAM,YAAY,IAAI,cAAc,KAAK,KAAK,YAAY;EAC1D,OAAO,IAAI,iCAAiC,SAAS;CACzD;CAEA,QAAgB,K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O,QAAQ,WAAW,IAAI,IAAI,GAAG,IAAI;EAEpD,IAAI,cAAc;GACd,KAAK,eAAe;GACpB,KAAK,QAAQ,KAAK,KAAK,YAAY;EACvC;EAEA,KAAK,SAAS,KAAK,aAAa,YAAY;EAG5C,OAAO,iBAAiB,WAAW,OAAO,UAAU;GAChD,IAAI,CAAC,qBAAqB,KAAK,GAAG;GAElC,IACI,MAAM,KAAK,SAAS,YAAY,gCAClC;IACE,KAAK,eAAe,MAAM,KAAK;IAC/B,KAAK,SAAS,KAAK,aAAa,KAAK,YAAY;IACjD,KAAK,QAAQ,KAAK,KAAK,MAAM,KAAK,KAAK;IAKvC,KAAK,QAAQ,EAAE,QAAQ,SAAS,CAAC,CAAC,CAC7B,MAAM,WAAW;KAEd,IAEI,KAAK,UAAU,OAAO,OAAO,MAC7B,KAAK,UAAU,KAAK,MAAM,GAC5B;MACE,KAAK,KAAK,iBAAiB,MAAM;MACjC,KAAK,SAAS,OAAO;KACzB;IACJ,CAAC,CAAC,CACD,OAAO,QAAQ;KACZ,QAAQ,MACJ,uCACA,GACJ;IACJ,CAAC;GACT;EACJ,CAAC;CACL;CAEA,MAAa,QACT,MACuC;EACvC,OAAO,MAAM,KAAK,OAAO,QAAW,IAAI;CAC5C;AACJ"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/DappSyncProvider.ts","../src/DappAsyncProvider.ts"],"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 type RpcTypes as DappRpcTypes,\n} from '@canton-network/core-wallet-dapp-rpc-client'\nimport { AbstractProvider } from '@canton-network/core-splice-provider'\nimport type { RequestArgs } from '@canton-network/core-types'\nimport {\n type 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 const rpcTransport = transport ?? new WindowTransport(window)\n this.client = new SpliceWalletJSONRPCDAppAPI(rpcTransport)\n // CIP-103 events (txChanged, accountsChanged, statusChanged,\n // connected) arrive as wallet-pushed notifications on the window\n // transport; bridge them into the AbstractProvider listener map so\n // provider.on(event, listener) delivers them as the CIP requires.\n if (rpcTransport instanceof WindowTransport) {\n rpcTransport.onNotification((method, params) => {\n this.emit(method, params)\n })\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 type RpcTypes as DappAsyncRpcTypes,\n type 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 type 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 listeners: Set<(event: string, args: unknown[]) => void>\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 url: URL\n private client: SpliceWalletJSONRPCRemoteDAppAPI\n private status?: Session | undefined\n private readonly sseForwarder = (event: string, args: unknown[]) => {\n this.emit(event, ...args)\n }\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 const dispatchToProviders =\n (eventName: string) => (event: MessageEvent) => {\n const args = parseSSEData(event.data)\n connection?.listeners.forEach((listener) => {\n listener(eventName, args)\n })\n }\n\n eventSource.onmessage = dispatchToProviders('message')\n\n eventSource.addEventListener(\n 'accountsChanged',\n dispatchToProviders('accountsChanged')\n )\n eventSource.addEventListener(\n 'statusChanged',\n dispatchToProviders('statusChanged')\n )\n eventSource.addEventListener(\n 'connected',\n dispatchToProviders('connected')\n )\n eventSource.addEventListener(\n 'txChanged',\n dispatchToProviders('txChanged')\n )\n eventSource.addEventListener(\n 'messageSignature',\n dispatchToProviders('messageSignature')\n )\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 listeners: new Set(),\n }\n }\n\n connection.listeners.add(this.sseForwarder)\n }\n\n constructor(url: URL | string, sessionToken?: string) {\n super()\n this.url = typeof url === 'string' ? new URL(url) : url\n\n if (sessionToken) {\n this.sessionToken = sessionToken\n this.openSSE(this.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 // TODO this is not ideal as it's possible for same object to have different keys order after stringify\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,IAAa,mBAAb,cAAsC,iBAA+B;CAGjE,YAAY,WAA0B;EAClC,MAAM;EAHF,gBAAA,MAAA,UAAA,KAAA,CAAA;EAIJ,MAAM,eAAe,aAAa,IAAI,gBAAgB,MAAM;EAC5D,KAAK,SAAS,IAAI,2BAA2B,YAAY;EAKzD,IAAI,wBAAwB,iBACxB,aAAa,gBAAgB,QAAQ,WAAW;GAC5C,KAAK,KAAK,QAAQ,MAAM;EAC5B,CAAC;CAET;CAEA,MAAa,QACT,MACkC;EAClC,OAAO,MAAM,KAAK,OAAO,QAAW,IAAI;CAC5C;AACJ;;ACZA,IAAI,aAAyB;AAE7B,SAAS,aAAa,MAAyB;CAC3C,IAAI;EACA,MAAM,SAAS,KAAK,MAAM,IAAI;EAC9B,OAAO,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,MAAM;CACnD,QAAQ;EACJ,OAAO,CAAC,IAAI;CAChB;AACJ;AAEA,IAAa,oBAAb,cAAuC,iBAAoC;CASvE,aACI,cACgC;EAChC,MAAM,YAAY,IAAI,cAAc,KAAK,KAAK,YAAY;EAC1D,OAAO,IAAI,iCAAiC,S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A;EA4EI,KAAK,MAAM,OAAO,QAAQ,WAAW,IAAI,IAAI,GAAG,IAAI;EAEpD,IAAI,cAAc;GACd,KAAK,eAAe;GACpB,KAAK,QAAQ,KAAK,KAAK,YAAY;EACvC;EAEA,KAAK,SAAS,KAAK,aAAa,YAAY;EAG5C,OAAO,iBAAiB,WAAW,OAAO,UAAU;GAChD,IAAI,CAAC,qBAAqB,KAAK,GAAG;GAElC,IACI,MAAM,KAAK,SAAS,YAAY,gCAClC;IACE,KAAK,eAAe,MAAM,KAAK;IAC/B,KAAK,SAAS,KAAK,aAAa,KAAK,YAAY;IACjD,KAAK,QAAQ,KAAK,KAAK,MAAM,KAAK,KAAK;IAKvC,KAAK,QAAQ,EAAE,QAAQ,SAAS,CAAC,CAAC,CAC7B,MAAM,WAAW;KAEd,IAEI,KAAK,UAAU,OAAO,OAAO,MAC7B,KAAK,UAAU,KAAK,MAAM,GAC5B;MACE,KAAK,KAAK,iBAAiB,MAAM;MACjC,KAAK,SAAS,OAAO;KACzB;IACJ,CAAC,CAAC,CACD,OAAO,QAAQ;KACZ,QAAQ,MACJ,uCACA,GACJ;IACJ,CAAC;GACT;EACJ,CAAC;CACL;CAEA,MAAa,QACT,MACuC;EACvC,OAAO,MAAM,KAAK,OAAO,QAAW,IAAI;CAC5C;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canton-network/core-provider-dapp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "CIP-0103 provider for web dApps, covering both Sync and Async APIs.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -21,17 +21,17 @@
|
|
|
21
21
|
"@vitest/browser-playwright": "^5.0.5",
|
|
22
22
|
"@vitest/coverage-v8": "^5.0.5",
|
|
23
23
|
"playwright": "^1.64.1",
|
|
24
|
-
"tsdown": "^0.23.
|
|
24
|
+
"tsdown": "^0.23.4",
|
|
25
25
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
26
26
|
"vitest": "^5.0.5"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@canton-network/core-ledger-client-types": "2.
|
|
30
|
-
"@canton-network/core-rpc-transport": "1.
|
|
31
|
-
"@canton-network/core-splice-provider": "1.
|
|
32
|
-
"@canton-network/core-types": "2.
|
|
33
|
-
"@canton-network/core-wallet-dapp-remote-rpc-client": "1.
|
|
34
|
-
"@canton-network/core-wallet-dapp-rpc-client": "1.
|
|
29
|
+
"@canton-network/core-ledger-client-types": "2.3.0",
|
|
30
|
+
"@canton-network/core-rpc-transport": "1.17.0",
|
|
31
|
+
"@canton-network/core-splice-provider": "1.17.0",
|
|
32
|
+
"@canton-network/core-types": "2.3.0",
|
|
33
|
+
"@canton-network/core-wallet-dapp-remote-rpc-client": "1.17.0",
|
|
34
|
+
"@canton-network/core-wallet-dapp-rpc-client": "1.17.0"
|
|
35
35
|
},
|
|
36
36
|
"files": [
|
|
37
37
|
"dist/**"
|