@canton-network/dapp-sdk 1.7.0 → 1.8.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/adapter/extension-adapter.d.ts +1 -1
- package/dist/adapter/extension-adapter.d.ts.map +1 -1
- package/dist/adapter/remote-adapter.d.ts.map +1 -1
- package/dist/adapter/walletconnect-adapter.d.ts.map +1 -1
- package/dist/dapp-api/rpc-gen/index.d.ts.map +1 -1
- package/dist/dapp-api/rpc-gen/typings.d.ts +1 -1
- package/dist/dapp-api/rpc-gen/typings.d.ts.map +1 -1
- package/dist/error.d.ts +1 -0
- package/dist/error.d.ts.map +1 -1
- package/dist/index.cjs +48 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +48 -40
- package/dist/index.js.map +1 -1
- package/dist/sdk-controller.d.ts +1 -1
- package/dist/sdk-controller.d.ts.map +1 -1
- package/dist/sdk.d.ts +12 -0
- package/dist/sdk.d.ts.map +1 -1
- package/dist/storage.d.ts +1 -1
- package/dist/storage.d.ts.map +1 -1
- package/dist/util.d.ts +1 -1
- package/dist/util.d.ts.map +1 -1
- package/dist/version.d.ts +10 -0
- package/dist/version.d.ts.map +1 -0
- package/package.json +29 -16
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import '@canton-network/core-provider-dapp';
|
|
2
|
+
import './version.js';
|
|
3
|
+
export { SDK_VERSION } from './version.js';
|
|
2
4
|
export { CANTON_LOGO_PNG, WALLET_GATEWAY_ICON } from './assets';
|
|
3
5
|
export { DappClient } from './client';
|
|
4
6
|
export type { DappClientOptions } from './client';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,oCAAoC,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,oCAAoC,CAAA;AAE3C,OAAO,cAAc,CAAA;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAG1C,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAG/D,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrC,YAAY,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAGjD,cAAc,iBAAiB,CAAA;AAG/B,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAA;AACvE,YAAY,EACR,qBAAqB,EACrB,aAAa,GAChB,MAAM,uCAAuC,CAAA;AAG9C,cAAc,SAAS,CAAA;AAGvB,OAAO,KAAK,OAAO,MAAM,6CAA6C,CAAA;AACtE,YAAY,EACR,WAAW,EACX,aAAa,EACb,oBAAoB,EACpB,2BAA2B,EAC3B,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACpB,cAAc,EACd,MAAM,EACN,OAAO,EACP,OAAO,GACV,MAAM,6CAA6C,CAAA;AACpD,YAAY,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAGvE,OAAO,EACH,OAAO,EACP,GAAG,IAAI,OAAO,EACd,IAAI,EACJ,OAAO,EACP,UAAU,EACV,WAAW,EACX,MAAM,EACN,YAAY,EACZ,cAAc,EACd,qBAAqB,EACrB,SAAS,EACT,IAAI,EACJ,oBAAoB,EACpB,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,WAAW,EACX,qBAAqB,EACrB,uBAAuB,EACvB,iBAAiB,EACjB,iBAAiB,GACpB,MAAM,OAAO,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -3,9 +3,19 @@ import { CANTON_ANNOUNCE_PROVIDER_EVENT, CANTON_REQUEST_PROVIDER_EVENT, Discover
|
|
|
3
3
|
import { notifyWalletPickerConnected, notifyWalletPickerError, pickWallet, popup, waitForWalletPickerRetrySelection } from "@canton-network/core-wallet-ui-components";
|
|
4
4
|
import { DiscoveryClient, DiscoveryClient as DiscoveryClient$1, DiscoveryError, EventEmitter, NotConnectedError, SessionExpiredError, TimeoutError, UserRejectedError, WalletNotFoundError, WalletNotInstalledError } from "@canton-network/core-wallet-discovery";
|
|
5
5
|
import { WindowTransport } from "@canton-network/core-rpc-transport";
|
|
6
|
+
import { errorCodes, providerErrors, rpcErrors, toJsonRpcError } from "@canton-network/core-rpc-errors";
|
|
6
7
|
import SignClient from "@walletconnect/sign-client";
|
|
7
8
|
import { v4 } from "uuid";
|
|
8
9
|
import * as dappAPI from "@canton-network/core-wallet-dapp-rpc-client";
|
|
10
|
+
//#region src/version.ts
|
|
11
|
+
/** Published version of `@canton-network/dapp-sdk`. */
|
|
12
|
+
const SDK_VERSION = "1.8.0";
|
|
13
|
+
const DAPP_SDK_BUILD = Object.freeze({
|
|
14
|
+
name: "@canton-network/dapp-sdk",
|
|
15
|
+
version: SDK_VERSION
|
|
16
|
+
});
|
|
17
|
+
globalThis.__CANTON_DAPP_SDK__ = DAPP_SDK_BUILD;
|
|
18
|
+
//#endregion
|
|
9
19
|
//#region src/assets.ts
|
|
10
20
|
/**
|
|
11
21
|
* Base64-encoded icon assets for the dApp SDK.
|
|
@@ -79,7 +89,7 @@ const composeSIWXMessage = (params) => {
|
|
|
79
89
|
].filter((line) => typeof line === "string").join("\n").trim();
|
|
80
90
|
};
|
|
81
91
|
//#endregion
|
|
82
|
-
//#region \0@oxc-project+runtime@0.
|
|
92
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
|
|
83
93
|
function _typeof(o) {
|
|
84
94
|
"@babel/helpers - typeof";
|
|
85
95
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -89,7 +99,7 @@ function _typeof(o) {
|
|
|
89
99
|
}, _typeof(o);
|
|
90
100
|
}
|
|
91
101
|
//#endregion
|
|
92
|
-
//#region \0@oxc-project+runtime@0.
|
|
102
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
|
|
93
103
|
function toPrimitive(t, r) {
|
|
94
104
|
if ("object" != _typeof(t) || !t) return t;
|
|
95
105
|
var e = t[Symbol.toPrimitive];
|
|
@@ -101,13 +111,13 @@ function toPrimitive(t, r) {
|
|
|
101
111
|
return ("string" === r ? String : Number)(t);
|
|
102
112
|
}
|
|
103
113
|
//#endregion
|
|
104
|
-
//#region \0@oxc-project+runtime@0.
|
|
114
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
|
|
105
115
|
function toPropertyKey(t) {
|
|
106
116
|
var i = toPrimitive(t, "string");
|
|
107
117
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
108
118
|
}
|
|
109
119
|
//#endregion
|
|
110
|
-
//#region \0@oxc-project+runtime@0.
|
|
120
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
|
|
111
121
|
function _defineProperty(e, r, t) {
|
|
112
122
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
113
123
|
value: t,
|
|
@@ -318,24 +328,10 @@ function buildController(methods) {
|
|
|
318
328
|
};
|
|
319
329
|
}
|
|
320
330
|
//#endregion
|
|
321
|
-
//#region src/error.ts
|
|
322
|
-
let ErrorCode = /* @__PURE__ */ function(ErrorCode) {
|
|
323
|
-
ErrorCode[ErrorCode["ProviderNotFound"] = 0] = "ProviderNotFound";
|
|
324
|
-
ErrorCode[ErrorCode["UserCancelled"] = 1] = "UserCancelled";
|
|
325
|
-
ErrorCode[ErrorCode["Timeout"] = 2] = "Timeout";
|
|
326
|
-
ErrorCode[ErrorCode["TransactionFailed"] = 3] = "TransactionFailed";
|
|
327
|
-
ErrorCode[ErrorCode["Other"] = 4] = "Other";
|
|
328
|
-
return ErrorCode;
|
|
329
|
-
}({});
|
|
330
|
-
//#endregion
|
|
331
331
|
//#region src/sdk-controller.ts
|
|
332
332
|
const withTimeout = (reject, details, timeoutMs = 3e5) => setTimeout(() => {
|
|
333
333
|
console.warn(`SDK: ${details}`);
|
|
334
|
-
reject(
|
|
335
|
-
status: "error",
|
|
336
|
-
error: 2,
|
|
337
|
-
details
|
|
338
|
-
});
|
|
334
|
+
reject(rpcErrors.resourceUnavailable(details));
|
|
339
335
|
}, timeoutMs);
|
|
340
336
|
const dappSDKController = (provider) => buildController({
|
|
341
337
|
connect: async () => {
|
|
@@ -386,11 +382,7 @@ const dappSDKController = (provider) => buildController({
|
|
|
386
382
|
if (event.status === "failed") {
|
|
387
383
|
provider.removeListener("txChanged", listener);
|
|
388
384
|
clearTimeout(timeout);
|
|
389
|
-
reject({
|
|
390
|
-
status: "error",
|
|
391
|
-
error: 3,
|
|
392
|
-
details: `Transaction with commandId ${event.commandId} failed to execute.`
|
|
393
|
-
});
|
|
385
|
+
reject(rpcErrors.transactionRejected(`Transaction with commandId ${event.commandId} failed to execute.`));
|
|
394
386
|
}
|
|
395
387
|
if (event.status === "executed") {
|
|
396
388
|
provider.removeListener("txChanged", listener);
|
|
@@ -428,11 +420,7 @@ const dappSDKController = (provider) => buildController({
|
|
|
428
420
|
provider.removeListener("messageSignature", listener);
|
|
429
421
|
clearTimeout(timeout);
|
|
430
422
|
if (event.status === "failed") {
|
|
431
|
-
reject({
|
|
432
|
-
status: "error",
|
|
433
|
-
error: 3,
|
|
434
|
-
details: `Message signing failed for messageId ${event.messageId}.`
|
|
435
|
-
});
|
|
423
|
+
reject(rpcErrors.transactionRejected(`Message signing failed for messageId ${event.messageId}.`));
|
|
436
424
|
return;
|
|
437
425
|
}
|
|
438
426
|
resolve({ signature: event.signature });
|
|
@@ -551,7 +539,7 @@ var RemoteMappedProvider = class {
|
|
|
551
539
|
case "getPrimaryAccount": return controller.getPrimaryAccount();
|
|
552
540
|
case "getActiveNetwork": return controller.getActiveNetwork();
|
|
553
541
|
case "signMessage": return controller.signMessage(args.params);
|
|
554
|
-
default: throw
|
|
542
|
+
default: throw providerErrors.unsupportedMethod(`Unsupported method: ${String(args.method)}`);
|
|
555
543
|
}
|
|
556
544
|
}
|
|
557
545
|
on(event, listener) {
|
|
@@ -668,7 +656,7 @@ var WalletConnectAdapter = class WalletConnectAdapter {
|
|
|
668
656
|
isNetworkConnected: false
|
|
669
657
|
}
|
|
670
658
|
};
|
|
671
|
-
if (!this.session) throw
|
|
659
|
+
if (!this.session) throw providerErrors.unauthorized("WalletConnect session not established");
|
|
672
660
|
if (args.method === "prepareExecute" || args.method === "prepareExecuteAndWait") {
|
|
673
661
|
const result = await this.walletConnectRequest("prepareSignExecute", args.params);
|
|
674
662
|
this.emit("txChanged", result);
|
|
@@ -702,7 +690,7 @@ var WalletConnectAdapter = class WalletConnectAdapter {
|
|
|
702
690
|
}
|
|
703
691
|
/** Send a request through signClient, prefixing the method with `canton_`. */
|
|
704
692
|
async walletConnectRequest(method, params) {
|
|
705
|
-
if (!this.signClient || !this.session) throw
|
|
693
|
+
if (!this.signClient || !this.session) throw providerErrors.unauthorized("WalletConnect session not established");
|
|
706
694
|
try {
|
|
707
695
|
return await this.signClient.request({
|
|
708
696
|
topic: this.session.topic,
|
|
@@ -712,11 +700,8 @@ var WalletConnectAdapter = class WalletConnectAdapter {
|
|
|
712
700
|
params: params ?? {}
|
|
713
701
|
}
|
|
714
702
|
});
|
|
715
|
-
} catch (
|
|
716
|
-
|
|
717
|
-
const message = err instanceof Error ? err.message : "message" in errObj && typeof errObj.message === "string" ? errObj.message : String(err);
|
|
718
|
-
const code = "code" in errObj ? errObj.code : -32603;
|
|
719
|
-
throw new Error(`RPC error: ${code} - ${message}`, { cause: err });
|
|
703
|
+
} catch (error) {
|
|
704
|
+
throw toJsonRpcError(error);
|
|
720
705
|
}
|
|
721
706
|
}
|
|
722
707
|
emitConnected() {
|
|
@@ -815,7 +800,7 @@ var WalletConnectAdapter = class WalletConnectAdapter {
|
|
|
815
800
|
signature: "",
|
|
816
801
|
error: {
|
|
817
802
|
message: err.message,
|
|
818
|
-
code:
|
|
803
|
+
code: errorCodes.rpc.internal
|
|
819
804
|
}
|
|
820
805
|
});
|
|
821
806
|
}
|
|
@@ -847,6 +832,17 @@ var WalletConnectAdapter = class WalletConnectAdapter {
|
|
|
847
832
|
}
|
|
848
833
|
};
|
|
849
834
|
//#endregion
|
|
835
|
+
//#region src/error.ts
|
|
836
|
+
/** @deprecated No longer emitted; errors are `JsonRpcError`s with a code from `errorCodes` in `@canton-network/core-rpc-errors`. */
|
|
837
|
+
let ErrorCode = /* @__PURE__ */ function(ErrorCode) {
|
|
838
|
+
ErrorCode[ErrorCode["ProviderNotFound"] = 0] = "ProviderNotFound";
|
|
839
|
+
ErrorCode[ErrorCode["UserCancelled"] = 1] = "UserCancelled";
|
|
840
|
+
ErrorCode[ErrorCode["Timeout"] = 2] = "Timeout";
|
|
841
|
+
ErrorCode[ErrorCode["TransactionFailed"] = 3] = "TransactionFailed";
|
|
842
|
+
ErrorCode[ErrorCode["Other"] = 4] = "Other";
|
|
843
|
+
return ErrorCode;
|
|
844
|
+
}({});
|
|
845
|
+
//#endregion
|
|
850
846
|
//#region src/gateways.json
|
|
851
847
|
var gateways_default = [{
|
|
852
848
|
"name": "Wallet Gateway (localhost, dev)",
|
|
@@ -911,6 +907,10 @@ function normalizeConnectOptions(options) {
|
|
|
911
907
|
enableSuggestedWallets: defaultTrue(options.enableSuggestedWallets)
|
|
912
908
|
};
|
|
913
909
|
}
|
|
910
|
+
/**
|
|
911
|
+
* Wallet requests reject with a `JsonRpcError` whose `code` is one of the CIP-103
|
|
912
|
+
* `errorCodes`; branch on `code`, not on `message`.
|
|
913
|
+
*/
|
|
914
914
|
var DappSDK = class {
|
|
915
915
|
constructor(options) {
|
|
916
916
|
_defineProperty(this, "RECENT_GATEWAYS_KEY", "splice_wallet_picker_recent");
|
|
@@ -1022,7 +1022,7 @@ var DappSDK = class {
|
|
|
1022
1022
|
return `${baseMessage} (HTTP ${statusCode})`;
|
|
1023
1023
|
}
|
|
1024
1024
|
requireClient() {
|
|
1025
|
-
if (!this.client) throw
|
|
1025
|
+
if (!this.client) throw providerErrors.unauthorized("Not connected — call connect() first");
|
|
1026
1026
|
return this.client;
|
|
1027
1027
|
}
|
|
1028
1028
|
/**
|
|
@@ -1175,9 +1175,17 @@ var DappSDK = class {
|
|
|
1175
1175
|
async prepareExecute(params) {
|
|
1176
1176
|
return this.requireClient().prepareExecute(params);
|
|
1177
1177
|
}
|
|
1178
|
+
/**
|
|
1179
|
+
* @throws `JsonRpcError` with `userRejectedRequest` or `transactionRejected` if the
|
|
1180
|
+
* transaction is declined or fails, and `resourceUnavailable` if no outcome arrives in time.
|
|
1181
|
+
*/
|
|
1178
1182
|
async prepareExecuteAndWait(params) {
|
|
1179
1183
|
return this.requireClient().prepareExecuteAndWait(params);
|
|
1180
1184
|
}
|
|
1185
|
+
/**
|
|
1186
|
+
* @throws `JsonRpcError` with `userRejectedRequest` or `transactionRejected` if signing
|
|
1187
|
+
* is declined or fails, and `resourceUnavailable` if no signature arrives in time.
|
|
1188
|
+
*/
|
|
1181
1189
|
async signMessage(params) {
|
|
1182
1190
|
return this.requireClient().signMessage(params);
|
|
1183
1191
|
}
|
|
@@ -1253,6 +1261,6 @@ function createDefaultAdapters(defaultGatewayConfigs) {
|
|
|
1253
1261
|
}));
|
|
1254
1262
|
}
|
|
1255
1263
|
//#endregion
|
|
1256
|
-
export { CANTON_LOGO_PNG, DappClient, DappSDK, DiscoveryClient, DiscoveryError, ErrorCode, EventEmitter, ExtensionAdapter, NotConnectedError, RemoteAdapter, SessionExpiredError, TimeoutError, UserRejectedError, WALLET_GATEWAY_ICON, WalletConnectAdapter, WalletNotFoundError, WalletNotInstalledError, connect, dappAPI, sdk as dappSDK, disconnect, getConnectedProvider, init, isConnected, ledgerApi, listAccounts, onAccountsChanged, onConnected, onStatusChanged, onTxChanged, open, prepareExecute, prepareExecuteAndWait, removeOnAccountsChanged, removeOnConnected, removeOnStatusChanged, removeOnTxChanged, status };
|
|
1264
|
+
export { CANTON_LOGO_PNG, DappClient, DappSDK, DiscoveryClient, DiscoveryError, ErrorCode, EventEmitter, ExtensionAdapter, NotConnectedError, RemoteAdapter, SDK_VERSION, SessionExpiredError, TimeoutError, UserRejectedError, WALLET_GATEWAY_ICON, WalletConnectAdapter, WalletNotFoundError, WalletNotInstalledError, connect, dappAPI, sdk as dappSDK, disconnect, getConnectedProvider, init, isConnected, ledgerApi, listAccounts, onAccountsChanged, onConnected, onStatusChanged, onTxChanged, open, prepareExecute, prepareExecuteAndWait, removeOnAccountsChanged, removeOnConnected, removeOnStatusChanged, removeOnTxChanged, status };
|
|
1257
1265
|
|
|
1258
1266
|
//# sourceMappingURL=index.js.map
|