@tezos-x/octez.connect-dapp 5.0.0-beta.7 → 5.0.2
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/cjs/dapp-client/DAppClient.js +37 -21
- package/dist/cjs/dapp-client/DAppClient.js.map +1 -1
- package/dist/cjs/dapp-client/DAppClientOptions.d.ts +18 -10
- package/dist/cjs/dapp-client/DAppClientOptions.js.map +1 -1
- package/dist/esm/dapp-client/DAppClient.js +38 -22
- package/dist/esm/dapp-client/DAppClient.js.map +1 -1
- package/dist/esm/dapp-client/DAppClientOptions.d.ts +18 -10
- package/dist/esm/dapp-client/DAppClientOptions.js.map +1 -1
- package/dist/octez.connect.dapp.min.js +1 -1
- package/package.json +9 -9
|
@@ -130,16 +130,24 @@ export interface DAppClientOptions {
|
|
|
130
130
|
*/
|
|
131
131
|
enableMetrics?: boolean;
|
|
132
132
|
/**
|
|
133
|
-
* Minimum
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
* `
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
133
|
+
* Minimum wallet version the dApp will accept. The gate is opt-in: it
|
|
134
|
+
* defaults to the lowest supported protocol version, so every wallet the
|
|
135
|
+
* SDK can talk to is accepted and upgrading the SDK never rejects existing
|
|
136
|
+
* v2/v3 wallets. Set `'4'` to require the v4 multi-network protocol. Must
|
|
137
|
+
* be a decimal-integer string in `[1, BEACON_VERSION]`; otherwise
|
|
138
|
+
* `InvalidRequiredMinimumVersionError` is thrown at construction. A wallet
|
|
139
|
+
* below this minimum is rejected with `VersionUnsupportedBeaconError` when
|
|
140
|
+
* a request is sent.
|
|
141
|
+
*
|
|
142
|
+
* The version compared against this minimum is the wallet's EFFECTIVE
|
|
143
|
+
* version, not the raw `peer.version`: legacy wallets echo the dApp's own
|
|
144
|
+
* version at pairing, so a declared version is only trusted when the
|
|
145
|
+
* pairing response carried the v5 `protocolVersion` capability marker —
|
|
146
|
+
* marker-less wallets that declared a version count as `'2'` (and are
|
|
147
|
+
* therefore rejected by a minimum of `'3'` or `'4'`, even though their
|
|
148
|
+
* echoed `peer.version` may read higher). A wallet that reports no version
|
|
149
|
+
* at all (WalletConnect pairings) is still treated as unknown and allowed,
|
|
150
|
+
* so those pairings keep working.
|
|
143
151
|
*/
|
|
144
152
|
requiredMinimumVersion?: string;
|
|
145
153
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DAppClientOptions.js","sourceRoot":"","sources":["../../../src/dapp-client/DAppClientOptions.ts"],"names":[],"mappings":"","sourcesContent":["import { BeaconEvent, BeaconEventType, BeaconEventHandlerFunction } from '../events'\nimport { BlockExplorer } from '../utils/block-explorer'\nimport {\n Storage,\n NetworkType,\n ColorMode,\n NodeDistributions,\n AnalyticsInterface,\n Network\n} from '@tezos-x/octez.connect-types'\n\ntype RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> &\n {\n [K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>\n }[Keys]\n\n/**\n * @category DApp\n */\nexport interface DAppClientOptions {\n /**\n * Name of the application\n */\n name: string\n\n /**\n * Description of the application\n */\n description?: string\n\n /**\n * A URL to the icon of the application\n */\n iconUrl?: string\n\n /**\n * A URL to the website of the application\n */\n appUrl?: string\n\n /**\n * The storage that will be used by the SDK\n */\n storage?: Storage\n\n /**\n * An object that will be used to overwrite default event handler behaviour.\n *\n * If you plan to overwrite all default events, use \"disableDefaultEvents\" instead.\n *\n * This will overwrite the default event handler, so this can lead to unexpected behavior in some cases.\n * We recommend that you overwrite all handlers if you want to use your own UI.\n *\n * If you simply want to be notified of events happening, but do not want to overwrite the default behavior,\n * please use `subscribeToEvent()` on the DAppClient instead.\n */\n eventHandlers?: {\n [key in BeaconEvent]?: {\n handler: BeaconEventHandlerFunction<BeaconEventType[key]>\n }\n }\n\n /**\n * Disable all default Events and UI elements. If passed together with \"eventHandlers\",\n * the default eventHandlers will be removed, and the ones passed by the user will be added.\n */\n disableDefaultEvents?: boolean\n\n /**\n * A list of matrix nodes to connect to. If a non-empty array is passed, the default options will be overwritten.\n * One node will be randomly selected based on the local keypair and the other nodes will be used as a fallback in case the primary node goes down.\n *\n * Only provide the hostname, no https:// prefix. Eg. { [Regions.EU1]: ['matrix.example.com'] }\n */\n matrixNodes?: NodeDistributions\n\n /**\n * The block explorer used by the SDK\n */\n blockExplorer?: BlockExplorer\n\n /**\n * Indicates on which network the DApp is running on.\n */\n network?: Network\n\n /**\n * @deprecated Please use \"network\" instead.\n * Indicates on which network the DApp is planning to run. This is currently used to adjust the URLs of web-wallets in the pairing alert if they use different URLs for testnets.\n * You will still have to define the network you intend to use during the permission request.\n */\n preferredNetwork?: NetworkType\n\n /**\n * Set the color mode for the UI elements (alerts and toasts)\n */\n colorMode?: ColorMode\n\n /**\n * A URL to the Terms & Conditions page that will be displayed in the pairing modal\n */\n termsAndConditionsUrl?: string\n\n /**\n * A URL to the Privacy Policy page that will be displayed in the pairing modal\n */\n privacyPolicyUrl?: string\n\n /**\n * A list of contracts that the DApp is using. Allows to attach human readable error messages for to error codes\n */\n errorMessages?: Record<string, Record<string | number, string>>\n\n /**\n * Configuration that is passed to the WalletConnect transport.\n *\n * This is required to enable WalletConnect connections.\n */\n walletConnectOptions?: RequireAtLeastOne<{\n /**\n * The projectId of the application. Has to be obtained from https://cloud.walletconnect.com/\n */\n projectId?: string\n\n /**\n * The relay server to connect to\n */\n relayUrl?: string\n }>\n\n /**\n * Explicitly disable the WalletConnect transport.\n *\n * WalletConnect is opt-in (it is only built when `walletConnectOptions` is\n * provided). This additive flag lets a DApp that does provide\n * `walletConnectOptions` still turn the transport off without removing that\n * configuration. When `true`, no WalletConnect transport is constructed or\n * listened to. Absence preserves current behavior. Use it for environments\n * where the WalletConnect provider cannot run (e.g. a Firefox MV3\n * content-script compartment).\n */\n disableWalletConnect?: boolean\n\n /**\n * The analytics instance that will be used by the SDK\n */\n analytics?: AnalyticsInterface\n\n /**\n * The wallets that will be featured in the UI.\n */\n featuredWallets?: string[]\n\n /**\n * Automatically switch between apps on Mobile Devices (Enabled by Default)\n */\n enableAppSwitching?: boolean\n\n /**\n * Enable metrics tracking (Disabled by Default)\n */\n enableMetrics?: boolean\n\n /**\n * Minimum
|
|
1
|
+
{"version":3,"file":"DAppClientOptions.js","sourceRoot":"","sources":["../../../src/dapp-client/DAppClientOptions.ts"],"names":[],"mappings":"","sourcesContent":["import { BeaconEvent, BeaconEventType, BeaconEventHandlerFunction } from '../events'\nimport { BlockExplorer } from '../utils/block-explorer'\nimport {\n Storage,\n NetworkType,\n ColorMode,\n NodeDistributions,\n AnalyticsInterface,\n Network\n} from '@tezos-x/octez.connect-types'\n\ntype RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> &\n {\n [K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>\n }[Keys]\n\n/**\n * @category DApp\n */\nexport interface DAppClientOptions {\n /**\n * Name of the application\n */\n name: string\n\n /**\n * Description of the application\n */\n description?: string\n\n /**\n * A URL to the icon of the application\n */\n iconUrl?: string\n\n /**\n * A URL to the website of the application\n */\n appUrl?: string\n\n /**\n * The storage that will be used by the SDK\n */\n storage?: Storage\n\n /**\n * An object that will be used to overwrite default event handler behaviour.\n *\n * If you plan to overwrite all default events, use \"disableDefaultEvents\" instead.\n *\n * This will overwrite the default event handler, so this can lead to unexpected behavior in some cases.\n * We recommend that you overwrite all handlers if you want to use your own UI.\n *\n * If you simply want to be notified of events happening, but do not want to overwrite the default behavior,\n * please use `subscribeToEvent()` on the DAppClient instead.\n */\n eventHandlers?: {\n [key in BeaconEvent]?: {\n handler: BeaconEventHandlerFunction<BeaconEventType[key]>\n }\n }\n\n /**\n * Disable all default Events and UI elements. If passed together with \"eventHandlers\",\n * the default eventHandlers will be removed, and the ones passed by the user will be added.\n */\n disableDefaultEvents?: boolean\n\n /**\n * A list of matrix nodes to connect to. If a non-empty array is passed, the default options will be overwritten.\n * One node will be randomly selected based on the local keypair and the other nodes will be used as a fallback in case the primary node goes down.\n *\n * Only provide the hostname, no https:// prefix. Eg. { [Regions.EU1]: ['matrix.example.com'] }\n */\n matrixNodes?: NodeDistributions\n\n /**\n * The block explorer used by the SDK\n */\n blockExplorer?: BlockExplorer\n\n /**\n * Indicates on which network the DApp is running on.\n */\n network?: Network\n\n /**\n * @deprecated Please use \"network\" instead.\n * Indicates on which network the DApp is planning to run. This is currently used to adjust the URLs of web-wallets in the pairing alert if they use different URLs for testnets.\n * You will still have to define the network you intend to use during the permission request.\n */\n preferredNetwork?: NetworkType\n\n /**\n * Set the color mode for the UI elements (alerts and toasts)\n */\n colorMode?: ColorMode\n\n /**\n * A URL to the Terms & Conditions page that will be displayed in the pairing modal\n */\n termsAndConditionsUrl?: string\n\n /**\n * A URL to the Privacy Policy page that will be displayed in the pairing modal\n */\n privacyPolicyUrl?: string\n\n /**\n * A list of contracts that the DApp is using. Allows to attach human readable error messages for to error codes\n */\n errorMessages?: Record<string, Record<string | number, string>>\n\n /**\n * Configuration that is passed to the WalletConnect transport.\n *\n * This is required to enable WalletConnect connections.\n */\n walletConnectOptions?: RequireAtLeastOne<{\n /**\n * The projectId of the application. Has to be obtained from https://cloud.walletconnect.com/\n */\n projectId?: string\n\n /**\n * The relay server to connect to\n */\n relayUrl?: string\n }>\n\n /**\n * Explicitly disable the WalletConnect transport.\n *\n * WalletConnect is opt-in (it is only built when `walletConnectOptions` is\n * provided). This additive flag lets a DApp that does provide\n * `walletConnectOptions` still turn the transport off without removing that\n * configuration. When `true`, no WalletConnect transport is constructed or\n * listened to. Absence preserves current behavior. Use it for environments\n * where the WalletConnect provider cannot run (e.g. a Firefox MV3\n * content-script compartment).\n */\n disableWalletConnect?: boolean\n\n /**\n * The analytics instance that will be used by the SDK\n */\n analytics?: AnalyticsInterface\n\n /**\n * The wallets that will be featured in the UI.\n */\n featuredWallets?: string[]\n\n /**\n * Automatically switch between apps on Mobile Devices (Enabled by Default)\n */\n enableAppSwitching?: boolean\n\n /**\n * Enable metrics tracking (Disabled by Default)\n */\n enableMetrics?: boolean\n\n /**\n * Minimum wallet version the dApp will accept. The gate is opt-in: it\n * defaults to the lowest supported protocol version, so every wallet the\n * SDK can talk to is accepted and upgrading the SDK never rejects existing\n * v2/v3 wallets. Set `'4'` to require the v4 multi-network protocol. Must\n * be a decimal-integer string in `[1, BEACON_VERSION]`; otherwise\n * `InvalidRequiredMinimumVersionError` is thrown at construction. A wallet\n * below this minimum is rejected with `VersionUnsupportedBeaconError` when\n * a request is sent.\n *\n * The version compared against this minimum is the wallet's EFFECTIVE\n * version, not the raw `peer.version`: legacy wallets echo the dApp's own\n * version at pairing, so a declared version is only trusted when the\n * pairing response carried the v5 `protocolVersion` capability marker —\n * marker-less wallets that declared a version count as `'2'` (and are\n * therefore rejected by a minimum of `'3'` or `'4'`, even though their\n * echoed `peer.version` may read higher). A wallet that reports no version\n * at all (WalletConnect pairings) is still treated as unknown and allowed,\n * so those pairings keep working.\n */\n requiredMinimumVersion?: string\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import bs58check from 'bs58check';
|
|
2
2
|
import { TransportType, StorageKey, BeaconMessageType, PermissionScope, NetworkType, Origin, BeaconErrorType, SigningType, ColorMode, TransportStatus } from '@tezos-x/octez.connect-types';
|
|
3
|
-
import { Client, AppMetadataManager, Serializer, LocalStorage, getAccountIdentifier, getSenderId, Logger, StorageValidator, SDK_VERSION, IndexedDBStorage, MultiTabChannel, BACKEND_URL, getError, usesWrappedMessages, buildErrorContext, UnknownBeaconError, AbortedBeaconError, compareBeaconVersion, isMultiNetworkVersion, VersionUnsupportedBeaconError, NetworksUnsupportedBeaconError, normalizeTezosCaip2, isValidTezosCaip2, networkFromTezosCaip2, networkTypeFromTezosCaip2, resolveRequiredMinimumVersion, negotiateEnvelopeVersion, wrapBeaconMessage } from '@tezos-x/octez.connect-core';
|
|
3
|
+
import { Client, AppMetadataManager, Serializer, LocalStorage, getAccountIdentifier, getSenderId, Logger, StorageValidator, SDK_VERSION, IndexedDBStorage, MultiTabChannel, BACKEND_URL, getError, usesWrappedMessages, buildErrorContext, UnknownBeaconError, AbortedBeaconError, compareBeaconVersion, isMultiNetworkVersion, VersionUnsupportedBeaconError, NetworksUnsupportedBeaconError, normalizeTezosCaip2, isValidTezosCaip2, networkFromTezosCaip2, networkTypeFromTezosCaip2, resolveRequiredMinimumVersion, negotiateEnvelopeVersion, effectivePeerVersion, MESSAGE_WRAPPED_FROM_VERSION, wrapBeaconMessage } from '@tezos-x/octez.connect-core';
|
|
4
4
|
import { TezosBlockchain } from '@tezos-x/octez.connect-blockchain-tezos';
|
|
5
5
|
import { getAddressFromPublicKey, ExposedPromise, generateGUID, toHex, signMessage, CONTRACT_PREFIX, prefixPublicKey, isValidAddress, getKeypairFromSeed } from '@tezos-x/octez.connect-utils';
|
|
6
6
|
import { PostMessageTransport } from '@tezos-x/octez.connect-transport-postmessage';
|
|
@@ -1121,7 +1121,7 @@ export class DAppClient extends Client {
|
|
|
1121
1121
|
// reading response.message.version would always miss and collapse to '0',
|
|
1122
1122
|
// misrouting v4 responses when no peer is persisted yet.
|
|
1123
1123
|
const walletPeerV3 = await this.getPeer();
|
|
1124
|
-
const walletPeerVersionV3 = walletPeerV3
|
|
1124
|
+
const walletPeerVersionV3 = effectivePeerVersion(walletPeerV3) ?? response.version;
|
|
1125
1125
|
const partialAccountInfos = await blockchain.getAccountInfosFromPermissionResponse(response.message, walletPeerVersionV3);
|
|
1126
1126
|
const blockchainDataScopes = response.message.blockchainData.scopes;
|
|
1127
1127
|
const accountInfos = partialAccountInfos.map((p) => ({
|
|
@@ -1268,10 +1268,11 @@ export class DAppClient extends Client {
|
|
|
1268
1268
|
this.sendMetrics('performance-metrics/save', await this.buildPayload('connect', 'success'));
|
|
1269
1269
|
logger.log('requestPermissions', '######## MESSAGE #######');
|
|
1270
1270
|
logger.log('requestPermissions', message);
|
|
1271
|
-
//
|
|
1272
|
-
//
|
|
1271
|
+
// Capability-aware peer version (legacy wallets echo the dApp's version
|
|
1272
|
+
// at pairing — see effectivePeerVersion); fall back to the response
|
|
1273
|
+
// envelope version when no peer is persisted yet.
|
|
1273
1274
|
const walletPeer = await this.getPeer();
|
|
1274
|
-
const walletPeerVersion = walletPeer
|
|
1275
|
+
const walletPeerVersion = effectivePeerVersion(walletPeer) ?? message.version;
|
|
1275
1276
|
// Gate the freshly-paired wallet against the dApp's required minimum (a
|
|
1276
1277
|
// no-op under the default, permissive minimum). Throws
|
|
1277
1278
|
// VersionUnsupportedBeaconError when the wallet is too old.
|
|
@@ -1861,10 +1862,15 @@ export class DAppClient extends Client {
|
|
|
1861
1862
|
return walletInfo;
|
|
1862
1863
|
}
|
|
1863
1864
|
// Throws VersionUnsupportedBeaconError when a wallet that reported a version
|
|
1864
|
-
// is below requiredMinimumVersion (or reports a malformed one).
|
|
1865
|
-
//
|
|
1866
|
-
//
|
|
1867
|
-
//
|
|
1865
|
+
// is below requiredMinimumVersion (or reports a malformed one). Callers pass
|
|
1866
|
+
// the EFFECTIVE version (see effectivePeerVersion): a declared version is
|
|
1867
|
+
// only trusted alongside the v5 `protocolVersion` pairing marker; a
|
|
1868
|
+
// marker-less wallet that declared one counts as '2' (legacy wallets echo
|
|
1869
|
+
// the dApp's version, so the raw peer.version may read deceptively high).
|
|
1870
|
+
// A peer that never reported a version (WalletConnect pairings, legacy
|
|
1871
|
+
// pairings predating versioning) is treated as unknown and allowed through,
|
|
1872
|
+
// so raising the minimum never retroactively breaks an already-paired
|
|
1873
|
+
// session on a pure read.
|
|
1868
1874
|
assertWalletVersionMeetsMinimum(walletVersion) {
|
|
1869
1875
|
if (walletVersion === undefined) {
|
|
1870
1876
|
return;
|
|
@@ -2107,13 +2113,16 @@ export class DAppClient extends Client {
|
|
|
2107
2113
|
// Enforce the dApp's required minimum before a request leaves the SDK.
|
|
2108
2114
|
// No-op under the default (permissive) minimum; otherwise rejects an
|
|
2109
2115
|
// under-minimum wallet with VersionUnsupportedBeaconError.
|
|
2110
|
-
this.assertWalletVersionMeetsMinimum(peer
|
|
2111
|
-
// The wire dialect is negotiated per peer — min(peer
|
|
2112
|
-
// BEACON_VERSION), floor '2'.
|
|
2113
|
-
//
|
|
2114
|
-
//
|
|
2115
|
-
//
|
|
2116
|
-
|
|
2116
|
+
this.assertWalletVersionMeetsMinimum(effectivePeerVersion(peer));
|
|
2117
|
+
// The wire dialect is negotiated per peer — min(effective peer version,
|
|
2118
|
+
// BEACON_VERSION), floor '2'. The effective version is capability-aware:
|
|
2119
|
+
// legacy wallets ECHO the dApp's version in their pairing response, so
|
|
2120
|
+
// peer.version alone would misread a 4.8.x wallet as v4; only peers that
|
|
2121
|
+
// sent the v5 `protocolVersion` marker are trusted. A wrapped-capable
|
|
2122
|
+
// peer receives the flat requestInput (the unchanged public shape)
|
|
2123
|
+
// mapped onto the wrapped Tezos payload; a legacy peer receives the flat
|
|
2124
|
+
// v2 message it has always spoken. Integrators never see either dialect.
|
|
2125
|
+
const negotiatedVersion = negotiateEnvelopeVersion(effectivePeerVersion(peer));
|
|
2117
2126
|
const requestSenderId = await getSenderId(await this.beaconId);
|
|
2118
2127
|
let request;
|
|
2119
2128
|
if (usesWrappedMessages(negotiatedVersion)) {
|
|
@@ -2223,14 +2232,21 @@ export class DAppClient extends Client {
|
|
|
2223
2232
|
const account = await this.getActiveAccount();
|
|
2224
2233
|
const peer = await this.getPeer(account);
|
|
2225
2234
|
// Enforce the dApp's required minimum before a request leaves the SDK.
|
|
2226
|
-
this.assertWalletVersionMeetsMinimum(peer
|
|
2235
|
+
this.assertWalletVersionMeetsMinimum(effectivePeerVersion(peer));
|
|
2236
|
+
// The envelope carries the version negotiated against the effective
|
|
2237
|
+
// (capability-aware) peer version — see effectivePeerVersion: legacy
|
|
2238
|
+
// wallets echo the dApp's version, so only peers that sent the v5
|
|
2239
|
+
// `protocolVersion` marker are trusted with the v4 dialect. Unlike
|
|
2240
|
+
// makeRequest, this path is wrapper-only (the v3 blockchainData shape
|
|
2241
|
+
// has no flat equivalent), so it floors at '3' instead of '2': a legacy
|
|
2242
|
+
// wallet routes a version-'3' wrapper through its v3 branch, whereas a
|
|
2243
|
+
// '2'-stamped wrapper would be misrouted as flat and silently dropped.
|
|
2244
|
+
const negotiatedVersion = negotiateEnvelopeVersion(effectivePeerVersion(peer));
|
|
2227
2245
|
const request = {
|
|
2228
2246
|
id: messageId,
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
// multi-network branch only when it declared v4 at pairing.
|
|
2233
|
-
version: negotiateEnvelopeVersion(peer?.version),
|
|
2247
|
+
version: usesWrappedMessages(negotiatedVersion)
|
|
2248
|
+
? negotiatedVersion
|
|
2249
|
+
: String(MESSAGE_WRAPPED_FROM_VERSION),
|
|
2234
2250
|
senderId: await getSenderId(await this.beaconId),
|
|
2235
2251
|
message: requestInput
|
|
2236
2252
|
};
|