@partylayer/provider 0.2.0 → 0.2.1
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.d.mts +3 -34
- package/dist/index.d.ts +3 -34
- package/dist/index.js +23 -45
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -39
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CIP0103Provider, CIP0103RequestPayload, CIP0103EventListener, PartyLayerError, CIP0103ConnectResult, CIP0103TxChangedEvent,
|
|
2
|
-
export { CIP0103Account, CIP0103AccountStatus, CIP0103ConnectResult, CIP0103Event, CIP0103EventListener, CIP0103LedgerApiRequest, CIP0103LedgerApiResponse, CIP0103Method, CIP0103Network, CIP0103Provider, CIP0103ProviderInfo, CIP0103ProviderRpcError, CIP0103ProviderType, CIP0103RequestParams, CIP0103RequestPayload, CIP0103SignMessageRequest, CIP0103StatusEvent, CIP0103TxChangedEvent, CIP0103TxExecutedPayload, CIP0103TxFailedPayload, CIP0103TxPendingPayload, CIP0103TxSignedPayload, CIP0103TxStatus, CIP0103_EVENTS, CIP0103_MANDATORY_METHODS, CIP0103_METHODS } from '@partylayer/core';
|
|
1
|
+
import { CIP0103Provider, CIP0103RequestPayload, CIP0103EventListener, PartyLayerError, CIP0103ConnectResult, CIP0103TxChangedEvent, CIP0103RequestParams } from '@partylayer/core';
|
|
2
|
+
export { CANTON_NETWORKS, CIP0103Account, CIP0103AccountStatus, CIP0103ConnectResult, CIP0103Event, CIP0103EventListener, CIP0103LedgerApiRequest, CIP0103LedgerApiResponse, CIP0103Method, CIP0103Network, CIP0103Provider, CIP0103ProviderInfo, CIP0103ProviderRpcError, CIP0103ProviderType, CIP0103RequestParams, CIP0103RequestPayload, CIP0103SignMessageRequest, CIP0103StatusEvent, CIP0103TxChangedEvent, CIP0103TxExecutedPayload, CIP0103TxFailedPayload, CIP0103TxPendingPayload, CIP0103TxSignedPayload, CIP0103TxStatus, CIP0103_EVENTS, CIP0103_MANDATORY_METHODS, CIP0103_METHODS, fromCAIP2Network, isValidCAIP2, toCAIP2Network } from '@partylayer/core';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* CIP-0103 Wallet Discovery
|
|
@@ -384,37 +384,6 @@ declare function handleAsyncConnect(walletProvider: CIP0103Provider, connectResu
|
|
|
384
384
|
*/
|
|
385
385
|
declare function handleAsyncPrepareExecute(walletProvider: CIP0103Provider, commandId: string, userUrl: string | undefined, options?: AsyncPrepareExecuteOptions): Promise<CIP0103TxChangedEvent>;
|
|
386
386
|
|
|
387
|
-
/**
|
|
388
|
-
* CAIP-2 Network Identity Utilities
|
|
389
|
-
*
|
|
390
|
-
* All CIP-0103 network identifiers use CAIP-2 format: "namespace:reference"
|
|
391
|
-
* e.g. "canton:da-mainnet", "canton:da-devnet"
|
|
392
|
-
*
|
|
393
|
-
* Reference: https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md
|
|
394
|
-
*/
|
|
395
|
-
|
|
396
|
-
declare const CANTON_NETWORKS: Record<string, string>;
|
|
397
|
-
/**
|
|
398
|
-
* Convert a legacy PartyLayer NetworkId (e.g. "devnet") or already-CAIP-2
|
|
399
|
-
* string to a CIP-0103 Network object.
|
|
400
|
-
*
|
|
401
|
-
* @throws {Error} if the resulting network ID is not valid CAIP-2
|
|
402
|
-
*/
|
|
403
|
-
declare function toCAIP2Network(networkId: string): CIP0103Network;
|
|
404
|
-
/**
|
|
405
|
-
* Extract the short network name from a CAIP-2 ID.
|
|
406
|
-
* Returns the original string if no reverse mapping exists.
|
|
407
|
-
*/
|
|
408
|
-
declare function fromCAIP2Network(caip2: string): string;
|
|
409
|
-
/**
|
|
410
|
-
* Validate that a string conforms to CAIP-2 format.
|
|
411
|
-
*
|
|
412
|
-
* CAIP-2 format: namespace:reference
|
|
413
|
-
* - namespace: [-a-z0-9]{3,8}
|
|
414
|
-
* - reference: [-_a-zA-Z0-9]{1,32}
|
|
415
|
-
*/
|
|
416
|
-
declare function isValidCAIP2(networkId: string): boolean;
|
|
417
|
-
|
|
418
387
|
/**
|
|
419
388
|
* CIP-0103 Event Bus
|
|
420
389
|
*
|
|
@@ -468,4 +437,4 @@ declare class MethodRouter {
|
|
|
468
437
|
private registerDefaults;
|
|
469
438
|
}
|
|
470
439
|
|
|
471
|
-
export { type AnnounceDiscoveryOptions, type AnnouncedWallet, type AsyncConnectOptions, type AsyncPrepareExecuteOptions, type BridgeableClient,
|
|
440
|
+
export { type AnnounceDiscoveryOptions, type AnnouncedWallet, type AsyncConnectOptions, type AsyncPrepareExecuteOptions, type BridgeableClient, CIP0103EventBus, type DiscoveredProvider, type ExtensionChannelOptions, JSON_RPC_ERRORS, type MethodHandler, MethodRouter, PartyLayerProvider, type PartyLayerProviderOptions, ProviderRpcError, RPC_ERRORS, chainDisconnected, createExtensionChannelProvider, createProviderBridge, disconnected, discoverAnnouncedProviders, discoverInjectedProviders, discoverProviders, handleAsyncConnect, handleAsyncPrepareExecute, internalError, invalidParams, isCIP0103Provider, methodNotFound, resourceNotFound, resourceUnavailable, toPartyLayerError, toProviderRpcError, transactionRejected, unauthorized, unsupportedMethod, userRejected, waitForProvider };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CIP0103Provider, CIP0103RequestPayload, CIP0103EventListener, PartyLayerError, CIP0103ConnectResult, CIP0103TxChangedEvent,
|
|
2
|
-
export { CIP0103Account, CIP0103AccountStatus, CIP0103ConnectResult, CIP0103Event, CIP0103EventListener, CIP0103LedgerApiRequest, CIP0103LedgerApiResponse, CIP0103Method, CIP0103Network, CIP0103Provider, CIP0103ProviderInfo, CIP0103ProviderRpcError, CIP0103ProviderType, CIP0103RequestParams, CIP0103RequestPayload, CIP0103SignMessageRequest, CIP0103StatusEvent, CIP0103TxChangedEvent, CIP0103TxExecutedPayload, CIP0103TxFailedPayload, CIP0103TxPendingPayload, CIP0103TxSignedPayload, CIP0103TxStatus, CIP0103_EVENTS, CIP0103_MANDATORY_METHODS, CIP0103_METHODS } from '@partylayer/core';
|
|
1
|
+
import { CIP0103Provider, CIP0103RequestPayload, CIP0103EventListener, PartyLayerError, CIP0103ConnectResult, CIP0103TxChangedEvent, CIP0103RequestParams } from '@partylayer/core';
|
|
2
|
+
export { CANTON_NETWORKS, CIP0103Account, CIP0103AccountStatus, CIP0103ConnectResult, CIP0103Event, CIP0103EventListener, CIP0103LedgerApiRequest, CIP0103LedgerApiResponse, CIP0103Method, CIP0103Network, CIP0103Provider, CIP0103ProviderInfo, CIP0103ProviderRpcError, CIP0103ProviderType, CIP0103RequestParams, CIP0103RequestPayload, CIP0103SignMessageRequest, CIP0103StatusEvent, CIP0103TxChangedEvent, CIP0103TxExecutedPayload, CIP0103TxFailedPayload, CIP0103TxPendingPayload, CIP0103TxSignedPayload, CIP0103TxStatus, CIP0103_EVENTS, CIP0103_MANDATORY_METHODS, CIP0103_METHODS, fromCAIP2Network, isValidCAIP2, toCAIP2Network } from '@partylayer/core';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* CIP-0103 Wallet Discovery
|
|
@@ -384,37 +384,6 @@ declare function handleAsyncConnect(walletProvider: CIP0103Provider, connectResu
|
|
|
384
384
|
*/
|
|
385
385
|
declare function handleAsyncPrepareExecute(walletProvider: CIP0103Provider, commandId: string, userUrl: string | undefined, options?: AsyncPrepareExecuteOptions): Promise<CIP0103TxChangedEvent>;
|
|
386
386
|
|
|
387
|
-
/**
|
|
388
|
-
* CAIP-2 Network Identity Utilities
|
|
389
|
-
*
|
|
390
|
-
* All CIP-0103 network identifiers use CAIP-2 format: "namespace:reference"
|
|
391
|
-
* e.g. "canton:da-mainnet", "canton:da-devnet"
|
|
392
|
-
*
|
|
393
|
-
* Reference: https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md
|
|
394
|
-
*/
|
|
395
|
-
|
|
396
|
-
declare const CANTON_NETWORKS: Record<string, string>;
|
|
397
|
-
/**
|
|
398
|
-
* Convert a legacy PartyLayer NetworkId (e.g. "devnet") or already-CAIP-2
|
|
399
|
-
* string to a CIP-0103 Network object.
|
|
400
|
-
*
|
|
401
|
-
* @throws {Error} if the resulting network ID is not valid CAIP-2
|
|
402
|
-
*/
|
|
403
|
-
declare function toCAIP2Network(networkId: string): CIP0103Network;
|
|
404
|
-
/**
|
|
405
|
-
* Extract the short network name from a CAIP-2 ID.
|
|
406
|
-
* Returns the original string if no reverse mapping exists.
|
|
407
|
-
*/
|
|
408
|
-
declare function fromCAIP2Network(caip2: string): string;
|
|
409
|
-
/**
|
|
410
|
-
* Validate that a string conforms to CAIP-2 format.
|
|
411
|
-
*
|
|
412
|
-
* CAIP-2 format: namespace:reference
|
|
413
|
-
* - namespace: [-a-z0-9]{3,8}
|
|
414
|
-
* - reference: [-_a-zA-Z0-9]{1,32}
|
|
415
|
-
*/
|
|
416
|
-
declare function isValidCAIP2(networkId: string): boolean;
|
|
417
|
-
|
|
418
387
|
/**
|
|
419
388
|
* CIP-0103 Event Bus
|
|
420
389
|
*
|
|
@@ -468,4 +437,4 @@ declare class MethodRouter {
|
|
|
468
437
|
private registerDefaults;
|
|
469
438
|
}
|
|
470
439
|
|
|
471
|
-
export { type AnnounceDiscoveryOptions, type AnnouncedWallet, type AsyncConnectOptions, type AsyncPrepareExecuteOptions, type BridgeableClient,
|
|
440
|
+
export { type AnnounceDiscoveryOptions, type AnnouncedWallet, type AsyncConnectOptions, type AsyncPrepareExecuteOptions, type BridgeableClient, CIP0103EventBus, type DiscoveredProvider, type ExtensionChannelOptions, JSON_RPC_ERRORS, type MethodHandler, MethodRouter, PartyLayerProvider, type PartyLayerProviderOptions, ProviderRpcError, RPC_ERRORS, chainDisconnected, createExtensionChannelProvider, createProviderBridge, disconnected, discoverAnnouncedProviders, discoverInjectedProviders, discoverProviders, handleAsyncConnect, handleAsyncPrepareExecute, internalError, invalidParams, isCIP0103Provider, methodNotFound, resourceNotFound, resourceUnavailable, toPartyLayerError, toProviderRpcError, transactionRejected, unauthorized, unsupportedMethod, userRejected, waitForProvider };
|
package/dist/index.js
CHANGED
|
@@ -165,6 +165,7 @@ var ERROR_CODE_TO_RPC = {
|
|
|
165
165
|
REGISTRY_VERIFICATION_FAILED: JSON_RPC_ERRORS.INTERNAL_ERROR,
|
|
166
166
|
REGISTRY_SCHEMA_INVALID: JSON_RPC_ERRORS.INTERNAL_ERROR,
|
|
167
167
|
INTERNAL_ERROR: JSON_RPC_ERRORS.INTERNAL_ERROR,
|
|
168
|
+
NETWORK_MISMATCH: JSON_RPC_ERRORS.INVALID_INPUT,
|
|
168
169
|
TIMEOUT: JSON_RPC_ERRORS.INVALID_INPUT
|
|
169
170
|
};
|
|
170
171
|
var RPC_TO_ERROR_CODE = {
|
|
@@ -504,43 +505,8 @@ var PartyLayerProvider = class {
|
|
|
504
505
|
}
|
|
505
506
|
};
|
|
506
507
|
|
|
507
|
-
// src/network.ts
|
|
508
|
-
var CANTON_NETWORKS = {
|
|
509
|
-
mainnet: "canton:da-mainnet",
|
|
510
|
-
testnet: "canton:da-testnet",
|
|
511
|
-
devnet: "canton:da-devnet",
|
|
512
|
-
local: "canton:da-local"
|
|
513
|
-
};
|
|
514
|
-
var CAIP2_TO_SHORT = Object.fromEntries(
|
|
515
|
-
Object.entries(CANTON_NETWORKS).map(([short, full]) => [full, short])
|
|
516
|
-
);
|
|
517
|
-
function toCAIP2Network(networkId) {
|
|
518
|
-
let result;
|
|
519
|
-
if (networkId.includes(":")) {
|
|
520
|
-
result = networkId;
|
|
521
|
-
} else {
|
|
522
|
-
const caip2 = CANTON_NETWORKS[networkId];
|
|
523
|
-
result = caip2 ?? `canton:${networkId}`;
|
|
524
|
-
}
|
|
525
|
-
if (!isValidCAIP2(result)) {
|
|
526
|
-
throw new Error(
|
|
527
|
-
`Invalid CAIP-2 network identifier: "${result}". Expected format: "namespace:reference"`
|
|
528
|
-
);
|
|
529
|
-
}
|
|
530
|
-
return { networkId: result };
|
|
531
|
-
}
|
|
532
|
-
function fromCAIP2Network(caip2) {
|
|
533
|
-
const short = CAIP2_TO_SHORT[caip2];
|
|
534
|
-
if (short) return short;
|
|
535
|
-
const colonIndex = caip2.indexOf(":");
|
|
536
|
-
return colonIndex >= 0 ? caip2.slice(colonIndex + 1) : caip2;
|
|
537
|
-
}
|
|
538
|
-
function isValidCAIP2(networkId) {
|
|
539
|
-
return /^[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}$/.test(networkId);
|
|
540
|
-
}
|
|
541
|
-
|
|
542
508
|
// src/bridge.ts
|
|
543
|
-
var PROVIDER_VERSION = "0.2.
|
|
509
|
+
var PROVIDER_VERSION = "0.2.1" ;
|
|
544
510
|
function createProviderBridge(client) {
|
|
545
511
|
const eventBus = new CIP0103EventBus();
|
|
546
512
|
const pendingEmitted = /* @__PURE__ */ new Set();
|
|
@@ -596,7 +562,7 @@ async function handleRequest(client, args, eventBus, pendingEmitted) {
|
|
|
596
562
|
version: PROVIDER_VERSION,
|
|
597
563
|
providerType: "browser"
|
|
598
564
|
},
|
|
599
|
-
network: session ? toCAIP2Network(session.network) : void 0,
|
|
565
|
+
network: session ? core.toCAIP2Network(session.network) : void 0,
|
|
600
566
|
session: session ? {
|
|
601
567
|
accessToken: "",
|
|
602
568
|
userId: String(session.partyId)
|
|
@@ -605,7 +571,7 @@ async function handleRequest(client, args, eventBus, pendingEmitted) {
|
|
|
605
571
|
}
|
|
606
572
|
case "getActiveNetwork": {
|
|
607
573
|
const session = await client.getActiveSession();
|
|
608
|
-
return toCAIP2Network(
|
|
574
|
+
return core.toCAIP2Network(
|
|
609
575
|
session?.network ?? "devnet"
|
|
610
576
|
);
|
|
611
577
|
}
|
|
@@ -715,7 +681,7 @@ function wireEvents(client, eventBus, pendingEmitted) {
|
|
|
715
681
|
version: PROVIDER_VERSION,
|
|
716
682
|
providerType: "browser"
|
|
717
683
|
},
|
|
718
|
-
network: toCAIP2Network(session.network),
|
|
684
|
+
network: core.toCAIP2Network(session.network),
|
|
719
685
|
session: {
|
|
720
686
|
accessToken: "",
|
|
721
687
|
userId: String(session.partyId)
|
|
@@ -729,7 +695,7 @@ function wireEvents(client, eventBus, pendingEmitted) {
|
|
|
729
695
|
hint: "",
|
|
730
696
|
publicKey: "",
|
|
731
697
|
namespace: "",
|
|
732
|
-
networkId: toCAIP2Network(session.network).networkId,
|
|
698
|
+
networkId: core.toCAIP2Network(session.network).networkId,
|
|
733
699
|
signingProviderId: ""
|
|
734
700
|
}
|
|
735
701
|
]);
|
|
@@ -814,7 +780,7 @@ function sessionToAccount(session) {
|
|
|
814
780
|
hint: "",
|
|
815
781
|
publicKey: "",
|
|
816
782
|
namespace: "",
|
|
817
|
-
networkId: toCAIP2Network(session.network).networkId,
|
|
783
|
+
networkId: core.toCAIP2Network(session.network).networkId,
|
|
818
784
|
signingProviderId: ""
|
|
819
785
|
};
|
|
820
786
|
}
|
|
@@ -1080,6 +1046,10 @@ async function discoverProviders(options = {}) {
|
|
|
1080
1046
|
return out;
|
|
1081
1047
|
}
|
|
1082
1048
|
|
|
1049
|
+
Object.defineProperty(exports, "CANTON_NETWORKS", {
|
|
1050
|
+
enumerable: true,
|
|
1051
|
+
get: function () { return core.CANTON_NETWORKS; }
|
|
1052
|
+
});
|
|
1083
1053
|
Object.defineProperty(exports, "CIP0103_EVENTS", {
|
|
1084
1054
|
enumerable: true,
|
|
1085
1055
|
get: function () { return core.CIP0103_EVENTS; }
|
|
@@ -1092,7 +1062,18 @@ Object.defineProperty(exports, "CIP0103_METHODS", {
|
|
|
1092
1062
|
enumerable: true,
|
|
1093
1063
|
get: function () { return core.CIP0103_METHODS; }
|
|
1094
1064
|
});
|
|
1095
|
-
exports
|
|
1065
|
+
Object.defineProperty(exports, "fromCAIP2Network", {
|
|
1066
|
+
enumerable: true,
|
|
1067
|
+
get: function () { return core.fromCAIP2Network; }
|
|
1068
|
+
});
|
|
1069
|
+
Object.defineProperty(exports, "isValidCAIP2", {
|
|
1070
|
+
enumerable: true,
|
|
1071
|
+
get: function () { return core.isValidCAIP2; }
|
|
1072
|
+
});
|
|
1073
|
+
Object.defineProperty(exports, "toCAIP2Network", {
|
|
1074
|
+
enumerable: true,
|
|
1075
|
+
get: function () { return core.toCAIP2Network; }
|
|
1076
|
+
});
|
|
1096
1077
|
exports.CIP0103EventBus = CIP0103EventBus;
|
|
1097
1078
|
exports.JSON_RPC_ERRORS = JSON_RPC_ERRORS;
|
|
1098
1079
|
exports.MethodRouter = MethodRouter;
|
|
@@ -1106,17 +1087,14 @@ exports.disconnected = disconnected;
|
|
|
1106
1087
|
exports.discoverAnnouncedProviders = discoverAnnouncedProviders;
|
|
1107
1088
|
exports.discoverInjectedProviders = discoverInjectedProviders;
|
|
1108
1089
|
exports.discoverProviders = discoverProviders;
|
|
1109
|
-
exports.fromCAIP2Network = fromCAIP2Network;
|
|
1110
1090
|
exports.handleAsyncConnect = handleAsyncConnect;
|
|
1111
1091
|
exports.handleAsyncPrepareExecute = handleAsyncPrepareExecute;
|
|
1112
1092
|
exports.internalError = internalError;
|
|
1113
1093
|
exports.invalidParams = invalidParams;
|
|
1114
1094
|
exports.isCIP0103Provider = isCIP0103Provider;
|
|
1115
|
-
exports.isValidCAIP2 = isValidCAIP2;
|
|
1116
1095
|
exports.methodNotFound = methodNotFound;
|
|
1117
1096
|
exports.resourceNotFound = resourceNotFound;
|
|
1118
1097
|
exports.resourceUnavailable = resourceUnavailable;
|
|
1119
|
-
exports.toCAIP2Network = toCAIP2Network;
|
|
1120
1098
|
exports.toPartyLayerError = toPartyLayerError;
|
|
1121
1099
|
exports.toProviderRpcError = toProviderRpcError;
|
|
1122
1100
|
exports.transactionRejected = transactionRejected;
|