@partylayer/sdk 0.18.2 → 0.19.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 +2 -0
- package/dist/index.d.mts +36 -5
- package/dist/index.d.ts +36 -5
- package/dist/index.js +137 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +131 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { toWalletId, toPartyId, isRecognizedNetwork, toSignature, ledgerApiBodyToObject, normalizeLedgerMethodLower, hashForPrivacy, createMetricsPayload, isOfficialAdapterFactory, isOfficialProviderAdapter, mapUnknownErrorToPartyLayerError, findMatchingWalletInfo, detectNetworkMismatch, NetworkMismatchError, METRICS, AdapterNotRegisteredError, WalletNotFoundError, capabilityGuard, installGuard, toSessionId, CapabilityNotSupportedError, errorMetricName } from '@partylayer/core';
|
|
2
|
-
export { AdapterNotRegisteredError, PartyLayerError as CantonConnectError, CapabilityNotSupportedError, ENABLEMENT_METRICS, ERROR_METRICS, InternalError, METRICS, OriginNotAllowedError, PartyLayerError, REGISTRY_METRICS, RegistryFetchFailedError, RegistrySchemaInvalidError, RegistryVerificationFailedError, SessionExpiredError, TimeoutError, TransportError, UserRejectedError, WalletNotFoundError, WalletNotInstalledError, errorMetricName, isOfficialAdapterFactory, isOfficialProviderAdapter } from '@partylayer/core';
|
|
1
|
+
import { toWalletId, toPartyId, isRecognizedNetwork, toSignature, ledgerApiBodyToObject, normalizeLedgerMethodLower, hashForPrivacy, createMetricsPayload, isOfficialAdapterFactory, isOfficialProviderAdapter, mapUnknownErrorToPartyLayerError, findMatchingWalletInfo, detectNetworkMismatch, NetworkMismatchError, METRICS, AdapterNotRegisteredError, WalletNotFoundError, capabilityGuard, installGuard, toSessionId, CapabilityNotSupportedError, toTransferIntent, errorMetricName, toTransactionHash } from '@partylayer/core';
|
|
2
|
+
export { AdapterNotRegisteredError, PartyLayerError as CantonConnectError, CapabilityNotSupportedError, ENABLEMENT_METRICS, ERROR_METRICS, InternalError, METRICS, OriginNotAllowedError, PartyLayerError, REGISTRY_METRICS, RegistryFetchFailedError, RegistrySchemaInvalidError, RegistryVerificationFailedError, SessionExpiredError, TRANSFER_INTENT_FIELDS, TimeoutError, TransportError, UserRejectedError, WalletNotFoundError, WalletNotInstalledError, errorMetricName, isOfficialAdapterFactory, isOfficialProviderAdapter, toTransferIntent } from '@partylayer/core';
|
|
3
3
|
import { RegistryClient } from '@partylayer/registry-client';
|
|
4
4
|
export { deriveGenericWalletName, findMatchingWallet, findMatchingWalletInfo, isCip0103Native, matchesProviderDetection } from '@partylayer/registry-client';
|
|
5
5
|
import { subscribeAnnouncedProviders, createExtensionChannelProvider, discoverProviders, createProviderBridge } from '@partylayer/provider';
|
|
@@ -15,6 +15,64 @@ export { SendAdapter } from '@partylayer/adapter-send';
|
|
|
15
15
|
export { BronAdapter } from '@partylayer/adapter-bron';
|
|
16
16
|
|
|
17
17
|
// src/client.ts
|
|
18
|
+
var UNSUPPORTED_METHOD = 4200;
|
|
19
|
+
var METHOD_NOT_FOUND = -32601;
|
|
20
|
+
function isUnsupportedMethod(err) {
|
|
21
|
+
const code = err?.code;
|
|
22
|
+
return code === UNSUPPORTED_METHOD || code === METHOD_NOT_FOUND;
|
|
23
|
+
}
|
|
24
|
+
function receiptFromExecutedTx(result) {
|
|
25
|
+
const tx = result?.tx;
|
|
26
|
+
const updateId = tx?.payload?.updateId;
|
|
27
|
+
if (typeof updateId !== "string" || updateId.length === 0) return null;
|
|
28
|
+
return {
|
|
29
|
+
transactionHash: toTransactionHash(updateId),
|
|
30
|
+
submittedAt: Date.now(),
|
|
31
|
+
commandId: typeof tx?.commandId === "string" ? tx.commandId : void 0,
|
|
32
|
+
updateId
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function reportOnce(state, walletId, detail, logger) {
|
|
36
|
+
if (state.logged) return;
|
|
37
|
+
state.logged = true;
|
|
38
|
+
logger?.warn(
|
|
39
|
+
`[PartyLayer] ${walletId}: ${detail} Receipts from it carry no real updateId.`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
async function submitViaPrepareExecute(provider, params, opts) {
|
|
43
|
+
const rpcParams = params;
|
|
44
|
+
const { walletId, state, logger } = opts;
|
|
45
|
+
if (state.verb !== "plain") {
|
|
46
|
+
try {
|
|
47
|
+
const result = await provider.request({
|
|
48
|
+
method: "prepareExecuteAndWait",
|
|
49
|
+
params: rpcParams
|
|
50
|
+
});
|
|
51
|
+
state.verb = "awaited";
|
|
52
|
+
const receipt = receiptFromExecutedTx(result);
|
|
53
|
+
if (receipt) return receipt;
|
|
54
|
+
reportOnce(
|
|
55
|
+
state,
|
|
56
|
+
walletId,
|
|
57
|
+
"prepareExecuteAndWait returned no updateId.",
|
|
58
|
+
logger
|
|
59
|
+
);
|
|
60
|
+
return result;
|
|
61
|
+
} catch (err) {
|
|
62
|
+
if (!isUnsupportedMethod(err)) throw err;
|
|
63
|
+
state.verb = "plain";
|
|
64
|
+
reportOnce(
|
|
65
|
+
state,
|
|
66
|
+
walletId,
|
|
67
|
+
"has no prepareExecuteAndWait; using prepareExecute, which the CIP-0103 types return as null.",
|
|
68
|
+
logger
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return provider.request({ method: "prepareExecute", params: rpcParams });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/announce-adapter.ts
|
|
18
76
|
var ANNOUNCED_WALLET_ID_PREFIX = "browser:ext:";
|
|
19
77
|
function announcedWalletId(announceId) {
|
|
20
78
|
return toWalletId(`${ANNOUNCED_WALLET_ID_PREFIX}${announceId}`);
|
|
@@ -48,6 +106,11 @@ var GenericAnnounceAdapter = class {
|
|
|
48
106
|
staticMetadata;
|
|
49
107
|
mapError;
|
|
50
108
|
signMessageBase64;
|
|
109
|
+
/**
|
|
110
|
+
* Which execute verb this wallet turned out to support. Resolved on the first
|
|
111
|
+
* submit and reused, so the wallet is asked at most once.
|
|
112
|
+
*/
|
|
113
|
+
executeVerb = {};
|
|
51
114
|
// Optional WalletAdapter surface — assigned in the ctor ONLY when configured,
|
|
52
115
|
// so `getCapabilities()` and `'x' in adapter` feature-detection stay honest.
|
|
53
116
|
restore;
|
|
@@ -143,11 +206,12 @@ var GenericAnnounceAdapter = class {
|
|
|
143
206
|
};
|
|
144
207
|
});
|
|
145
208
|
}
|
|
146
|
-
async submitTransaction(
|
|
209
|
+
async submitTransaction(ctx, _session, params) {
|
|
147
210
|
return this.guarded(
|
|
148
|
-
() => this.provider
|
|
149
|
-
|
|
150
|
-
|
|
211
|
+
() => submitViaPrepareExecute(this.provider, params, {
|
|
212
|
+
walletId: String(this.walletId),
|
|
213
|
+
state: this.executeVerb,
|
|
214
|
+
logger: ctx.logger
|
|
151
215
|
})
|
|
152
216
|
);
|
|
153
217
|
}
|
|
@@ -260,6 +324,11 @@ var GenericDiscoveryAdapter = class {
|
|
|
260
324
|
networkHosts;
|
|
261
325
|
/** Lazily resolved from `official.provider()` — NOT at construction (SSR-safe). */
|
|
262
326
|
providerInstance = null;
|
|
327
|
+
/**
|
|
328
|
+
* Which execute verb this wallet turned out to support. Resolved on the first
|
|
329
|
+
* submit and reused, so the wallet is asked at most once.
|
|
330
|
+
*/
|
|
331
|
+
executeVerb = {};
|
|
263
332
|
constructor(args) {
|
|
264
333
|
if (args.official) {
|
|
265
334
|
this.official = args.official;
|
|
@@ -427,10 +496,11 @@ var GenericDiscoveryAdapter = class {
|
|
|
427
496
|
params: { message: params.message }
|
|
428
497
|
});
|
|
429
498
|
}
|
|
430
|
-
async submitTransaction(
|
|
431
|
-
return this.provider
|
|
432
|
-
|
|
433
|
-
|
|
499
|
+
async submitTransaction(ctx, _session, params) {
|
|
500
|
+
return submitViaPrepareExecute(this.provider, params, {
|
|
501
|
+
walletId: String(this.walletId),
|
|
502
|
+
state: this.executeVerb,
|
|
503
|
+
logger: ctx.logger
|
|
434
504
|
});
|
|
435
505
|
}
|
|
436
506
|
};
|
|
@@ -1041,7 +1111,8 @@ var PartyLayerClient = class {
|
|
|
1041
1111
|
);
|
|
1042
1112
|
}
|
|
1043
1113
|
if (!filter?.includeExperimental) {
|
|
1044
|
-
|
|
1114
|
+
const channel = this.config.channel || "stable";
|
|
1115
|
+
return registryWallets.filter((walletInfo) => walletInfo.channel === channel);
|
|
1045
1116
|
}
|
|
1046
1117
|
return registryWallets;
|
|
1047
1118
|
}
|
|
@@ -1690,6 +1761,55 @@ var PartyLayerClient = class {
|
|
|
1690
1761
|
throw error;
|
|
1691
1762
|
}
|
|
1692
1763
|
}
|
|
1764
|
+
/**
|
|
1765
|
+
* Request a typed transfer. The application says what it wants; the wallet
|
|
1766
|
+
* builds the command, shows the user what they are authorising, obtains their
|
|
1767
|
+
* approval, signs, executes, and returns the real update id.
|
|
1768
|
+
*
|
|
1769
|
+
* The acting party comes from the active session, never from the caller, and
|
|
1770
|
+
* the intent is narrowed to the allowlisted fields before any adapter sees it,
|
|
1771
|
+
* so no caller-supplied option can reach the wallet.
|
|
1772
|
+
*
|
|
1773
|
+
* Throws `CapabilityNotSupportedError` when the active wallet does not
|
|
1774
|
+
* implement it. Ask first with `session.capabilitiesSnapshot.includes('transfer')`,
|
|
1775
|
+
* or require it at connect with `connect({ requiredCapabilities: ['transfer'] })`.
|
|
1776
|
+
*/
|
|
1777
|
+
async requestTransfer(intent) {
|
|
1778
|
+
const session = await this.getActiveSession();
|
|
1779
|
+
if (!session) {
|
|
1780
|
+
throw new Error("No active session");
|
|
1781
|
+
}
|
|
1782
|
+
const adapter = this.adapters.get(session.walletId);
|
|
1783
|
+
if (!adapter || !adapter.requestTransfer) {
|
|
1784
|
+
throw new CapabilityNotSupportedError(
|
|
1785
|
+
session.walletId,
|
|
1786
|
+
"transfer"
|
|
1787
|
+
);
|
|
1788
|
+
}
|
|
1789
|
+
const safeIntent = toTransferIntent(intent);
|
|
1790
|
+
const correlationId = newCorrelationId();
|
|
1791
|
+
this.log("debug", "requestTransfer:start", "requestTransfer", {}, correlationId);
|
|
1792
|
+
try {
|
|
1793
|
+
this.assertNetworkOk(session);
|
|
1794
|
+
const ctx = this.createAdapterContext();
|
|
1795
|
+
const result = await adapter.requestTransfer(ctx, session, safeIntent);
|
|
1796
|
+
this.emit("tx:status", {
|
|
1797
|
+
type: "tx:status",
|
|
1798
|
+
sessionId: session.sessionId,
|
|
1799
|
+
txId: result.updateId,
|
|
1800
|
+
status: "committed",
|
|
1801
|
+
raw: result
|
|
1802
|
+
}, correlationId);
|
|
1803
|
+
return result;
|
|
1804
|
+
} catch (err) {
|
|
1805
|
+
const error = mapUnknownErrorToPartyLayerError(err, {
|
|
1806
|
+
phase: "requestTransfer",
|
|
1807
|
+
walletId: String(session.walletId)
|
|
1808
|
+
});
|
|
1809
|
+
this.emit("error", { type: "error", error }, correlationId);
|
|
1810
|
+
throw error;
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1693
1813
|
/**
|
|
1694
1814
|
* Subscribe to events
|
|
1695
1815
|
*/
|