@partylayer/sdk 0.4.1 → 0.6.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.d.mts +49 -1
- package/dist/index.d.ts +49 -1
- package/dist/index.js +75 -35
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/dist/index.d.mts
CHANGED
|
@@ -84,6 +84,19 @@ interface PartyLayerConfig {
|
|
|
84
84
|
channel?: 'stable' | 'beta';
|
|
85
85
|
/** Default network */
|
|
86
86
|
network: NetworkId;
|
|
87
|
+
/**
|
|
88
|
+
* Network-mismatch enforcement policy (default: `'guard'`).
|
|
89
|
+
*
|
|
90
|
+
* When a connected wallet's effective network differs from `network`:
|
|
91
|
+
* - `'off'` — detect + emit `session:networkMismatch` only; never block.
|
|
92
|
+
* - `'guard'` — (default) block wrong-network TRANSACTIONS (signMessage,
|
|
93
|
+
* signTransaction, submitTransaction, ledgerApi); connect still succeeds.
|
|
94
|
+
* - `'strict'` — also block CONNECT (throws `NetworkMismatchError`).
|
|
95
|
+
*
|
|
96
|
+
* BEHAVIOR CHANGE: prior to this, wrong-network transactions always
|
|
97
|
+
* proceeded. Set `'off'` to restore that.
|
|
98
|
+
*/
|
|
99
|
+
networkEnforcement?: 'off' | 'guard' | 'strict';
|
|
87
100
|
/**
|
|
88
101
|
* Wallet adapters to register (OPTIONAL)
|
|
89
102
|
*
|
|
@@ -165,6 +178,12 @@ interface ConnectOptions {
|
|
|
165
178
|
requiredCapabilities?: string[];
|
|
166
179
|
/** Timeout in milliseconds */
|
|
167
180
|
timeoutMs?: number;
|
|
181
|
+
/**
|
|
182
|
+
* Called with a pairing/display URI (e.g. a WalletConnect `wc:` URI) the
|
|
183
|
+
* moment the adapter produces one, before approval. Used by the connect UI
|
|
184
|
+
* to render a QR / deep-link. Adapters without such a URI never call it.
|
|
185
|
+
*/
|
|
186
|
+
onDisplayUri?: (uri: string) => void;
|
|
168
187
|
}
|
|
169
188
|
/**
|
|
170
189
|
* Wallet filter options
|
|
@@ -226,6 +245,21 @@ interface SessionExpiredEvent {
|
|
|
226
245
|
type: 'session:expired';
|
|
227
246
|
sessionId: SessionId;
|
|
228
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* Network mismatch event — the connected wallet's effective network differs
|
|
250
|
+
* from the dApp's configured network. Emitted under ALL policies (informational);
|
|
251
|
+
* `enforced` is true when the active policy ('guard' | 'strict') will block.
|
|
252
|
+
*/
|
|
253
|
+
interface SessionNetworkMismatchEvent {
|
|
254
|
+
type: 'session:networkMismatch';
|
|
255
|
+
sessionId: SessionId;
|
|
256
|
+
/** dApp-configured (expected) network, CAIP-2 normalized. */
|
|
257
|
+
expected: string;
|
|
258
|
+
/** Wallet-reported (actual) network, CAIP-2 normalized. */
|
|
259
|
+
actual: string;
|
|
260
|
+
/** Whether the active policy will block (guard|strict) vs. detect-only (off). */
|
|
261
|
+
enforced: boolean;
|
|
262
|
+
}
|
|
229
263
|
/**
|
|
230
264
|
* Transaction status event
|
|
231
265
|
*/
|
|
@@ -246,7 +280,7 @@ interface ErrorEvent {
|
|
|
246
280
|
/**
|
|
247
281
|
* All event types
|
|
248
282
|
*/
|
|
249
|
-
type PartyLayerEvent = RegistryUpdatedEvent | RegistryStatusEvent | SessionConnectedEvent | SessionDisconnectedEvent | SessionExpiredEvent | TxStatusEvent | ErrorEvent;
|
|
283
|
+
type PartyLayerEvent = RegistryUpdatedEvent | RegistryStatusEvent | SessionConnectedEvent | SessionDisconnectedEvent | SessionExpiredEvent | SessionNetworkMismatchEvent | TxStatusEvent | ErrorEvent;
|
|
250
284
|
/**
|
|
251
285
|
* Event handler type
|
|
252
286
|
*/
|
|
@@ -297,6 +331,20 @@ declare class PartyLayerClient {
|
|
|
297
331
|
* List available wallets
|
|
298
332
|
*/
|
|
299
333
|
listWallets(filter?: WalletFilter): Promise<WalletInfo[]>;
|
|
334
|
+
/** Active network-enforcement policy (default 'guard'). */
|
|
335
|
+
private get enforcement();
|
|
336
|
+
/**
|
|
337
|
+
* Detect a confident network mismatch between the dApp's configured network
|
|
338
|
+
* and the session's (wallet-reported) network. Returns null when they match
|
|
339
|
+
* or the comparison isn't confident (conservative — never a false positive).
|
|
340
|
+
*/
|
|
341
|
+
private networkMismatch;
|
|
342
|
+
/**
|
|
343
|
+
* Guard a transaction-class operation: throw `NetworkMismatchError` when the
|
|
344
|
+
* session is on the wrong network AND the policy enforces it ('guard' |
|
|
345
|
+
* 'strict'). Also protects restored sessions and mid-session network switches.
|
|
346
|
+
*/
|
|
347
|
+
private assertNetworkOk;
|
|
300
348
|
/**
|
|
301
349
|
* Connect to a wallet
|
|
302
350
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -84,6 +84,19 @@ interface PartyLayerConfig {
|
|
|
84
84
|
channel?: 'stable' | 'beta';
|
|
85
85
|
/** Default network */
|
|
86
86
|
network: NetworkId;
|
|
87
|
+
/**
|
|
88
|
+
* Network-mismatch enforcement policy (default: `'guard'`).
|
|
89
|
+
*
|
|
90
|
+
* When a connected wallet's effective network differs from `network`:
|
|
91
|
+
* - `'off'` — detect + emit `session:networkMismatch` only; never block.
|
|
92
|
+
* - `'guard'` — (default) block wrong-network TRANSACTIONS (signMessage,
|
|
93
|
+
* signTransaction, submitTransaction, ledgerApi); connect still succeeds.
|
|
94
|
+
* - `'strict'` — also block CONNECT (throws `NetworkMismatchError`).
|
|
95
|
+
*
|
|
96
|
+
* BEHAVIOR CHANGE: prior to this, wrong-network transactions always
|
|
97
|
+
* proceeded. Set `'off'` to restore that.
|
|
98
|
+
*/
|
|
99
|
+
networkEnforcement?: 'off' | 'guard' | 'strict';
|
|
87
100
|
/**
|
|
88
101
|
* Wallet adapters to register (OPTIONAL)
|
|
89
102
|
*
|
|
@@ -165,6 +178,12 @@ interface ConnectOptions {
|
|
|
165
178
|
requiredCapabilities?: string[];
|
|
166
179
|
/** Timeout in milliseconds */
|
|
167
180
|
timeoutMs?: number;
|
|
181
|
+
/**
|
|
182
|
+
* Called with a pairing/display URI (e.g. a WalletConnect `wc:` URI) the
|
|
183
|
+
* moment the adapter produces one, before approval. Used by the connect UI
|
|
184
|
+
* to render a QR / deep-link. Adapters without such a URI never call it.
|
|
185
|
+
*/
|
|
186
|
+
onDisplayUri?: (uri: string) => void;
|
|
168
187
|
}
|
|
169
188
|
/**
|
|
170
189
|
* Wallet filter options
|
|
@@ -226,6 +245,21 @@ interface SessionExpiredEvent {
|
|
|
226
245
|
type: 'session:expired';
|
|
227
246
|
sessionId: SessionId;
|
|
228
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* Network mismatch event — the connected wallet's effective network differs
|
|
250
|
+
* from the dApp's configured network. Emitted under ALL policies (informational);
|
|
251
|
+
* `enforced` is true when the active policy ('guard' | 'strict') will block.
|
|
252
|
+
*/
|
|
253
|
+
interface SessionNetworkMismatchEvent {
|
|
254
|
+
type: 'session:networkMismatch';
|
|
255
|
+
sessionId: SessionId;
|
|
256
|
+
/** dApp-configured (expected) network, CAIP-2 normalized. */
|
|
257
|
+
expected: string;
|
|
258
|
+
/** Wallet-reported (actual) network, CAIP-2 normalized. */
|
|
259
|
+
actual: string;
|
|
260
|
+
/** Whether the active policy will block (guard|strict) vs. detect-only (off). */
|
|
261
|
+
enforced: boolean;
|
|
262
|
+
}
|
|
229
263
|
/**
|
|
230
264
|
* Transaction status event
|
|
231
265
|
*/
|
|
@@ -246,7 +280,7 @@ interface ErrorEvent {
|
|
|
246
280
|
/**
|
|
247
281
|
* All event types
|
|
248
282
|
*/
|
|
249
|
-
type PartyLayerEvent = RegistryUpdatedEvent | RegistryStatusEvent | SessionConnectedEvent | SessionDisconnectedEvent | SessionExpiredEvent | TxStatusEvent | ErrorEvent;
|
|
283
|
+
type PartyLayerEvent = RegistryUpdatedEvent | RegistryStatusEvent | SessionConnectedEvent | SessionDisconnectedEvent | SessionExpiredEvent | SessionNetworkMismatchEvent | TxStatusEvent | ErrorEvent;
|
|
250
284
|
/**
|
|
251
285
|
* Event handler type
|
|
252
286
|
*/
|
|
@@ -297,6 +331,20 @@ declare class PartyLayerClient {
|
|
|
297
331
|
* List available wallets
|
|
298
332
|
*/
|
|
299
333
|
listWallets(filter?: WalletFilter): Promise<WalletInfo[]>;
|
|
334
|
+
/** Active network-enforcement policy (default 'guard'). */
|
|
335
|
+
private get enforcement();
|
|
336
|
+
/**
|
|
337
|
+
* Detect a confident network mismatch between the dApp's configured network
|
|
338
|
+
* and the session's (wallet-reported) network. Returns null when they match
|
|
339
|
+
* or the comparison isn't confident (conservative — never a false positive).
|
|
340
|
+
*/
|
|
341
|
+
private networkMismatch;
|
|
342
|
+
/**
|
|
343
|
+
* Guard a transaction-class operation: throw `NetworkMismatchError` when the
|
|
344
|
+
* session is on the wrong network AND the policy enforces it ('guard' |
|
|
345
|
+
* 'strict'). Also protects restored sessions and mid-session network switches.
|
|
346
|
+
*/
|
|
347
|
+
private assertNetworkOk;
|
|
300
348
|
/**
|
|
301
349
|
* Connect to a wallet
|
|
302
350
|
*/
|
package/dist/index.js
CHANGED
|
@@ -2,20 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
var core = require('@partylayer/core');
|
|
4
4
|
var registryClient = require('@partylayer/registry-client');
|
|
5
|
+
var provider = require('@partylayer/provider');
|
|
5
6
|
var adapterConsole = require('@partylayer/adapter-console');
|
|
6
7
|
var adapterLoop = require('@partylayer/adapter-loop');
|
|
7
8
|
var adapterCantor8 = require('@partylayer/adapter-cantor8');
|
|
8
9
|
var adapterNightly = require('@partylayer/adapter-nightly');
|
|
9
10
|
var adapterSend = require('@partylayer/adapter-send');
|
|
10
11
|
var adapterBron = require('@partylayer/adapter-bron');
|
|
11
|
-
var provider = require('@partylayer/provider');
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
15
|
-
}) : x)(function(x) {
|
|
16
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
17
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
18
|
-
});
|
|
13
|
+
// src/client.ts
|
|
19
14
|
|
|
20
15
|
// src/config.ts
|
|
21
16
|
var DEFAULT_REGISTRY_URL = "https://registry.partylayer.xyz";
|
|
@@ -494,6 +489,29 @@ var PartyLayerClient = class {
|
|
|
494
489
|
}
|
|
495
490
|
return registryWallets;
|
|
496
491
|
}
|
|
492
|
+
/** Active network-enforcement policy (default 'guard'). */
|
|
493
|
+
get enforcement() {
|
|
494
|
+
return this.config.networkEnforcement ?? "guard";
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Detect a confident network mismatch between the dApp's configured network
|
|
498
|
+
* and the session's (wallet-reported) network. Returns null when they match
|
|
499
|
+
* or the comparison isn't confident (conservative — never a false positive).
|
|
500
|
+
*/
|
|
501
|
+
networkMismatch(session) {
|
|
502
|
+
return core.detectNetworkMismatch(this.config.network, session.network);
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Guard a transaction-class operation: throw `NetworkMismatchError` when the
|
|
506
|
+
* session is on the wrong network AND the policy enforces it ('guard' |
|
|
507
|
+
* 'strict'). Also protects restored sessions and mid-session network switches.
|
|
508
|
+
*/
|
|
509
|
+
assertNetworkOk(session) {
|
|
510
|
+
const mm = this.networkMismatch(session);
|
|
511
|
+
if (mm && this.enforcement !== "off") {
|
|
512
|
+
throw new core.NetworkMismatchError(mm.expected, mm.actual);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
497
515
|
/**
|
|
498
516
|
* Connect to a wallet
|
|
499
517
|
*/
|
|
@@ -574,7 +592,8 @@ var PartyLayerClient = class {
|
|
|
574
592
|
const connectPromise = adapter.connect(ctx, {
|
|
575
593
|
timeoutMs,
|
|
576
594
|
partyId: void 0,
|
|
577
|
-
preferInstalled: options?.preferInstalled
|
|
595
|
+
preferInstalled: options?.preferInstalled,
|
|
596
|
+
onDisplayUri: options?.onDisplayUri
|
|
578
597
|
});
|
|
579
598
|
const timeoutPromise = new Promise((_, reject) => {
|
|
580
599
|
setTimeout(() => {
|
|
@@ -586,13 +605,31 @@ var PartyLayerClient = class {
|
|
|
586
605
|
sessionId: core.toSessionId(`session_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`),
|
|
587
606
|
walletId: selectedWallet.walletId,
|
|
588
607
|
partyId: result.partyId,
|
|
589
|
-
network
|
|
608
|
+
// The wallet's reported network (adapters that read the live wallet —
|
|
609
|
+
// e.g. Console via getActiveNetwork — surface the actual network here;
|
|
610
|
+
// echo-only adapters report ctx.network === config.network). Used for
|
|
611
|
+
// mismatch detection; falls back to the configured network.
|
|
612
|
+
network: result.session.network ?? this.config.network,
|
|
590
613
|
createdAt: Date.now(),
|
|
591
614
|
expiresAt: result.session.expiresAt,
|
|
592
615
|
origin: this.origin,
|
|
593
616
|
capabilitiesSnapshot: result.capabilities,
|
|
594
617
|
metadata: result.session.metadata
|
|
595
618
|
};
|
|
619
|
+
const mismatch = this.networkMismatch(session);
|
|
620
|
+
if (mismatch) {
|
|
621
|
+
session.networkMismatch = mismatch;
|
|
622
|
+
this.emit("session:networkMismatch", {
|
|
623
|
+
type: "session:networkMismatch",
|
|
624
|
+
sessionId: session.sessionId,
|
|
625
|
+
expected: mismatch.expected,
|
|
626
|
+
actual: mismatch.actual,
|
|
627
|
+
enforced: this.enforcement !== "off"
|
|
628
|
+
});
|
|
629
|
+
if (this.enforcement === "strict") {
|
|
630
|
+
throw new core.NetworkMismatchError(mismatch.expected, mismatch.actual);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
596
633
|
await this.persistSession(session);
|
|
597
634
|
this.activeSession = session;
|
|
598
635
|
this.updateRegistryStatus();
|
|
@@ -676,6 +713,7 @@ var PartyLayerClient = class {
|
|
|
676
713
|
);
|
|
677
714
|
}
|
|
678
715
|
try {
|
|
716
|
+
this.assertNetworkOk(session);
|
|
679
717
|
const ctx = this.createAdapterContext();
|
|
680
718
|
return await adapter.signMessage(ctx, session, params);
|
|
681
719
|
} catch (err) {
|
|
@@ -703,6 +741,7 @@ var PartyLayerClient = class {
|
|
|
703
741
|
);
|
|
704
742
|
}
|
|
705
743
|
try {
|
|
744
|
+
this.assertNetworkOk(session);
|
|
706
745
|
const ctx = this.createAdapterContext();
|
|
707
746
|
const result = await adapter.signTransaction(ctx, session, params);
|
|
708
747
|
this.emit("tx:status", {
|
|
@@ -738,6 +777,7 @@ var PartyLayerClient = class {
|
|
|
738
777
|
);
|
|
739
778
|
}
|
|
740
779
|
try {
|
|
780
|
+
this.assertNetworkOk(session);
|
|
741
781
|
const ctx = this.createAdapterContext();
|
|
742
782
|
const result = await adapter.submitTransaction(ctx, session, params);
|
|
743
783
|
this.emit("tx:status", {
|
|
@@ -773,6 +813,7 @@ var PartyLayerClient = class {
|
|
|
773
813
|
);
|
|
774
814
|
}
|
|
775
815
|
try {
|
|
816
|
+
this.assertNetworkOk(session);
|
|
776
817
|
const ctx = this.createAdapterContext();
|
|
777
818
|
return await adapter.ledgerApi(ctx, session, params);
|
|
778
819
|
} catch (err) {
|
|
@@ -822,8 +863,7 @@ var PartyLayerClient = class {
|
|
|
822
863
|
* @returns CIP-0103 compliant Provider
|
|
823
864
|
*/
|
|
824
865
|
asProvider() {
|
|
825
|
-
|
|
826
|
-
return createProviderBridge2(this);
|
|
866
|
+
return provider.createProviderBridge(this);
|
|
827
867
|
}
|
|
828
868
|
/**
|
|
829
869
|
* Destroy client and cleanup
|
|
@@ -1096,30 +1136,6 @@ Object.defineProperty(exports, "matchesProviderDetection", {
|
|
|
1096
1136
|
enumerable: true,
|
|
1097
1137
|
get: function () { return registryClient.matchesProviderDetection; }
|
|
1098
1138
|
});
|
|
1099
|
-
Object.defineProperty(exports, "ConsoleAdapter", {
|
|
1100
|
-
enumerable: true,
|
|
1101
|
-
get: function () { return adapterConsole.ConsoleAdapter; }
|
|
1102
|
-
});
|
|
1103
|
-
Object.defineProperty(exports, "LoopAdapter", {
|
|
1104
|
-
enumerable: true,
|
|
1105
|
-
get: function () { return adapterLoop.LoopAdapter; }
|
|
1106
|
-
});
|
|
1107
|
-
Object.defineProperty(exports, "Cantor8Adapter", {
|
|
1108
|
-
enumerable: true,
|
|
1109
|
-
get: function () { return adapterCantor8.Cantor8Adapter; }
|
|
1110
|
-
});
|
|
1111
|
-
Object.defineProperty(exports, "NightlyAdapter", {
|
|
1112
|
-
enumerable: true,
|
|
1113
|
-
get: function () { return adapterNightly.NightlyAdapter; }
|
|
1114
|
-
});
|
|
1115
|
-
Object.defineProperty(exports, "SendAdapter", {
|
|
1116
|
-
enumerable: true,
|
|
1117
|
-
get: function () { return adapterSend.SendAdapter; }
|
|
1118
|
-
});
|
|
1119
|
-
Object.defineProperty(exports, "BronAdapter", {
|
|
1120
|
-
enumerable: true,
|
|
1121
|
-
get: function () { return adapterBron.BronAdapter; }
|
|
1122
|
-
});
|
|
1123
1139
|
Object.defineProperty(exports, "CANTON_NETWORKS", {
|
|
1124
1140
|
enumerable: true,
|
|
1125
1141
|
get: function () { return provider.CANTON_NETWORKS; }
|
|
@@ -1184,6 +1200,30 @@ Object.defineProperty(exports, "waitForProvider", {
|
|
|
1184
1200
|
enumerable: true,
|
|
1185
1201
|
get: function () { return provider.waitForProvider; }
|
|
1186
1202
|
});
|
|
1203
|
+
Object.defineProperty(exports, "ConsoleAdapter", {
|
|
1204
|
+
enumerable: true,
|
|
1205
|
+
get: function () { return adapterConsole.ConsoleAdapter; }
|
|
1206
|
+
});
|
|
1207
|
+
Object.defineProperty(exports, "LoopAdapter", {
|
|
1208
|
+
enumerable: true,
|
|
1209
|
+
get: function () { return adapterLoop.LoopAdapter; }
|
|
1210
|
+
});
|
|
1211
|
+
Object.defineProperty(exports, "Cantor8Adapter", {
|
|
1212
|
+
enumerable: true,
|
|
1213
|
+
get: function () { return adapterCantor8.Cantor8Adapter; }
|
|
1214
|
+
});
|
|
1215
|
+
Object.defineProperty(exports, "NightlyAdapter", {
|
|
1216
|
+
enumerable: true,
|
|
1217
|
+
get: function () { return adapterNightly.NightlyAdapter; }
|
|
1218
|
+
});
|
|
1219
|
+
Object.defineProperty(exports, "SendAdapter", {
|
|
1220
|
+
enumerable: true,
|
|
1221
|
+
get: function () { return adapterSend.SendAdapter; }
|
|
1222
|
+
});
|
|
1223
|
+
Object.defineProperty(exports, "BronAdapter", {
|
|
1224
|
+
enumerable: true,
|
|
1225
|
+
get: function () { return adapterBron.BronAdapter; }
|
|
1226
|
+
});
|
|
1187
1227
|
exports.CantonConnectClient = PartyLayerClient;
|
|
1188
1228
|
exports.DEFAULT_REGISTRY_URL = DEFAULT_REGISTRY_URL;
|
|
1189
1229
|
exports.MetricsTelemetryAdapter = MetricsTelemetryAdapter;
|