@canton-network/core-provider-ledger 0.2.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,74 @@
1
+ # provider-ledger
2
+
3
+ This package provides a SpliceProvider (see https://github.com/hyperledger-labs/splice-wallet-kernel/tree/main/core/splice-provider) implementation intended for direct Ledger usage. It is suitable for both NodeJS and browser environments, but if you are building a Canton dApp, then you likely want to use the [`dapp-sdk`](https://www.npmjs.com/package/@canton-network/dapp-sdk) instead, which gives a `DappProvider`.
4
+
5
+ This provider only supports a single method, `ledgerApi`, which proxies request through to an underlying Ledger JSON-API client. Due to the nature of the Canton Ledger JSON-API, the only supported transport is HTTP.
6
+
7
+ ## usage
8
+
9
+ ```ts
10
+ import { LedgerProvider } from '@canton-network/core-provider-ledger'
11
+
12
+ const provider = new LedgerProvider({
13
+ baseUrl: 'https://ledger-api.example.com',
14
+ accessToken: 'jwt...',
15
+ })
16
+
17
+ const version = await provider.request({
18
+ method: 'ledgerApi',
19
+ params: {
20
+ resource: '/v2/version',
21
+ requestMethod: 'get',
22
+ },
23
+ })
24
+ ```
25
+
26
+ ## types
27
+
28
+ Due to some type inference limitations, the return type of request collapses to `unknown`. In order to aid the compiler, you can supply an optional type argument corresponding to the operation you are using on the ledgerApi. Afterwards, the response is cleanly typed:
29
+
30
+ ```ts
31
+ import { LedgerProvider, Ops } from '@canton-network/core-provider-ledger'
32
+
33
+ // ...
34
+
35
+ const party = await provider.request<Ops.PostV2Parties>({
36
+ method: 'ledgerApi',
37
+ params: {
38
+ resource: '/v2/parties',
39
+ requestMethod: 'post',
40
+ body: {
41
+ partyHint: 'my-party',
42
+ },
43
+ },
44
+ })
45
+
46
+ console.log(party.partyDetails?.party)
47
+ ```
48
+
49
+ ## data
50
+
51
+ There are various ways to pass data into the request, depending on the operation. Let type inference guide you, but know there are three possibilities:
52
+
53
+ ```ts
54
+
55
+ provider.request({
56
+ method: 'ledgerApi',
57
+ params: {
58
+ ...,
59
+ body?: {
60
+ // usually for POST requests (JSON object body)
61
+ },
62
+ path?: {
63
+ // `path` arguments, usually for GET requests (i.e., `/v2/parties/{party-id}`)
64
+ "party-id": "some-party-id"
65
+ },
66
+ query?: {
67
+ // `query` params, usually for GET requests (i.e., `/v2/...?param=data`)
68
+ "param": "data"
69
+ }
70
+ }
71
+ })
72
+ ```
73
+
74
+ Any particular operation may require just one, none, or multiple client data inputs.
@@ -0,0 +1,33 @@
1
+ import { AbstractProvider } from '@canton-network/core-splice-provider';
2
+ import { RequestArgs } from '@canton-network/core-types';
3
+ import { LedgerTypes } from '@canton-network/core-ledger-client-types';
4
+ export declare class LedgerProvider extends AbstractProvider<LedgerTypes> {
5
+ private client;
6
+ constructor({ baseUrl, accessToken, }: {
7
+ baseUrl: string | URL;
8
+ accessToken: string;
9
+ });
10
+ /**
11
+ *
12
+ * Example usage:
13
+ *
14
+ * const provider = new LedgerProvider(...)
15
+ *
16
+ * // Caveat: TypeScript can infer the correct params body based on the method + API path, but the result will be typed as `unknown` without a type argument:
17
+ *
18
+ * const result1 = await provider.request({ method: 'ledgerApi', params: { ... } });
19
+ * // ^ type = `unknown`
20
+ *
21
+ *
22
+ * // Specify an operation type to get a fully typed result:
23
+ *
24
+ * const result2 = await provider.request<Ops.PostV2Parties>({ method: 'ledgerApi', params: { ... } });
25
+ * // ^ type = `PostV2Parties['ledgerApi']['result']`
26
+ *
27
+ * @param args
28
+ * @returns
29
+ */
30
+ request<L extends LedgerTypes>(args: RequestArgs<L, 'ledgerApi'>): Promise<L['ledgerApi']['result']>;
31
+ private getLedgerParams;
32
+ }
33
+ //# sourceMappingURL=LedgerProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LedgerProvider.d.ts","sourceRoot":"","sources":["../src/LedgerProvider.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAA;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAA;AAQtE,qBAAa,cAAe,SAAQ,gBAAgB,CAAC,WAAW,CAAC;IAC7D,OAAO,CAAC,MAAM,CAAc;gBAEhB,EACR,OAAO,EACP,WAAW,GACd,EAAE;QACC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAA;QACrB,WAAW,EAAE,MAAM,CAAA;KACtB;IAUD;;;;;;;;;;;;;;;;;;;OAmBG;IACU,OAAO,CAAC,CAAC,SAAS,WAAW,EACtC,IAAI,EAAE,WAAW,CAAC,CAAC,EAAE,WAAW,CAAC,GAClC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,CAAC;IAuCpC,OAAO,CAAC,eAAe;CAgB1B"}
package/dist/index.cjs ADDED
@@ -0,0 +1,105 @@
1
+ 'use strict';
2
+
3
+ var coreSpliceProvider = require('@canton-network/core-splice-provider');
4
+ var coreLedgerClient = require('@canton-network/core-ledger-client');
5
+ var pino = require('pino');
6
+ var coreLedgerClientTypes = require('@canton-network/core-ledger-client-types');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
+
10
+ var pino__default = /*#__PURE__*/_interopDefault(pino);
11
+
12
+ var __defProp = Object.defineProperty;
13
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
15
+ var LedgerProvider = class extends coreSpliceProvider.AbstractProvider {
16
+ constructor({
17
+ baseUrl,
18
+ accessToken
19
+ }) {
20
+ super();
21
+ __publicField(this, "client");
22
+ this.client = new coreLedgerClient.LedgerClient({
23
+ baseUrl: typeof baseUrl === "string" ? new URL(baseUrl) : baseUrl,
24
+ accessToken,
25
+ // TODO: use some generalized logger
26
+ logger: pino__default.default({ name: "LedgerProvider" })
27
+ });
28
+ }
29
+ /**
30
+ *
31
+ * Example usage:
32
+ *
33
+ * const provider = new LedgerProvider(...)
34
+ *
35
+ * // Caveat: TypeScript can infer the correct params body based on the method + API path, but the result will be typed as `unknown` without a type argument:
36
+ *
37
+ * const result1 = await provider.request({ method: 'ledgerApi', params: { ... } });
38
+ * // ^ type = `unknown`
39
+ *
40
+ *
41
+ * // Specify an operation type to get a fully typed result:
42
+ *
43
+ * const result2 = await provider.request<Ops.PostV2Parties>({ method: 'ledgerApi', params: { ... } });
44
+ * // ^ type = `PostV2Parties['ledgerApi']['result']`
45
+ *
46
+ * @param args
47
+ * @returns
48
+ */
49
+ async request(args) {
50
+ console.log("Received request:", args);
51
+ if (args.method === "ledgerApi" && "params" in args) {
52
+ switch (args.params.requestMethod) {
53
+ case "get": {
54
+ const params = this.getLedgerParams(args.params);
55
+ return await this.client.getWithRetry(
56
+ args.params.resource,
57
+ // TODO: casting is necessary b/c of v3.3/v3.4 differences
58
+ void 0,
59
+ params
60
+ );
61
+ }
62
+ case "post": {
63
+ const params = this.getLedgerParams(args.params);
64
+ const body = "body" in args.params ? args.params.body : {};
65
+ return await this.client.postWithRetry(
66
+ args.params.resource,
67
+ // TODO: casting is necessary b/c of v3.3/v3.4 differences
68
+ body,
69
+ // TODO: need to fix client typing
70
+ void 0,
71
+ params
72
+ );
73
+ }
74
+ // TODO: generalize LedgerClient to support any HTTP method
75
+ case "delete":
76
+ case "patch":
77
+ default: {
78
+ throw new Error(
79
+ `Unsupported request method: ${args.params.requestMethod}`
80
+ );
81
+ }
82
+ }
83
+ } else {
84
+ throw new Error(`Unsupported method: ${args.method}`);
85
+ }
86
+ }
87
+ getLedgerParams(params) {
88
+ const extracted = {};
89
+ if ("path" in params) {
90
+ Object.assign(extracted, { path: params.path });
91
+ }
92
+ if ("query" in params) {
93
+ Object.assign(extracted, { query: params.query });
94
+ }
95
+ return extracted;
96
+ }
97
+ };
98
+
99
+ Object.defineProperty(exports, "Ops", {
100
+ enumerable: true,
101
+ get: function () { return coreLedgerClientTypes.Provider; }
102
+ });
103
+ exports.LedgerProvider = LedgerProvider;
104
+ //# sourceMappingURL=index.cjs.map
105
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/LedgerProvider.ts"],"names":["AbstractProvider","LedgerClient","pino"],"mappings":";;;;;;;;;;;;;;AAaO,IAAM,cAAA,GAAN,cAA6BA,mCAAA,CAA8B;AAAA,EAG9D,WAAA,CAAY;AAAA,IACR,OAAA;AAAA,IACA;AAAA,GACJ,EAGG;AACC,IAAA,KAAA,EAAM;AATV,IAAA,aAAA,CAAA,IAAA,EAAQ,QAAA,CAAA;AAUJ,IAAA,IAAA,CAAK,MAAA,GAAS,IAAIC,6BAAA,CAAa;AAAA,MAC3B,SAAS,OAAO,OAAA,KAAY,WAAW,IAAI,GAAA,CAAI,OAAO,CAAA,GAAI,OAAA;AAAA,MAC1D,WAAA;AAAA;AAAA,MAEA,MAAA,EAAQC,qBAAA,CAAK,EAAE,IAAA,EAAM,kBAAkB;AAAA,KAC1C,CAAA;AAAA,EACL;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsBA,MAAa,QACT,IAAA,EACiC;AACjC,IAAA,OAAA,CAAQ,GAAA,CAAI,qBAAqB,IAAI,CAAA;AAErC,IAAA,IAAI,IAAA,CAAK,MAAA,KAAW,WAAA,IAAe,QAAA,IAAY,IAAA,EAAM;AACjD,MAAA,QAAQ,IAAA,CAAK,OAAO,aAAA;AAAe,QAC/B,KAAK,KAAA,EAAO;AACR,UAAA,MAAM,MAAA,GAAS,IAAA,CAAK,eAAA,CAAgB,IAAA,CAAK,MAAM,CAAA;AAE/C,UAAA,OAAO,MAAM,KAAK,MAAA,CAAO,YAAA;AAAA,YACrB,KAAK,MAAA,CAAO,QAAA;AAAA;AAAA,YACZ,MAAA;AAAA,YACA;AAAA,WACJ;AAAA,QACJ;AAAA,QACA,KAAK,MAAA,EAAQ;AACT,UAAA,MAAM,MAAA,GAAS,IAAA,CAAK,eAAA,CAAgB,IAAA,CAAK,MAAM,CAAA;AAC/C,UAAA,MAAM,OAAO,MAAA,IAAU,IAAA,CAAK,SAAS,IAAA,CAAK,MAAA,CAAO,OAAO,EAAC;AAEzD,UAAA,OAAO,MAAM,KAAK,MAAA,CAAO,aAAA;AAAA,YACrB,KAAK,MAAA,CAAO,QAAA;AAAA;AAAA,YACZ,IAAA;AAAA;AAAA,YACA,MAAA;AAAA,YACA;AAAA,WACJ;AAAA,QACJ;AAAA;AAAA,QAEA,KAAK,QAAA;AAAA,QACL,KAAK,OAAA;AAAA,QACL,SAAS;AACL,UAAA,MAAM,IAAI,KAAA;AAAA,YACN,CAAA,4BAAA,EAA+B,IAAA,CAAK,MAAA,CAAO,aAAa,CAAA;AAAA,WAC5D;AAAA,QACJ;AAAA;AACJ,IACJ,CAAA,MAAO;AACH,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,oBAAA,EAAuB,IAAA,CAAK,MAAM,CAAA,CAAE,CAAA;AAAA,IACxD;AAAA,EACJ;AAAA,EAEQ,gBAAgB,MAAA,EAGtB;AACE,IAAA,MAAM,YAAY,EAAC;AAEnB,IAAA,IAAI,UAAU,MAAA,EAAQ;AAClB,MAAA,MAAA,CAAO,OAAO,SAAA,EAAW,EAAE,IAAA,EAAM,MAAA,CAAO,MAAM,CAAA;AAAA,IAClD;AAEA,IAAA,IAAI,WAAW,MAAA,EAAQ;AACnB,MAAA,MAAA,CAAO,OAAO,SAAA,EAAW,EAAE,KAAA,EAAO,MAAA,CAAO,OAAO,CAAA;AAAA,IACpD;AAEA,IAAA,OAAO,SAAA;AAAA,EACX;AACJ","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 { AbstractProvider } from '@canton-network/core-splice-provider'\nimport { RequestArgs } from '@canton-network/core-types'\nimport { LedgerTypes } from '@canton-network/core-ledger-client-types'\nimport {\n GetEndpoint,\n LedgerClient,\n PostEndpoint,\n} from '@canton-network/core-ledger-client'\nimport pino from 'pino'\n\nexport class LedgerProvider extends AbstractProvider<LedgerTypes> {\n private client: LedgerClient\n\n constructor({\n baseUrl,\n accessToken,\n }: {\n baseUrl: string | URL\n accessToken: string\n }) {\n super()\n this.client = new LedgerClient({\n baseUrl: typeof baseUrl === 'string' ? new URL(baseUrl) : baseUrl,\n accessToken,\n // TODO: use some generalized logger\n logger: pino({ name: 'LedgerProvider' }),\n })\n }\n\n /**\n *\n * Example usage:\n *\n * const provider = new LedgerProvider(...)\n *\n * // Caveat: TypeScript can infer the correct params body based on the method + API path, but the result will be typed as `unknown` without a type argument:\n *\n * const result1 = await provider.request({ method: 'ledgerApi', params: { ... } });\n * // ^ type = `unknown`\n *\n *\n * // Specify an operation type to get a fully typed result:\n *\n * const result2 = await provider.request<Ops.PostV2Parties>({ method: 'ledgerApi', params: { ... } });\n * // ^ type = `PostV2Parties['ledgerApi']['result']`\n *\n * @param args\n * @returns\n */\n public async request<L extends LedgerTypes>(\n args: RequestArgs<L, 'ledgerApi'>\n ): Promise<L['ledgerApi']['result']> {\n console.log('Received request:', args)\n\n if (args.method === 'ledgerApi' && 'params' in args) {\n switch (args.params.requestMethod) {\n case 'get': {\n const params = this.getLedgerParams(args.params)\n\n return await this.client.getWithRetry(\n args.params.resource as GetEndpoint, // TODO: casting is necessary b/c of v3.3/v3.4 differences\n undefined,\n params\n )\n }\n case 'post': {\n const params = this.getLedgerParams(args.params)\n const body = 'body' in args.params ? args.params.body : {}\n\n return await this.client.postWithRetry(\n args.params.resource as PostEndpoint, // TODO: casting is necessary b/c of v3.3/v3.4 differences\n body as never, // TODO: need to fix client typing\n undefined,\n params\n )\n }\n // TODO: generalize LedgerClient to support any HTTP method\n case 'delete':\n case 'patch':\n default: {\n throw new Error(\n `Unsupported request method: ${args.params.requestMethod}`\n )\n }\n }\n } else {\n throw new Error(`Unsupported method: ${args.method}`)\n }\n }\n\n private getLedgerParams(params: object): {\n path?: Record<string, string>\n query?: Record<string, string>\n } {\n const extracted = {}\n\n if ('path' in params) {\n Object.assign(extracted, { path: params.path })\n }\n\n if ('query' in params) {\n Object.assign(extracted, { query: params.query })\n }\n\n return extracted\n }\n}\n"]}
@@ -0,0 +1,4 @@
1
+ export * from './LedgerProvider';
2
+ import { Provider as Ops } from '@canton-network/core-ledger-client-types';
3
+ export { Ops };
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,kBAAkB,CAAA;AAChC,OAAO,EAAE,QAAQ,IAAI,GAAG,EAAE,MAAM,0CAA0C,CAAA;AAE1E,OAAO,EAAE,GAAG,EAAE,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,95 @@
1
+ import { AbstractProvider } from '@canton-network/core-splice-provider';
2
+ import { LedgerClient } from '@canton-network/core-ledger-client';
3
+ import pino from 'pino';
4
+ export { Provider as Ops } from '@canton-network/core-ledger-client-types';
5
+
6
+ var __defProp = Object.defineProperty;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
9
+ var LedgerProvider = class extends AbstractProvider {
10
+ constructor({
11
+ baseUrl,
12
+ accessToken
13
+ }) {
14
+ super();
15
+ __publicField(this, "client");
16
+ this.client = new LedgerClient({
17
+ baseUrl: typeof baseUrl === "string" ? new URL(baseUrl) : baseUrl,
18
+ accessToken,
19
+ // TODO: use some generalized logger
20
+ logger: pino({ name: "LedgerProvider" })
21
+ });
22
+ }
23
+ /**
24
+ *
25
+ * Example usage:
26
+ *
27
+ * const provider = new LedgerProvider(...)
28
+ *
29
+ * // Caveat: TypeScript can infer the correct params body based on the method + API path, but the result will be typed as `unknown` without a type argument:
30
+ *
31
+ * const result1 = await provider.request({ method: 'ledgerApi', params: { ... } });
32
+ * // ^ type = `unknown`
33
+ *
34
+ *
35
+ * // Specify an operation type to get a fully typed result:
36
+ *
37
+ * const result2 = await provider.request<Ops.PostV2Parties>({ method: 'ledgerApi', params: { ... } });
38
+ * // ^ type = `PostV2Parties['ledgerApi']['result']`
39
+ *
40
+ * @param args
41
+ * @returns
42
+ */
43
+ async request(args) {
44
+ console.log("Received request:", args);
45
+ if (args.method === "ledgerApi" && "params" in args) {
46
+ switch (args.params.requestMethod) {
47
+ case "get": {
48
+ const params = this.getLedgerParams(args.params);
49
+ return await this.client.getWithRetry(
50
+ args.params.resource,
51
+ // TODO: casting is necessary b/c of v3.3/v3.4 differences
52
+ void 0,
53
+ params
54
+ );
55
+ }
56
+ case "post": {
57
+ const params = this.getLedgerParams(args.params);
58
+ const body = "body" in args.params ? args.params.body : {};
59
+ return await this.client.postWithRetry(
60
+ args.params.resource,
61
+ // TODO: casting is necessary b/c of v3.3/v3.4 differences
62
+ body,
63
+ // TODO: need to fix client typing
64
+ void 0,
65
+ params
66
+ );
67
+ }
68
+ // TODO: generalize LedgerClient to support any HTTP method
69
+ case "delete":
70
+ case "patch":
71
+ default: {
72
+ throw new Error(
73
+ `Unsupported request method: ${args.params.requestMethod}`
74
+ );
75
+ }
76
+ }
77
+ } else {
78
+ throw new Error(`Unsupported method: ${args.method}`);
79
+ }
80
+ }
81
+ getLedgerParams(params) {
82
+ const extracted = {};
83
+ if ("path" in params) {
84
+ Object.assign(extracted, { path: params.path });
85
+ }
86
+ if ("query" in params) {
87
+ Object.assign(extracted, { query: params.query });
88
+ }
89
+ return extracted;
90
+ }
91
+ };
92
+
93
+ export { LedgerProvider };
94
+ //# sourceMappingURL=index.js.map
95
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/LedgerProvider.ts"],"names":[],"mappings":";;;;;;;;AAaO,IAAM,cAAA,GAAN,cAA6B,gBAAA,CAA8B;AAAA,EAG9D,WAAA,CAAY;AAAA,IACR,OAAA;AAAA,IACA;AAAA,GACJ,EAGG;AACC,IAAA,KAAA,EAAM;AATV,IAAA,aAAA,CAAA,IAAA,EAAQ,QAAA,CAAA;AAUJ,IAAA,IAAA,CAAK,MAAA,GAAS,IAAI,YAAA,CAAa;AAAA,MAC3B,SAAS,OAAO,OAAA,KAAY,WAAW,IAAI,GAAA,CAAI,OAAO,CAAA,GAAI,OAAA;AAAA,MAC1D,WAAA;AAAA;AAAA,MAEA,MAAA,EAAQ,IAAA,CAAK,EAAE,IAAA,EAAM,kBAAkB;AAAA,KAC1C,CAAA;AAAA,EACL;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsBA,MAAa,QACT,IAAA,EACiC;AACjC,IAAA,OAAA,CAAQ,GAAA,CAAI,qBAAqB,IAAI,CAAA;AAErC,IAAA,IAAI,IAAA,CAAK,MAAA,KAAW,WAAA,IAAe,QAAA,IAAY,IAAA,EAAM;AACjD,MAAA,QAAQ,IAAA,CAAK,OAAO,aAAA;AAAe,QAC/B,KAAK,KAAA,EAAO;AACR,UAAA,MAAM,MAAA,GAAS,IAAA,CAAK,eAAA,CAAgB,IAAA,CAAK,MAAM,CAAA;AAE/C,UAAA,OAAO,MAAM,KAAK,MAAA,CAAO,YAAA;AAAA,YACrB,KAAK,MAAA,CAAO,QAAA;AAAA;AAAA,YACZ,MAAA;AAAA,YACA;AAAA,WACJ;AAAA,QACJ;AAAA,QACA,KAAK,MAAA,EAAQ;AACT,UAAA,MAAM,MAAA,GAAS,IAAA,CAAK,eAAA,CAAgB,IAAA,CAAK,MAAM,CAAA;AAC/C,UAAA,MAAM,OAAO,MAAA,IAAU,IAAA,CAAK,SAAS,IAAA,CAAK,MAAA,CAAO,OAAO,EAAC;AAEzD,UAAA,OAAO,MAAM,KAAK,MAAA,CAAO,aAAA;AAAA,YACrB,KAAK,MAAA,CAAO,QAAA;AAAA;AAAA,YACZ,IAAA;AAAA;AAAA,YACA,MAAA;AAAA,YACA;AAAA,WACJ;AAAA,QACJ;AAAA;AAAA,QAEA,KAAK,QAAA;AAAA,QACL,KAAK,OAAA;AAAA,QACL,SAAS;AACL,UAAA,MAAM,IAAI,KAAA;AAAA,YACN,CAAA,4BAAA,EAA+B,IAAA,CAAK,MAAA,CAAO,aAAa,CAAA;AAAA,WAC5D;AAAA,QACJ;AAAA;AACJ,IACJ,CAAA,MAAO;AACH,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,oBAAA,EAAuB,IAAA,CAAK,MAAM,CAAA,CAAE,CAAA;AAAA,IACxD;AAAA,EACJ;AAAA,EAEQ,gBAAgB,MAAA,EAGtB;AACE,IAAA,MAAM,YAAY,EAAC;AAEnB,IAAA,IAAI,UAAU,MAAA,EAAQ;AAClB,MAAA,MAAA,CAAO,OAAO,SAAA,EAAW,EAAE,IAAA,EAAM,MAAA,CAAO,MAAM,CAAA;AAAA,IAClD;AAEA,IAAA,IAAI,WAAW,MAAA,EAAQ;AACnB,MAAA,MAAA,CAAO,OAAO,SAAA,EAAW,EAAE,KAAA,EAAO,MAAA,CAAO,OAAO,CAAA;AAAA,IACpD;AAEA,IAAA,OAAO,SAAA;AAAA,EACX;AACJ","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 { AbstractProvider } from '@canton-network/core-splice-provider'\nimport { RequestArgs } from '@canton-network/core-types'\nimport { LedgerTypes } from '@canton-network/core-ledger-client-types'\nimport {\n GetEndpoint,\n LedgerClient,\n PostEndpoint,\n} from '@canton-network/core-ledger-client'\nimport pino from 'pino'\n\nexport class LedgerProvider extends AbstractProvider<LedgerTypes> {\n private client: LedgerClient\n\n constructor({\n baseUrl,\n accessToken,\n }: {\n baseUrl: string | URL\n accessToken: string\n }) {\n super()\n this.client = new LedgerClient({\n baseUrl: typeof baseUrl === 'string' ? new URL(baseUrl) : baseUrl,\n accessToken,\n // TODO: use some generalized logger\n logger: pino({ name: 'LedgerProvider' }),\n })\n }\n\n /**\n *\n * Example usage:\n *\n * const provider = new LedgerProvider(...)\n *\n * // Caveat: TypeScript can infer the correct params body based on the method + API path, but the result will be typed as `unknown` without a type argument:\n *\n * const result1 = await provider.request({ method: 'ledgerApi', params: { ... } });\n * // ^ type = `unknown`\n *\n *\n * // Specify an operation type to get a fully typed result:\n *\n * const result2 = await provider.request<Ops.PostV2Parties>({ method: 'ledgerApi', params: { ... } });\n * // ^ type = `PostV2Parties['ledgerApi']['result']`\n *\n * @param args\n * @returns\n */\n public async request<L extends LedgerTypes>(\n args: RequestArgs<L, 'ledgerApi'>\n ): Promise<L['ledgerApi']['result']> {\n console.log('Received request:', args)\n\n if (args.method === 'ledgerApi' && 'params' in args) {\n switch (args.params.requestMethod) {\n case 'get': {\n const params = this.getLedgerParams(args.params)\n\n return await this.client.getWithRetry(\n args.params.resource as GetEndpoint, // TODO: casting is necessary b/c of v3.3/v3.4 differences\n undefined,\n params\n )\n }\n case 'post': {\n const params = this.getLedgerParams(args.params)\n const body = 'body' in args.params ? args.params.body : {}\n\n return await this.client.postWithRetry(\n args.params.resource as PostEndpoint, // TODO: casting is necessary b/c of v3.3/v3.4 differences\n body as never, // TODO: need to fix client typing\n undefined,\n params\n )\n }\n // TODO: generalize LedgerClient to support any HTTP method\n case 'delete':\n case 'patch':\n default: {\n throw new Error(\n `Unsupported request method: ${args.params.requestMethod}`\n )\n }\n }\n } else {\n throw new Error(`Unsupported method: ${args.method}`)\n }\n }\n\n private getLedgerParams(params: object): {\n path?: Record<string, string>\n query?: Record<string, string>\n } {\n const extracted = {}\n\n if ('path' in params) {\n Object.assign(extracted, { path: params.path })\n }\n\n if ('query' in params) {\n Object.assign(extracted, { query: params.query })\n }\n\n return extracted\n }\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@canton-network/core-provider-ledger",
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "description": "A Splice Provider implementation for direct ledger access.",
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
+ "test": "jest",
24
+ "flatpack": "yarn pack --out \"$FLATPACK_OUTDIR\"",
25
+ "clean": "tsc -b --clean; rm -rf dist"
26
+ },
27
+ "devDependencies": {
28
+ "@jest/globals": "^30.2.0",
29
+ "@swc/core": "^1.15.11",
30
+ "@swc/jest": "^0.2.39",
31
+ "@types/jest": "^30.0.0",
32
+ "jest": "^30.2.0",
33
+ "ts-jest": "^29.4.6",
34
+ "ts-jest-resolver": "^2.0.1",
35
+ "tsup": "^8.5.1",
36
+ "typescript": "^5.9.3"
37
+ },
38
+ "dependencies": {
39
+ "@canton-network/core-ledger-client": "^0.28.1",
40
+ "@canton-network/core-ledger-client-types": "^0.21.0",
41
+ "@canton-network/core-splice-provider": "^0.25.0",
42
+ "@canton-network/core-types": "^0.19.0",
43
+ "pino": "^10.3.1"
44
+ },
45
+ "files": [
46
+ "dist/**"
47
+ ],
48
+ "publishConfig": {
49
+ "access": "public"
50
+ },
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "git+https://github.com/hyperledger-labs/splice-wallet-kernel.git",
54
+ "directory": "core/provider-ledger"
55
+ }
56
+ }