@canton-network/core-splice-provider 1.8.0 → 1.10.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 +291 -1
- package/dist/index.cjs +66 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +65 -34
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -1 +1,291 @@
|
|
|
1
|
-
# splice-provider
|
|
1
|
+
# @canton-network/core-splice-provider
|
|
2
|
+
|
|
3
|
+
Shared **Provider** abstraction for talking to a Canton ledger — either directly (JSON Ledger
|
|
4
|
+
API) or through a wallet / dApp API.
|
|
5
|
+
|
|
6
|
+
Consumers never call the ledger or a specific transport themselves. They use one interface:
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import {
|
|
10
|
+
AbstractProvider,
|
|
11
|
+
Provider,
|
|
12
|
+
} from '@canton-network/core-splice-provider'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The shape follows [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) (`request` + events)
|
|
16
|
+
without Ethereum method semantics. Concrete APIs are defined elsewhere — for example
|
|
17
|
+
[CIP-103](https://github.com/canton-foundation/cips/blob/main/cip-0103/cip-0103.md) for dApps
|
|
18
|
+
and the Canton JSON Ledger API for direct access.
|
|
19
|
+
|
|
20
|
+
Published on [npm](https://www.npmjs.com/package/@canton-network/core-splice-provider) under
|
|
21
|
+
Apache-2.0.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @canton-network/core-splice-provider
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Goals
|
|
30
|
+
|
|
31
|
+
- **One interface** for direct ledger access and wallet-mediated access
|
|
32
|
+
- **Transport agnostic** — HTTP, `postMessage`, SSE, in-process, or anything else
|
|
33
|
+
- **Auth agnostic** — implementations choose how credentials are obtained
|
|
34
|
+
- **Request + events** — `request` for RPC-style calls; `on` / `removeListener` / `emit` for streams
|
|
35
|
+
- **Typed methods** — params and results inferred from the method name
|
|
36
|
+
- **Small surface** — easy to reimplement in other languages; transport-specific providers can be published separately
|
|
37
|
+
|
|
38
|
+
What this package does **not** define: which LAPI or dApp methods exist, how authentication
|
|
39
|
+
works, or wallet / UI behaviour. Those belong to specs, codegen, and concrete providers.
|
|
40
|
+
|
|
41
|
+
```mermaid
|
|
42
|
+
flowchart TB
|
|
43
|
+
subgraph consumers [Consumers]
|
|
44
|
+
DappSDK["dApp SDK"]
|
|
45
|
+
WalletSDK["Wallet SDK"]
|
|
46
|
+
Custom["Custom app / tooling"]
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
Provider["Provider / AbstractProvider<br/><i>request · on · emit · removeListener</i>"]
|
|
50
|
+
|
|
51
|
+
subgraph impls [Implementations]
|
|
52
|
+
LedgerP["LedgerProvider"]
|
|
53
|
+
SyncP["DappSyncProvider"]
|
|
54
|
+
AsyncP["DappAsyncProvider"]
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
subgraph transports [Transports]
|
|
58
|
+
HTTP["HTTP"]
|
|
59
|
+
PM["postMessage"]
|
|
60
|
+
SSE["HTTPS + SSE"]
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
subgraph backends [Backends]
|
|
64
|
+
LAPI["JSON Ledger API"]
|
|
65
|
+
LocalW["Extension / desktop wallet"]
|
|
66
|
+
RemoteW["Remote wallet gateway"]
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
DappSDK --> Provider
|
|
70
|
+
WalletSDK --> Provider
|
|
71
|
+
Custom --> Provider
|
|
72
|
+
|
|
73
|
+
Provider --> LedgerP
|
|
74
|
+
Provider --> SyncP
|
|
75
|
+
Provider --> AsyncP
|
|
76
|
+
|
|
77
|
+
LedgerP --> HTTP --> LAPI
|
|
78
|
+
SyncP --> PM --> LocalW
|
|
79
|
+
AsyncP --> SSE --> RemoteW
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Provider interface
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
import { RequestArgs, UnknownRpcTypes } from '@canton-network/core-types'
|
|
86
|
+
|
|
87
|
+
export type EventListener<T> = (...args: T[]) => void
|
|
88
|
+
|
|
89
|
+
export interface Provider<T extends UnknownRpcTypes> {
|
|
90
|
+
request<M extends keyof T>(args: RequestArgs<T, M>): Promise<T[M]['result']>
|
|
91
|
+
|
|
92
|
+
on<E>(event: string, listener: EventListener<E>): Provider<T>
|
|
93
|
+
emit<E>(event: string, ...args: E[]): boolean
|
|
94
|
+
removeListener<E>(
|
|
95
|
+
event: string,
|
|
96
|
+
listenerToRemove: EventListener<E>
|
|
97
|
+
): Provider<T>
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The interface does not assume which methods are supported, how authentication works, or
|
|
102
|
+
whether calls go through a wallet — only a typed `request` and an event bus.
|
|
103
|
+
|
|
104
|
+
### `AbstractProvider`
|
|
105
|
+
|
|
106
|
+
Implements the event map (`on` / `emit` / `removeListener`) and leaves `request` abstract:
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
export abstract class AbstractProvider<
|
|
110
|
+
T extends UnknownRpcTypes,
|
|
111
|
+
> implements Provider<T> {
|
|
112
|
+
abstract request<M extends keyof T>(
|
|
113
|
+
args: RequestArgs<T, M>
|
|
114
|
+
): Promise<T[M]['result']>
|
|
115
|
+
|
|
116
|
+
// on / emit / removeListener provided
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Subclasses wire `request` to their transport (HTTP JSON LAPI, window `postMessage`, HTTPS +
|
|
121
|
+
SSE, and so on).
|
|
122
|
+
|
|
123
|
+
## Typing model
|
|
124
|
+
|
|
125
|
+
Every call is keyed by a method name `M`. Params come from `C[M]['params']` and the result
|
|
126
|
+
from `C[M]['result']`. Helpers live in [`@canton-network/core-types`](../types):
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
type UnknownRpcTypes = {
|
|
130
|
+
[method: string]: {
|
|
131
|
+
params: unknown
|
|
132
|
+
result: unknown
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
type RequestArgs<
|
|
137
|
+
T extends UnknownRpcTypes,
|
|
138
|
+
M extends keyof T,
|
|
139
|
+
> = T[M]['params'] extends never
|
|
140
|
+
? { method: M }
|
|
141
|
+
: { method: M; params: T[M]['params'] }
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Specs usually come from **OpenRPC** (JSON-RPC style) or **OpenAPI** (Ledger API). Codegen
|
|
145
|
+
produces TypeScript models; providers map them into this `params` / `result` shape.
|
|
146
|
+
|
|
147
|
+
### OpenRPC (dApp API)
|
|
148
|
+
|
|
149
|
+
Map each method to params and result. Use `params: never` when a method takes no arguments:
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
type DappClient = {
|
|
153
|
+
prepareExecute: {
|
|
154
|
+
params: PrepareExecuteParams
|
|
155
|
+
result: PrepareExecuteResult
|
|
156
|
+
}
|
|
157
|
+
status: {
|
|
158
|
+
params: never
|
|
159
|
+
result: StatusResult
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
class DappProvider implements Provider<DappClient> {
|
|
164
|
+
async request<M extends keyof DappClient>(
|
|
165
|
+
args: RequestArgs<DappClient, M>
|
|
166
|
+
): Promise<DappClient[M]['result']> {
|
|
167
|
+
// dispatch via transport…
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
await provider.request({ method: 'status' })
|
|
172
|
+
await provider.request({
|
|
173
|
+
method: 'prepareExecute',
|
|
174
|
+
params: {/* PrepareExecuteParams */},
|
|
175
|
+
})
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### OpenAPI (Ledger API)
|
|
179
|
+
|
|
180
|
+
Ledger access is exposed as one RPC-style method, `ledgerApi`, whose params encode the HTTP
|
|
181
|
+
operation (`resource`, `requestMethod`, optional `body` / `path` / `query`).
|
|
182
|
+
|
|
183
|
+
For per-operation type safety, each Ledger API operation is a distinct member of a union.
|
|
184
|
+
TypeScript narrows params and results from `resource` + `requestMethod` (you can also pass an
|
|
185
|
+
explicit operation type argument):
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
type LedgerClient =
|
|
189
|
+
| {
|
|
190
|
+
ledgerApi: {
|
|
191
|
+
params: {
|
|
192
|
+
resource: '/v2/parties'
|
|
193
|
+
requestMethod: 'get'
|
|
194
|
+
query: { /* … */ }
|
|
195
|
+
}
|
|
196
|
+
result: ListKnownPartiesResponse
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
| {
|
|
200
|
+
ledgerApi: {
|
|
201
|
+
params: {
|
|
202
|
+
resource: '/v2/parties'
|
|
203
|
+
requestMethod: 'post'
|
|
204
|
+
body: AllocatePartyRequest
|
|
205
|
+
}
|
|
206
|
+
result: AllocatePartyResponse
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
| /* … */
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
Stock OpenAPI codegen does not emit this shape; a dedicated generator produces the
|
|
213
|
+
provider-oriented operation types used by
|
|
214
|
+
[`@canton-network/core-provider-ledger`](../provider-ledger).
|
|
215
|
+
|
|
216
|
+
## Implementations
|
|
217
|
+
|
|
218
|
+
| Package | Class | Access model | Typical transport |
|
|
219
|
+
| ------------------------------------------------------------ | ------------------- | ---------------------------------- | ----------------------------- |
|
|
220
|
+
| [`@canton-network/core-provider-ledger`](../provider-ledger) | `LedgerProvider` | Direct JSON LAPI | HTTP |
|
|
221
|
+
| [`@canton-network/core-provider-dapp`](../provider-dapp) | `DappSyncProvider` | CIP-103 Sync (extension / desktop) | `postMessage` / window bridge |
|
|
222
|
+
| [`@canton-network/core-provider-dapp`](../provider-dapp) | `DappAsyncProvider` | CIP-103 Async (remote / custody) | HTTPS + SSE |
|
|
223
|
+
|
|
224
|
+
Higher-level SDKs (`@canton-network/dapp-sdk`, `@canton-network/wallet-sdk`) sit on these
|
|
225
|
+
providers so app code keeps the same interface for local and remote wallets.
|
|
226
|
+
|
|
227
|
+
### Minimal custom provider
|
|
228
|
+
|
|
229
|
+
```ts
|
|
230
|
+
import { AbstractProvider } from '@canton-network/core-splice-provider'
|
|
231
|
+
import { RequestArgs } from '@canton-network/core-types'
|
|
232
|
+
|
|
233
|
+
type MyRpc = {
|
|
234
|
+
ping: { params: { message: string }; result: string }
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
class MyProvider extends AbstractProvider<MyRpc> {
|
|
238
|
+
async request<M extends keyof MyRpc>(
|
|
239
|
+
args: RequestArgs<MyRpc, M>
|
|
240
|
+
): Promise<MyRpc[M]['result']> {
|
|
241
|
+
if (args.method === 'ping') {
|
|
242
|
+
return `pong:${args.params.message}` as MyRpc[M]['result']
|
|
243
|
+
}
|
|
244
|
+
throw new Error('Unsupported method')
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const provider = new MyProvider()
|
|
249
|
+
provider.on('ready', () => console.log('ready'))
|
|
250
|
+
await provider.request({ method: 'ping', params: { message: 'hi' } })
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
## Events
|
|
254
|
+
|
|
255
|
+
`AbstractProvider` maintains an in-memory listener map:
|
|
256
|
+
|
|
257
|
+
- `on(event, listener)` — register
|
|
258
|
+
- `removeListener(event, listener)` — unregister
|
|
259
|
+
- `emit(event, …args)` — notify; returns `false` if nobody is listening
|
|
260
|
+
|
|
261
|
+
Event names and payloads come from the concrete API (for example CIP-103 `statusChanged`,
|
|
262
|
+
`accountsChanged`, `txChanged`, plus Async-only `connected` and `messageSignature`). This
|
|
263
|
+
package only provides the subscription machinery.
|
|
264
|
+
|
|
265
|
+
## Errors
|
|
266
|
+
|
|
267
|
+
Implementations should expose a consistent error shape (code + message) regardless of
|
|
268
|
+
transport, normalizing underlying JSON Ledger API / JSON-RPC failures where needed. dApp
|
|
269
|
+
providers typically follow EIP-1193 / EIP-1474-style codes; see the
|
|
270
|
+
[dApp SDK errors reference](../../docs/dapp-sdk/reference/errors.md).
|
|
271
|
+
|
|
272
|
+
## Exports
|
|
273
|
+
|
|
274
|
+
| Export | Description |
|
|
275
|
+
| --------------------- | ------------------------------------------- |
|
|
276
|
+
| `Provider<T>` | Typed provider interface |
|
|
277
|
+
| `AbstractProvider<T>` | Base class with events; implement `request` |
|
|
278
|
+
| `EventListener<T>` | Listener callback type |
|
|
279
|
+
|
|
280
|
+
RPC map helpers (`UnknownRpcTypes`, `RequestArgs`) are in `@canton-network/core-types`.
|
|
281
|
+
|
|
282
|
+
## Related packages
|
|
283
|
+
|
|
284
|
+
| Package | Role |
|
|
285
|
+
| ------------------------------------------------------------ | ------------------------------ |
|
|
286
|
+
| [`@canton-network/core-types`](../types) | Shared RPC typing helpers |
|
|
287
|
+
| [`@canton-network/core-provider-ledger`](../provider-ledger) | Direct ledger provider |
|
|
288
|
+
| [`@canton-network/core-provider-dapp`](../provider-dapp) | Sync / Async dApp providers |
|
|
289
|
+
| [`@canton-network/core-rpc-transport`](../rpc-transport) | Transports used by RPC clients |
|
|
290
|
+
| [`@canton-network/dapp-sdk`](../../sdk/dapp-sdk) | High-level dApp SDK |
|
|
291
|
+
| [`@canton-network/wallet-sdk`](../../sdk/wallet-sdk) | Wallet SDK |
|
package/dist/index.cjs
CHANGED
|
@@ -1,40 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0@oxc-project+runtime@0.142.0/helpers/esm/typeof.js
|
|
3
|
+
function _typeof(o) {
|
|
4
|
+
"@babel/helpers - typeof";
|
|
5
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
6
|
+
return typeof o;
|
|
7
|
+
} : function(o) {
|
|
8
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
9
|
+
}, _typeof(o);
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region \0@oxc-project+runtime@0.142.0/helpers/esm/toPrimitive.js
|
|
13
|
+
function toPrimitive(t, r) {
|
|
14
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
15
|
+
var e = t[Symbol.toPrimitive];
|
|
16
|
+
if (void 0 !== e) {
|
|
17
|
+
var i = e.call(t, r || "default");
|
|
18
|
+
if ("object" != _typeof(i)) return i;
|
|
19
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
20
|
+
}
|
|
21
|
+
return ("string" === r ? String : Number)(t);
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region \0@oxc-project+runtime@0.142.0/helpers/esm/toPropertyKey.js
|
|
25
|
+
function toPropertyKey(t) {
|
|
26
|
+
var i = toPrimitive(t, "string");
|
|
27
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region \0@oxc-project+runtime@0.142.0/helpers/esm/defineProperty.js
|
|
31
|
+
function _defineProperty(e, r, t) {
|
|
32
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
33
|
+
value: t,
|
|
34
|
+
enumerable: !0,
|
|
35
|
+
configurable: !0,
|
|
36
|
+
writable: !0
|
|
37
|
+
}) : e[r] = t, e;
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/index.ts
|
|
41
|
+
/**
|
|
42
|
+
* An abstract base class for Providers that implements the event handling logic. It maintains a mapping of event names to arrays of listeners and provides methods to register, emit, and remove listeners. The request method is left abstract for subclasses to implement according to their specific RPC transport mechanism.
|
|
43
|
+
*/
|
|
8
44
|
var AbstractProvider = class {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (!this.listeners[event]) return this;
|
|
31
|
-
this.listeners[event] = this.listeners[event].filter(
|
|
32
|
-
(listener) => listener !== listenerToRemove
|
|
33
|
-
);
|
|
34
|
-
return this;
|
|
35
|
-
}
|
|
45
|
+
constructor() {
|
|
46
|
+
_defineProperty(this, "listeners", void 0);
|
|
47
|
+
this.listeners = {};
|
|
48
|
+
}
|
|
49
|
+
on(event, listener) {
|
|
50
|
+
if (!this.listeners[event]) this.listeners[event] = [];
|
|
51
|
+
this.listeners[event].push(listener);
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
emit(event, ...args) {
|
|
55
|
+
if (this.listeners[event]) {
|
|
56
|
+
this.listeners[event].forEach((listener) => listener(...args));
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
removeListener(event, listenerToRemove) {
|
|
62
|
+
if (!this.listeners[event]) return this;
|
|
63
|
+
this.listeners[event] = this.listeners[event].filter((listener) => listener !== listenerToRemove);
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
36
66
|
};
|
|
37
|
-
|
|
67
|
+
//#endregion
|
|
38
68
|
exports.AbstractProvider = AbstractProvider;
|
|
39
|
-
|
|
69
|
+
|
|
40
70
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../src/index.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 { RequestArgs, UnknownRpcTypes } from '@canton-network/core-types'\n\nexport type EventListener<T> = (...args: T[]) => void\n\n/**\n * The Provider interface is generic over a type `T` that defines a mapping between supported methods\n * and their corresponding request and response types. The request method takes an argument of type RequestArgs<T, M>,\n * where `M` is a key of `T` representing the method being called.\n *\n * The type of the params body for a method `M` is derived from T[M]['params']\n * The type of the result of calling a method `M` is derived from T[M]['result']\n */\nexport interface Provider<T extends UnknownRpcTypes> {\n request<M extends keyof T>(args: RequestArgs<T, M>): Promise<T[M]['result']>\n\n on<E>(event: string, listener: EventListener<E>): Provider<T>\n emit<E>(event: string, ...args: E[]): boolean\n removeListener<E>(\n event: string,\n listenerToRemove: EventListener<E>\n ): Provider<T>\n}\n\n/**\n * An abstract base class for Providers that implements the event handling logic. It maintains a mapping of event names to arrays of listeners and provides methods to register, emit, and remove listeners. The request method is left abstract for subclasses to implement according to their specific RPC transport mechanism.\n */\nexport abstract class AbstractProvider<\n T extends UnknownRpcTypes,\n> implements Provider<T> {\n listeners: { [event: string]: EventListener<unknown>[] }\n\n constructor() {\n this.listeners = {} // Event listeners\n }\n\n abstract request<M extends keyof T>(\n args: RequestArgs<T, M>\n ): Promise<T[M]['result']>\n\n // Event handling\n public on<E>(event: string, listener: EventListener<E>): Provider<T> {\n if (!this.listeners[event]) {\n this.listeners[event] = []\n }\n const listeners = this.listeners[event] as EventListener<E>[]\n listeners.push(listener)\n\n return this\n }\n\n public emit<E>(event: string, ...args: E[]): boolean {\n if (this.listeners[event]) {\n this.listeners[event].forEach((listener) => listener(...args))\n return true\n }\n return false\n }\n\n public removeListener<E>(\n event: string,\n listenerToRemove: EventListener<E>\n ): Provider<T> {\n if (!this.listeners[event]) return this\n\n this.listeners[event] = this.listeners[event].filter(\n (listener) => listener !== listenerToRemove\n )\n\n return this\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,IAAsB,mBAAtB,MAEyB;CAGrB,cAAc;EAFd,gBAAA,MAAA,aAAA,KAAA,CAAA;EAGI,KAAK,YAAY,CAAC;CACtB;CAOA,GAAa,OAAe,UAAyC;EACjE,IAAI,CAAC,KAAK,UAAU,QAChB,KAAK,UAAU,SAAS,CAAC;EAG7B,KADuB,UAAU,MACxB,CAAC,KAAK,QAAQ;EAEvB,OAAO;CACX;CAEA,KAAe,OAAe,GAAG,MAAoB;EACjD,IAAI,KAAK,UAAU,QAAQ;GACvB,KAAK,UAAU,MAAM,CAAC,SAAS,aAAa,SAAS,GAAG,IAAI,CAAC;GAC7D,OAAO;EACX;EACA,OAAO;CACX;CAEA,eACI,OACA,kBACW;EACX,IAAI,CAAC,KAAK,UAAU,QAAQ,OAAO;EAEnC,KAAK,UAAU,SAAS,KAAK,UAAU,MAAM,CAAC,QACzC,aAAa,aAAa,gBAC/B;EAEA,OAAO;CACX;AACJ"}
|
package/dist/index.js
CHANGED
|
@@ -1,38 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
//#region \0@oxc-project+runtime@0.142.0/helpers/esm/typeof.js
|
|
2
|
+
function _typeof(o) {
|
|
3
|
+
"@babel/helpers - typeof";
|
|
4
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
5
|
+
return typeof o;
|
|
6
|
+
} : function(o) {
|
|
7
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
8
|
+
}, _typeof(o);
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region \0@oxc-project+runtime@0.142.0/helpers/esm/toPrimitive.js
|
|
12
|
+
function toPrimitive(t, r) {
|
|
13
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
14
|
+
var e = t[Symbol.toPrimitive];
|
|
15
|
+
if (void 0 !== e) {
|
|
16
|
+
var i = e.call(t, r || "default");
|
|
17
|
+
if ("object" != _typeof(i)) return i;
|
|
18
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
19
|
+
}
|
|
20
|
+
return ("string" === r ? String : Number)(t);
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region \0@oxc-project+runtime@0.142.0/helpers/esm/toPropertyKey.js
|
|
24
|
+
function toPropertyKey(t) {
|
|
25
|
+
var i = toPrimitive(t, "string");
|
|
26
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region \0@oxc-project+runtime@0.142.0/helpers/esm/defineProperty.js
|
|
30
|
+
function _defineProperty(e, r, t) {
|
|
31
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
32
|
+
value: t,
|
|
33
|
+
enumerable: !0,
|
|
34
|
+
configurable: !0,
|
|
35
|
+
writable: !0
|
|
36
|
+
}) : e[r] = t, e;
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/index.ts
|
|
40
|
+
/**
|
|
41
|
+
* An abstract base class for Providers that implements the event handling logic. It maintains a mapping of event names to arrays of listeners and provides methods to register, emit, and remove listeners. The request method is left abstract for subclasses to implement according to their specific RPC transport mechanism.
|
|
42
|
+
*/
|
|
6
43
|
var AbstractProvider = class {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (!this.listeners[event]) return this;
|
|
29
|
-
this.listeners[event] = this.listeners[event].filter(
|
|
30
|
-
(listener) => listener !== listenerToRemove
|
|
31
|
-
);
|
|
32
|
-
return this;
|
|
33
|
-
}
|
|
44
|
+
constructor() {
|
|
45
|
+
_defineProperty(this, "listeners", void 0);
|
|
46
|
+
this.listeners = {};
|
|
47
|
+
}
|
|
48
|
+
on(event, listener) {
|
|
49
|
+
if (!this.listeners[event]) this.listeners[event] = [];
|
|
50
|
+
this.listeners[event].push(listener);
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
emit(event, ...args) {
|
|
54
|
+
if (this.listeners[event]) {
|
|
55
|
+
this.listeners[event].forEach((listener) => listener(...args));
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
removeListener(event, listenerToRemove) {
|
|
61
|
+
if (!this.listeners[event]) return this;
|
|
62
|
+
this.listeners[event] = this.listeners[event].filter((listener) => listener !== listenerToRemove);
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
34
65
|
};
|
|
35
|
-
|
|
66
|
+
//#endregion
|
|
36
67
|
export { AbstractProvider };
|
|
37
|
-
|
|
68
|
+
|
|
38
69
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.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 { RequestArgs, UnknownRpcTypes } from '@canton-network/core-types'\n\nexport type EventListener<T> = (...args: T[]) => void\n\n/**\n * The Provider interface is generic over a type `T` that defines a mapping between supported methods\n * and their corresponding request and response types. The request method takes an argument of type RequestArgs<T, M>,\n * where `M` is a key of `T` representing the method being called.\n *\n * The type of the params body for a method `M` is derived from T[M]['params']\n * The type of the result of calling a method `M` is derived from T[M]['result']\n */\nexport interface Provider<T extends UnknownRpcTypes> {\n request<M extends keyof T>(args: RequestArgs<T, M>): Promise<T[M]['result']>\n\n on<E>(event: string, listener: EventListener<E>): Provider<T>\n emit<E>(event: string, ...args: E[]): boolean\n removeListener<E>(\n event: string,\n listenerToRemove: EventListener<E>\n ): Provider<T>\n}\n\n/**\n * An abstract base class for Providers that implements the event handling logic. It maintains a mapping of event names to arrays of listeners and provides methods to register, emit, and remove listeners. The request method is left abstract for subclasses to implement according to their specific RPC transport mechanism.\n */\nexport abstract class AbstractProvider<\n T extends UnknownRpcTypes,\n> implements Provider<T> {\n listeners: { [event: string]: EventListener<unknown>[] }\n\n constructor() {\n this.listeners = {} // Event listeners\n }\n\n abstract request<M extends keyof T>(\n args: RequestArgs<T, M>\n ): Promise<T[M]['result']>\n\n // Event handling\n public on<E>(event: string, listener: EventListener<E>): Provider<T> {\n if (!this.listeners[event]) {\n this.listeners[event] = []\n }\n const listeners = this.listeners[event] as EventListener<E>[]\n listeners.push(listener)\n\n return this\n }\n\n public emit<E>(event: string, ...args: E[]): boolean {\n if (this.listeners[event]) {\n this.listeners[event].forEach((listener) => listener(...args))\n return true\n }\n return false\n }\n\n public removeListener<E>(\n event: string,\n listenerToRemove: EventListener<E>\n ): Provider<T> {\n if (!this.listeners[event]) return this\n\n this.listeners[event] = this.listeners[event].filter(\n (listener) => listener !== listenerToRemove\n )\n\n return this\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,IAAsB,mBAAtB,MAEyB;CAGrB,cAAc;EAFd,gBAAA,MAAA,aAAA,KAAA,CAAA;EAGI,KAAK,YAAY,CAAC;CACtB;CAOA,GAAa,OAAe,UAAyC;EACjE,IAAI,CAAC,KAAK,UAAU,QAChB,KAAK,UAAU,SAAS,CAAC;EAG7B,KADuB,UAAU,MACxB,CAAC,KAAK,QAAQ;EAEvB,OAAO;CACX;CAEA,KAAe,OAAe,GAAG,MAAoB;EACjD,IAAI,KAAK,UAAU,QAAQ;GACvB,KAAK,UAAU,MAAM,CAAC,SAAS,aAAa,SAAS,GAAG,IAAI,CAAC;GAC7D,OAAO;EACX;EACA,OAAO;CACX;CAEA,eACI,OACA,kBACW;EACX,IAAI,CAAC,KAAK,UAAU,QAAQ,OAAO;EAEnC,KAAK,UAAU,SAAS,KAAK,UAAU,MAAM,CAAC,QACzC,aAAa,aAAa,gBAC/B;EAEA,OAAO;CACX;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canton-network/core-splice-provider",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A JavaScript Splice Provider API (EIP-1193 compliant).",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -17,26 +17,26 @@
|
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
|
-
"build": "
|
|
21
|
-
"dev": "
|
|
20
|
+
"build": "tsdown --onSuccess \"tsc\"",
|
|
21
|
+
"dev": "tsdown --watch --onSuccess \"tsc\"",
|
|
22
22
|
"flatpack": "yarn pack --out \"$FLATPACK_OUTDIR\"",
|
|
23
23
|
"clean": "tsc -b --clean; rm -rf dist",
|
|
24
24
|
"test": "vitest run --project node --project browser --passWithNoTests",
|
|
25
25
|
"test:coverage": "vitest run --project node --project browser --coverage --passWithNoTests"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@vitest/browser-playwright": "^4.1.
|
|
29
|
-
"@vitest/coverage-v8": "^4.1.
|
|
30
|
-
"playwright": "^1.
|
|
31
|
-
"
|
|
28
|
+
"@vitest/browser-playwright": "^4.1.10",
|
|
29
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
30
|
+
"playwright": "^1.61.1",
|
|
31
|
+
"tsdown": "^0.22.9",
|
|
32
32
|
"typescript": "^5.9.3",
|
|
33
|
-
"vitest": "^4.1.
|
|
33
|
+
"vitest": "^4.1.10"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@canton-network/core-rpc-transport": "^1.
|
|
37
|
-
"@canton-network/core-types": "^1.
|
|
38
|
-
"@canton-network/core-wallet-dapp-remote-rpc-client": "^1.
|
|
39
|
-
"@canton-network/core-wallet-dapp-rpc-client": "^1.
|
|
36
|
+
"@canton-network/core-rpc-transport": "^1.10.0",
|
|
37
|
+
"@canton-network/core-types": "^1.10.0",
|
|
38
|
+
"@canton-network/core-wallet-dapp-remote-rpc-client": "^1.10.0",
|
|
39
|
+
"@canton-network/core-wallet-dapp-rpc-client": "^1.10.0"
|
|
40
40
|
},
|
|
41
41
|
"files": [
|
|
42
42
|
"dist/**"
|