@tezos-x/octez.connect-core 5.0.0-beta.6 → 5.0.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/cjs/package.json +3 -3
- package/dist/cjs/src/clients/client/Client.js +13 -16
- package/dist/cjs/src/clients/client/Client.js.map +1 -1
- package/dist/cjs/src/constants.js +2 -2
- package/dist/cjs/src/constants.js.map +1 -1
- package/dist/cjs/src/errors/InvalidBeaconVersionError.d.ts +17 -0
- package/dist/cjs/src/errors/InvalidBeaconVersionError.js +26 -0
- package/dist/cjs/src/errors/InvalidBeaconVersionError.js.map +1 -0
- package/dist/cjs/src/errors/InvalidRequiredMinimumVersionError.d.ts +16 -0
- package/dist/cjs/src/errors/InvalidRequiredMinimumVersionError.js +25 -0
- package/dist/cjs/src/errors/InvalidRequiredMinimumVersionError.js.map +1 -0
- package/dist/cjs/src/errors/NetworksUnsupportedBeaconError.d.ts +21 -0
- package/dist/cjs/src/errors/NetworksUnsupportedBeaconError.js +33 -0
- package/dist/cjs/src/errors/NetworksUnsupportedBeaconError.js.map +1 -0
- package/dist/cjs/src/errors/VersionUnsupportedBeaconError.d.ts +16 -0
- package/dist/cjs/src/errors/VersionUnsupportedBeaconError.js +26 -0
- package/dist/cjs/src/errors/VersionUnsupportedBeaconError.js.map +1 -0
- package/dist/cjs/src/errors/error-codes.d.ts +8 -0
- package/dist/cjs/src/errors/error-codes.js +5 -1
- package/dist/cjs/src/errors/error-codes.js.map +1 -1
- package/dist/cjs/src/index.d.ts +9 -2
- package/dist/cjs/src/index.js +28 -2
- package/dist/cjs/src/index.js.map +1 -1
- package/dist/cjs/src/managers/AccountManager.d.ts +7 -0
- package/dist/cjs/src/managers/AccountManager.js +11 -0
- package/dist/cjs/src/managers/AccountManager.js.map +1 -1
- package/dist/cjs/src/managers/PermissionManager.d.ts +7 -0
- package/dist/cjs/src/managers/PermissionManager.js +12 -0
- package/dist/cjs/src/managers/PermissionManager.js.map +1 -1
- package/dist/cjs/src/managers/PermissionValidator.js +13 -1
- package/dist/cjs/src/managers/PermissionValidator.js.map +1 -1
- package/dist/cjs/src/managers/StorageManager.d.ts +11 -0
- package/dist/cjs/src/managers/StorageManager.js +28 -0
- package/dist/cjs/src/managers/StorageManager.js.map +1 -1
- package/dist/cjs/src/utils/assert-never.d.ts +9 -2
- package/dist/cjs/src/utils/assert-never.js +21 -3
- package/dist/cjs/src/utils/assert-never.js.map +1 -1
- package/dist/cjs/src/utils/caip2.d.ts +61 -0
- package/dist/cjs/src/utils/caip2.js +93 -0
- package/dist/cjs/src/utils/caip2.js.map +1 -0
- package/dist/cjs/src/utils/get-account-identifier.js +19 -5
- package/dist/cjs/src/utils/get-account-identifier.js.map +1 -1
- package/dist/cjs/src/utils/message-utils.d.ts +94 -0
- package/dist/cjs/src/utils/message-utils.js +148 -5
- package/dist/cjs/src/utils/message-utils.js.map +1 -1
- package/dist/cjs/src/utils/required-minimum-version.d.ts +19 -0
- package/dist/cjs/src/utils/required-minimum-version.js +47 -0
- package/dist/cjs/src/utils/required-minimum-version.js.map +1 -0
- package/dist/esm/package.json +3 -3
- package/dist/esm/src/clients/client/Client.js +13 -18
- package/dist/esm/src/clients/client/Client.js.map +1 -1
- package/dist/esm/src/constants.js +2 -2
- package/dist/esm/src/constants.js.map +1 -1
- package/dist/esm/src/errors/InvalidBeaconVersionError.d.ts +17 -0
- package/dist/esm/src/errors/InvalidBeaconVersionError.js +24 -0
- package/dist/esm/src/errors/InvalidBeaconVersionError.js.map +1 -0
- package/dist/esm/src/errors/InvalidRequiredMinimumVersionError.d.ts +16 -0
- package/dist/esm/src/errors/InvalidRequiredMinimumVersionError.js +23 -0
- package/dist/esm/src/errors/InvalidRequiredMinimumVersionError.js.map +1 -0
- package/dist/esm/src/errors/NetworksUnsupportedBeaconError.d.ts +21 -0
- package/dist/esm/src/errors/NetworksUnsupportedBeaconError.js +30 -0
- package/dist/esm/src/errors/NetworksUnsupportedBeaconError.js.map +1 -0
- package/dist/esm/src/errors/VersionUnsupportedBeaconError.d.ts +16 -0
- package/dist/esm/src/errors/VersionUnsupportedBeaconError.js +25 -0
- package/dist/esm/src/errors/VersionUnsupportedBeaconError.js.map +1 -0
- package/dist/esm/src/errors/error-codes.d.ts +8 -0
- package/dist/esm/src/errors/error-codes.js +5 -1
- package/dist/esm/src/errors/error-codes.js.map +1 -1
- package/dist/esm/src/index.d.ts +9 -2
- package/dist/esm/src/index.js +9 -2
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/managers/AccountManager.d.ts +7 -0
- package/dist/esm/src/managers/AccountManager.js +9 -0
- package/dist/esm/src/managers/AccountManager.js.map +1 -1
- package/dist/esm/src/managers/PermissionManager.d.ts +7 -0
- package/dist/esm/src/managers/PermissionManager.js +10 -0
- package/dist/esm/src/managers/PermissionManager.js.map +1 -1
- package/dist/esm/src/managers/PermissionValidator.js +13 -1
- package/dist/esm/src/managers/PermissionValidator.js.map +1 -1
- package/dist/esm/src/managers/StorageManager.d.ts +11 -0
- package/dist/esm/src/managers/StorageManager.js +26 -0
- package/dist/esm/src/managers/StorageManager.js.map +1 -1
- package/dist/esm/src/utils/assert-never.d.ts +9 -2
- package/dist/esm/src/utils/assert-never.js +20 -3
- package/dist/esm/src/utils/assert-never.js.map +1 -1
- package/dist/esm/src/utils/caip2.d.ts +61 -0
- package/dist/esm/src/utils/caip2.js +82 -0
- package/dist/esm/src/utils/caip2.js.map +1 -0
- package/dist/esm/src/utils/get-account-identifier.js +19 -5
- package/dist/esm/src/utils/get-account-identifier.js.map +1 -1
- package/dist/esm/src/utils/message-utils.d.ts +94 -0
- package/dist/esm/src/utils/message-utils.js +139 -4
- package/dist/esm/src/utils/message-utils.js.map +1 -1
- package/dist/esm/src/utils/required-minimum-version.d.ts +19 -0
- package/dist/esm/src/utils/required-minimum-version.js +43 -0
- package/dist/esm/src/utils/required-minimum-version.js.map +1 -0
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":";;;;;;;AAAA;;;GAGG;AACH,oDAAgD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":";;;;;;;AAAA;;;GAGG;AACH,oDAAgD;AA8DJ,uFA9DnC,eAAM,OA8DmC;AA7DlD,sDAAkD;AAkEhD,4FAlEO,yBAAW,OAkEP;AAjEb,wEAAoE;AAmElE,qGAnEO,2CAAoB,OAmEP;AAlEtB,4FAAwF;AAmEtF,+GAnEO,+DAA8B,OAmEP;AAlEhC,wEAAoE;AAmElE,qGAnEO,2CAAoB,OAmEP;AAlEtB,8EAA0E;AAmExE,wGAnEO,iDAAuB,OAmEP;AAlEzB,0EAAsE;AAmEpE,sGAnEO,6CAAqB,OAmEP;AAlEvB,wFAAoF;AAmElF,6GAnEO,2DAA4B,OAmEP;AAlE9B,wFAAoF;AAmElF,6GAnEO,2DAA4B,OAmEP;AAlE9B,0FAAsF;AAmEpF,8GAnEO,6DAA6B,OAmEP;AAlE/B,oEAAgE;AAqE9D,mGArEO,uCAAkB,OAqEP;AApEpB,sDAAkD;AA4EzC,0FA5EA,qBAAS,OA4EA;AA3ElB,2DAAuD;AA8E9C,8FA9EA,6BAAa,OA8EA;AA7EtB,yDAAqD;AA6E7B,6FA7Ef,2BAAY,OA6Ee;AA5EpC,qDAAiD;AA4EoC,2FA5E5E,uBAAU,OA4E4E;AA3E/F,6CAAyC;AAkIhC,2FAlIA,uBAAU,OAkIA;AA/HnB,2CAOoB;AAwElB,4FA9EA,uBAAW,OA8EA;AACX,+FA9EA,0BAAc,OA8EA;AACd,oGA9EA,+BAAmB,OA8EA;AACnB,oGA9EA,+BAAmB,OA8EA;AACnB,wGA9EA,mCAAuB,OA8EA;AACvB,yGA9EA,oCAAwB,OA8EA;AA5E1B,yDAG2B;AA0EzB,mHA5EA,qDAAkC,OA4EA;AAClC,mHA5EA,qDAAkC,OA4EA;AA1Ep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BATK,mBAAQ,CASL;AA2CV,uDAU8B;AAT5B,oHAAA,mBAAmB,OAAA;AACnB,6HAAA,4BAA4B,OAAA;AAC5B,2HAAA,0BAA0B,OAAA;AAC1B,qHAAA,oBAAoB,OAAA;AACpB,iHAAA,gBAAgB,OAAA;AAChB,sHAAA,qBAAqB,OAAA;AACrB,yHAAA,wBAAwB,OAAA;AACxB,kHAAA,iBAAiB,OAAA;AACjB,oHAAA,mBAAmB,OAAA;AAErB,uCAOsB;AANpB,4GAAA,mBAAmB,OAAA;AACnB,0GAAA,iBAAiB,OAAA;AACjB,8GAAA,qBAAqB,OAAA;AACrB,kHAAA,yBAAyB,OAAA;AACzB,kHAAA,yBAAyB,OAAA;AACzB,kHAAA,yBAAyB,OAAA;AAE3B,qDAAkD;AAAzC,2GAAA,WAAW,OAAA;AACpB,6EAAgF;AAAvE,yIAAA,6BAA6B,OAAA;AAEtC,cAAc;AACd,mDAM4B;AAL1B,gHAAA,iBAAiB,OAAA;AACjB,gHAAA,iBAAiB,OAAA;AACjB,oHAAA,qBAAqB,OAAA;AACrB,0HAAA,2BAA2B,OAAA;AAC3B,qHAAA,sBAAsB,OAAA;AAGxB,cAAc;AACd,oDAAkJ;AAAzI,0GAAA,WAAW,OAAA;AAAE,6GAAA,cAAc,OAAA;AAAE,iHAAA,kBAAkB,OAAA;AAAE,6GAAA,cAAc,OAAA;AAAE,qHAAA,sBAAsB,OAAA;AAAE,iHAAA,kBAAkB,OAAA;AASpH,yCAAkE;AAAzD,oHAAA,uBAAuB,OAAA;AAAE,wGAAA,WAAW,OAAA","sourcesContent":["/**\n * General docs\n * @module public\n */\nimport { Client } from './clients/client/Client'\nimport { BeaconError } from './errors/BeaconError'\nimport { BroadcastBeaconError } from './errors/BroadcastBeaconError'\nimport { NetworkNotSupportedBeaconError } from './errors/NetworkNotSupportedBeaconError'\nimport { NoAddressBeaconError } from './errors/NoAddressBeaconError'\nimport { NoPrivateKeyBeaconError } from './errors/NoPrivateKeyBeaconError'\nimport { NotGrantedBeaconError } from './errors/NotGrantedBeaconError'\nimport { ParametersInvalidBeaconError } from './errors/ParametersInvalidBeaconError'\nimport { TooManyOperationsBeaconError } from './errors/TooManyOperationsBeaconError'\nimport { TransactionInvalidBeaconError } from './errors/TransactionInvalidBeaconError'\nimport { UnknownBeaconError } from './errors/UnknownBeaconError'\nimport { Transport } from './transports/Transport'\nimport { ChromeStorage } from './storage/ChromeStorage'\nimport { LocalStorage } from './storage/LocalStorage'\nimport { getStorage } from './storage/getStorage'\nimport { Serializer } from './Serializer'\n// import { RequestEncryptPayloadInput } from './types/RequestEncryptPayloadInput'\nimport { ClientOptions } from './clients/client/ClientOptions'\nimport {\n SDK_VERSION,\n BEACON_VERSION,\n PROTOCOL_VERSION_V1,\n PROTOCOL_VERSION_V2,\n LATEST_PROTOCOL_VERSION,\n DEFAULT_PROTOCOL_VERSION\n} from './constants'\nimport {\n getPreferredMessageProtocolVersion,\n setPreferredMessageProtocolVersion\n} from './message-protocol'\nimport { AccountManager } from './managers/AccountManager'\nimport { AppMetadataManager } from './managers/AppMetadataManager'\nimport { PermissionManager } from './managers/PermissionManager'\nimport { BeaconClient } from './clients/beacon-client/BeaconClient'\nimport { BeaconClientOptions } from './clients/beacon-client/BeaconClientOptions'\nimport { getAccountIdentifier } from './utils/get-account-identifier'\nimport { AbortedBeaconError } from './errors/AbortedBeaconError'\nimport { getSenderId } from './utils/get-sender-id'\nimport { PeerManager } from './managers/PeerManager'\nimport { MessageBasedClient } from './transports/clients/MessageBasedClient'\nimport { setDebugEnabled, getDebugEnabled } from './debug'\n// import { EncryptPayloadRequest } from './types/beacon/messages/EncryptPayloadRequest'\n// import { EncryptPayloadResponse } from './types/beacon/messages/EncryptPayloadResponse'\n// import { EncryptionTypeNotSupportedBeaconError } from './errors/EncryptionTypeNotSupportedBeaconError'\nimport { SignatureTypeNotSupportedBeaconError } from './errors/SignatureTypeNotSupportedBeaconError'\nimport { VersionUnsupportedBeaconError } from './errors/VersionUnsupportedBeaconError'\nimport { InvalidRequiredMinimumVersionError } from './errors/InvalidRequiredMinimumVersionError'\nimport { NetworksUnsupportedBeaconError } from './errors/NetworksUnsupportedBeaconError'\nimport { InvalidBeaconVersionError } from './errors/InvalidBeaconVersionError'\nimport { getLogger, Logger, setLogger } from './utils/Logger'\nimport { windowRef } from './MockWindow'\nimport { CommunicationClient } from './transports/clients/CommunicationClient'\nimport { ClientEvents } from './transports/clients/ClientEvents'\nimport { WCStorage } from './storage/WCStorage'\nimport { IndexedDBStorage } from './storage/IndexedDBStorage'\nimport { StorageValidator } from './storage/StorageValidator'\nimport { MultiTabChannel } from './utils/multi-tab-channel'\nimport getError from './errors/get-error'\n// import { EncryptionType } from './types/EncryptionType'\n// import { EncryptionOperation } from './types/EncryptionOperation'\n\n// Clients\nexport { BeaconClient, BeaconClientOptions, Client, ClientOptions, ClientEvents }\n\n// Errors\nexport {\n getError,\n BeaconError,\n AbortedBeaconError,\n BroadcastBeaconError,\n NetworkNotSupportedBeaconError,\n NoAddressBeaconError,\n NoPrivateKeyBeaconError,\n NotGrantedBeaconError,\n ParametersInvalidBeaconError,\n TooManyOperationsBeaconError,\n TransactionInvalidBeaconError,\n SignatureTypeNotSupportedBeaconError,\n // EncryptionTypeNotSupportedBeaconError,\n UnknownBeaconError,\n VersionUnsupportedBeaconError,\n InvalidRequiredMinimumVersionError,\n NetworksUnsupportedBeaconError,\n InvalidBeaconVersionError\n}\n\n// Transport\nexport { Transport, MessageBasedClient, CommunicationClient }\n\n// Storage\nexport { ChromeStorage, LocalStorage, WCStorage, IndexedDBStorage, StorageValidator, getStorage }\n\n// Managers\nexport { PeerManager, AccountManager, AppMetadataManager, PermissionManager }\n\n// Constants\nexport {\n SDK_VERSION,\n BEACON_VERSION,\n PROTOCOL_VERSION_V1,\n PROTOCOL_VERSION_V2,\n LATEST_PROTOCOL_VERSION,\n DEFAULT_PROTOCOL_VERSION,\n getPreferredMessageProtocolVersion,\n setPreferredMessageProtocolVersion\n}\n\n// Utils\nexport { getSenderId, getAccountIdentifier, windowRef, MultiTabChannel }\nexport {\n usesWrappedMessages,\n MESSAGE_WRAPPED_FROM_VERSION,\n MULTI_NETWORK_FROM_VERSION,\n compareBeaconVersion,\n isAtLeastVersion,\n isMultiNetworkVersion,\n negotiateEnvelopeVersion,\n wrapBeaconMessage,\n unwrapBeaconMessage\n} from './utils/message-utils'\nexport {\n normalizeTezosCaip2,\n isValidTezosCaip2,\n networkFromTezosCaip2,\n TEZOS_NETWORK_GENESIS_IDS,\n tezosCaip2FromNetworkType,\n networkTypeFromTezosCaip2\n} from './utils/caip2'\nexport { assertNever } from './utils/assert-never'\nexport { resolveRequiredMinimumVersion } from './utils/required-minimum-version'\n\n// Diagnostics\nexport {\n gatherDiagnostics,\n buildErrorContext,\n serializeErrorContext,\n copyErrorContextToClipboard,\n SENSITIVE_STORAGE_KEYS\n} from './utils/diagnostics'\n\n// Error codes\nexport { ERROR_CODES, WC_ERROR_CODES, MATRIX_ERROR_CODES, PM_ERROR_CODES, BLOCKCHAIN_ERROR_CODES, BEACON_ERROR_CODES } from './errors/error-codes'\nexport type { ErrorCode } from './errors/error-codes'\n\n// Others\nexport { Serializer, Logger, setLogger, getLogger }\n\n// Debug\nexport { setDebugEnabled, getDebugEnabled }\n\nexport { NOTIFICATION_ORACLE_URL, BACKEND_URL } from './constants'\n"]}
|
|
@@ -10,6 +10,13 @@ export declare class AccountManager {
|
|
|
10
10
|
getAccounts(): Promise<AccountInfo[]>;
|
|
11
11
|
getAccount(accountIdentifier: string): Promise<AccountInfo | undefined>;
|
|
12
12
|
addAccount(accountInfo: AccountInfo): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Persist several accounts in a single read-modify-write cycle. Behaves like
|
|
15
|
+
* calling {@link addAccount} for each entry (dedupe/overwrite by
|
|
16
|
+
* `accountIdentifier`) but touches storage once. Used by the v4 multi-network
|
|
17
|
+
* permission flow, which materialises one account per requested network.
|
|
18
|
+
*/
|
|
19
|
+
addAccounts(accountInfos: AccountInfo[]): Promise<void>;
|
|
13
20
|
updateAccount(accountIdentifier: string, accountInfo: Partial<AccountInfo>): Promise<AccountInfo | undefined>;
|
|
14
21
|
removeAccount(accountIdentifier: string): Promise<void>;
|
|
15
22
|
removeAccounts(accountIdentifiers: string[]): Promise<void>;
|
|
@@ -38,6 +38,17 @@ class AccountManager {
|
|
|
38
38
|
return this.storageManager.addOne(accountInfo, (account) => account.accountIdentifier === accountInfo.accountIdentifier);
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Persist several accounts in a single read-modify-write cycle. Behaves like
|
|
43
|
+
* calling {@link addAccount} for each entry (dedupe/overwrite by
|
|
44
|
+
* `accountIdentifier`) but touches storage once. Used by the v4 multi-network
|
|
45
|
+
* permission flow, which materialises one account per requested network.
|
|
46
|
+
*/
|
|
47
|
+
addAccounts(accountInfos) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
return this.storageManager.addMany(accountInfos, (stored, incoming) => stored.accountIdentifier === incoming.accountIdentifier);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
41
52
|
updateAccount(accountIdentifier, accountInfo) {
|
|
42
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
54
|
const account = yield this.getAccount(accountIdentifier);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountManager.js","sourceRoot":"","sources":["../../../../src/managers/AccountManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sEAA8F;AAC9F,qDAAiD;AACjD,+DAA2D;AAE3D;;;;GAIG;AACH,MAAa,cAAc;IAGzB,YAAY,OAAgB;QAC1B,IAAI,CAAC,cAAc,GAAG,IAAI,+BAAc,CAAC,OAAO,EAAE,gCAAU,CAAC,QAAQ,CAAC,CAAA;IACxE,CAAC;IAEY,WAAW;;;YACtB,OAAO,MAAA,CAAC,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC,mCAAI,EAAE,CAA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A;QACH,CAAC;KAAA;IAEY,aAAa,CACxB,iBAAyB,EACzB,WAAiC;;YAEjC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAA;YAExD,IAAI,CAAC,OAAO;gBAAE,OAAO,SAAS,CAAA;YAE9B,MAAM,UAAU,mCAAQ,OAAO,GAAK,WAAW,CAAE,CAAA;YACjD,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,CAC9B,UAAU,EACV,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,iBAAiB,KAAK,iBAAiB,EAC5D,IAAI,CACL,CAAA;YAED,OAAO,UAAU,CAAA;QACnB,CAAC;KAAA;IAEY,aAAa,CAAC,iBAAyB;;YAClD,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,iBAAiB,KAAK,iBAAiB,CAAC,CAAA;QACjG,CAAC;KAAA;IAEY,cAAc,CAAC,kBAA4B;;YACtD,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAC5C,kBAAkB,CAAC,QAAQ,CAAC,OAAO,CAAC,iBAAiB,CAAC,CACvD,CAAA;QACH,CAAC;KAAA;IAEY,iBAAiB;;YAC5B,OAAO,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,CAAA;QACxC,CAAC;KAAA;IAEY,aAAa,CAAC,OAAsB;;YAC/C,OAAO,yCAAmB,CAAC,aAAa,CACtC,OAAO,EACP,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAC1B,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAC5B,CAAA;QACH,CAAC;KAAA;CACF;AA1ED,wCA0EC","sourcesContent":["import { Storage, StorageKey, AccountInfo, BeaconMessage } from '@tezos-x/octez.connect-types'\nimport { StorageManager } from './StorageManager'\nimport { PermissionValidator } from './PermissionValidator'\n\n/**\n * @internalapi\n *\n * The AccountManager provides CRUD functionality for account entities and persists them to the provided storage.\n */\nexport class AccountManager {\n private readonly storageManager: StorageManager<StorageKey.ACCOUNTS>\n\n constructor(storage: Storage) {\n this.storageManager = new StorageManager(storage, StorageKey.ACCOUNTS)\n }\n\n public async getAccounts(): Promise<AccountInfo[]> {\n return (await this.storageManager.getAll()) ?? []\n }\n\n public async getAccount(accountIdentifier: string): Promise<AccountInfo | undefined> {\n return this.storageManager.getOne((account) => account.accountIdentifier === accountIdentifier)\n }\n\n public async addAccount(accountInfo: AccountInfo): Promise<void> {\n return this.storageManager.addOne(\n accountInfo,\n (account) => account.accountIdentifier === accountInfo.accountIdentifier\n )\n }\n\n /**\n * Persist several accounts in a single read-modify-write cycle. Behaves like\n * calling {@link addAccount} for each entry (dedupe/overwrite by\n * `accountIdentifier`) but touches storage once. Used by the v4 multi-network\n * permission flow, which materialises one account per requested network.\n */\n public async addAccounts(accountInfos: AccountInfo[]): Promise<void> {\n return this.storageManager.addMany(\n accountInfos,\n (stored, incoming) => stored.accountIdentifier === incoming.accountIdentifier\n )\n }\n\n public async updateAccount(\n accountIdentifier: string,\n accountInfo: Partial<AccountInfo>\n ): Promise<AccountInfo | undefined> {\n const account = await this.getAccount(accountIdentifier)\n\n if (!account) return undefined\n\n const newAccount = { ...account, ...accountInfo }\n await this.storageManager.addOne(\n newAccount,\n (account) => account.accountIdentifier === accountIdentifier,\n true\n )\n\n return newAccount\n }\n\n public async removeAccount(accountIdentifier: string): Promise<void> {\n return this.storageManager.remove((account) => account.accountIdentifier === accountIdentifier)\n }\n\n public async removeAccounts(accountIdentifiers: string[]): Promise<void> {\n return this.storageManager.remove((account) =>\n accountIdentifiers.includes(account.accountIdentifier)\n )\n }\n\n public async removeAllAccounts(): Promise<void> {\n return this.storageManager.removeAll()\n }\n\n public async hasPermission(message: BeaconMessage): Promise<boolean> {\n return PermissionValidator.hasPermission(\n message,\n this.getAccount.bind(this),\n this.getAccounts.bind(this)\n )\n }\n}\n"]}
|
|
@@ -10,6 +10,13 @@ export declare class PermissionManager {
|
|
|
10
10
|
getPermissions(): Promise<PermissionInfo[]>;
|
|
11
11
|
getPermission(accountIdentifier: string): Promise<PermissionInfo | undefined>;
|
|
12
12
|
addPermission(permissionInfo: PermissionInfo): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Persist several permissions in one read-modify-write cycle. Required for
|
|
15
|
+
* the v4 multi-network fanout (N permissions from one response): N
|
|
16
|
+
* concurrent `addPermission` calls race on the shared permission list and
|
|
17
|
+
* the last write clobbers the others.
|
|
18
|
+
*/
|
|
19
|
+
addPermissions(permissionInfos: PermissionInfo[]): Promise<void>;
|
|
13
20
|
removePermission(accountIdentifier: string, senderId: string): Promise<void>;
|
|
14
21
|
removePermissions(accountIdentifiers: string[]): Promise<void>;
|
|
15
22
|
removeAllPermissions(): Promise<void>;
|
|
@@ -39,6 +39,18 @@ class PermissionManager {
|
|
|
39
39
|
permission.senderId === permissionInfo.senderId);
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Persist several permissions in one read-modify-write cycle. Required for
|
|
44
|
+
* the v4 multi-network fanout (N permissions from one response): N
|
|
45
|
+
* concurrent `addPermission` calls race on the shared permission list and
|
|
46
|
+
* the last write clobbers the others.
|
|
47
|
+
*/
|
|
48
|
+
addPermissions(permissionInfos) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
return this.storageManager.addMany(permissionInfos, (stored, incoming) => stored.accountIdentifier === incoming.accountIdentifier &&
|
|
51
|
+
stored.senderId === incoming.senderId);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
42
54
|
removePermission(accountIdentifier, senderId) {
|
|
43
55
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44
56
|
return this.storageManager.remove((permission) => permission.accountIdentifier === accountIdentifier && permission.senderId === senderId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PermissionManager.js","sourceRoot":"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AAO,CAChC,eAAe,EACf,CAAC,MAAsB,EAAE,QAAwB,EAAE,EAAE,CACnD,MAAM,CAAC,iBAAiB,KAAK,QAAQ,CAAC,iBAAiB;gBACvD,MAAM,CAAC,QAAQ,KAAK,QAAQ,CAAC,QAAQ,CACxC,CAAA;QACH,CAAC;KAAA;IAEY,gBAAgB,CAAC,iBAAyB,EAAE,QAAgB;;YACvE,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,CAC/B,CAAC,UAA0B,EAAE,EAAE,CAC7B,UAAU,CAAC,iBAAiB,KAAK,iBAAiB,IAAI,UAAU,CAAC,QAAQ,KAAK,QAAQ,CACzF,CAAA;QACH,CAAC;KAAA;IAEY,iBAAiB,CAAC,kBAA4B;;YACzD,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,UAA0B,EAAE,EAAE,CAC/D,kBAAkB,CAAC,QAAQ,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAC1D,CAAA;QACH,CAAC;KAAA;IAEY,oBAAoB;;YAC/B,OAAO,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,CAAA;QACxC,CAAC;KAAA;IAEY,aAAa,CAAC,OAAsB;;YAC/C,OAAO,yCAAmB,CAAC,aAAa,CACtC,OAAO,EACP,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAC7B,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAC/B,CAAA;QACH,CAAC;KAAA;CACF;AAjED,8CAiEC","sourcesContent":["import { BeaconMessage, Storage, StorageKey, PermissionInfo } from '@tezos-x/octez.connect-types'\nimport { StorageManager } from './StorageManager'\nimport { PermissionValidator } from './PermissionValidator'\n\n/**\n * @internalapi\n *\n * The PermissionManager provides CRUD functionality for permission entities and persists them to the provided storage.\n */\nexport class PermissionManager {\n private readonly storageManager: StorageManager<StorageKey.PERMISSION_LIST>\n\n constructor(storage: Storage) {\n this.storageManager = new StorageManager(storage, StorageKey.PERMISSION_LIST)\n }\n\n public async getPermissions(): Promise<PermissionInfo[]> {\n return (await this.storageManager.getAll()) ?? []\n }\n\n public async getPermission(accountIdentifier: string): Promise<PermissionInfo | undefined> {\n return this.storageManager.getOne(\n (permission: PermissionInfo) => permission.accountIdentifier === accountIdentifier\n )\n }\n\n public async addPermission(permissionInfo: PermissionInfo): Promise<void> {\n return this.storageManager.addOne(\n permissionInfo,\n (permission: PermissionInfo) =>\n permission.accountIdentifier === permissionInfo.accountIdentifier &&\n permission.senderId === permissionInfo.senderId\n )\n }\n\n /**\n * Persist several permissions in one read-modify-write cycle. Required for\n * the v4 multi-network fanout (N permissions from one response): N\n * concurrent `addPermission` calls race on the shared permission list and\n * the last write clobbers the others.\n */\n public async addPermissions(permissionInfos: PermissionInfo[]): Promise<void> {\n return this.storageManager.addMany(\n permissionInfos,\n (stored: PermissionInfo, incoming: PermissionInfo) =>\n stored.accountIdentifier === incoming.accountIdentifier &&\n stored.senderId === incoming.senderId\n )\n }\n\n public async removePermission(accountIdentifier: string, senderId: string): Promise<void> {\n return this.storageManager.remove(\n (permission: PermissionInfo) =>\n permission.accountIdentifier === accountIdentifier && permission.senderId === senderId\n )\n }\n\n public async removePermissions(accountIdentifiers: string[]): Promise<void> {\n return this.storageManager.remove((permission: PermissionInfo) =>\n accountIdentifiers.includes(permission.accountIdentifier)\n )\n }\n\n public async removeAllPermissions(): Promise<void> {\n return this.storageManager.removeAll()\n }\n\n public async hasPermission(message: BeaconMessage): Promise<boolean> {\n return PermissionValidator.hasPermission(\n message,\n this.getPermission.bind(this),\n this.getPermissions.bind(this)\n )\n }\n}\n"]}
|
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.PermissionValidator = void 0;
|
|
13
13
|
const octez_connect_types_1 = require("@tezos-x/octez.connect-types");
|
|
14
14
|
const get_account_identifier_1 = require("../utils/get-account-identifier");
|
|
15
|
+
const caip2_1 = require("../utils/caip2");
|
|
15
16
|
/**
|
|
16
17
|
* @internalapi
|
|
17
18
|
*
|
|
@@ -33,7 +34,18 @@ class PermissionValidator {
|
|
|
33
34
|
return true;
|
|
34
35
|
}
|
|
35
36
|
case octez_connect_types_1.BeaconMessageType.OperationRequest: {
|
|
36
|
-
|
|
37
|
+
// operation_request.network is now `Network | string`: on the v4 path
|
|
38
|
+
// the wire carries a CAIP-2 string, which we coerce to the minimal
|
|
39
|
+
// Network used to derive the account identifier (same helper the
|
|
40
|
+
// permission-storage side uses, so the two ids match). Normalize first:
|
|
41
|
+
// the wire accepts both the bare reference (`NetX…`) and the full
|
|
42
|
+
// `tezos:NetX…` form, but permissions were stored under the normalized
|
|
43
|
+
// (prefixed) chainId, so a bare reference must be prefixed before the
|
|
44
|
+
// identifier is derived or the lookup misses a valid grant.
|
|
45
|
+
const networkForId = typeof message.network === 'string'
|
|
46
|
+
? (0, caip2_1.networkFromTezosCaip2)((0, caip2_1.normalizeTezosCaip2)(message.network))
|
|
47
|
+
: message.network;
|
|
48
|
+
const accountIdentifier = yield (0, get_account_identifier_1.getAccountIdentifier)(message.sourceAddress, networkForId);
|
|
37
49
|
const permission = yield getOne(accountIdentifier);
|
|
38
50
|
if (!permission) {
|
|
39
51
|
return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PermissionValidator.js","sourceRoot":"","sources":["../../../../src/managers/PermissionValidator.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"PermissionValidator.js","sourceRoot":"","sources":["../../../../src/managers/PermissionValidator.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sEAMqC;AACrC,4EAAsE;AACtE,0CAA2E;AAE3E;;;;GAIG;AACH,MAAa,mBAAmB;IAC9B;;;;;;OAMG;IACI,MAAM,CAAO,aAAa,CAC/B,OAAsB,EACtB,MAA6D,EAC7D,MAAyC;;YAEzC,QAAQ,OAAO,CAAC,IAAI,EAAE,CAAC;gBACrB,KAAK,uCAAiB,CAAC,iBAAi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M,CAAC,QAAQ,CAAC,qCAAe,CAAC,IAAI,CAAC,CACjD,CAAA;gBACH,CAAC;gBACD;oBACE,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;YAC1C,CAAC;QACH,CAAC;KAAA;CACF;AA7DD,kDA6DC","sourcesContent":["import {\n BeaconMessage,\n BeaconMessageType,\n Network,\n PermissionScope,\n PermissionEntity\n} from '@tezos-x/octez.connect-types'\nimport { getAccountIdentifier } from '../utils/get-account-identifier'\nimport { networkFromTezosCaip2, normalizeTezosCaip2 } from '../utils/caip2'\n\n/**\n * @internalapi\n *\n * The PermissionValidator is used to check if permissions for a certain message type have been given\n */\nexport class PermissionValidator {\n /**\n * Check if permissions were given for a certain message type.\n *\n * PermissionRequest and BroadcastRequest will always return true.\n *\n * @param message octez.connect message\n */\n public static async hasPermission(\n message: BeaconMessage,\n getOne: (id: string) => Promise<PermissionEntity | undefined>,\n getAll: () => Promise<PermissionEntity[]>\n ): Promise<boolean> {\n switch (message.type) {\n case BeaconMessageType.PermissionRequest:\n case BeaconMessageType.BroadcastRequest: {\n return true\n }\n case BeaconMessageType.OperationRequest: {\n // operation_request.network is now `Network | string`: on the v4 path\n // the wire carries a CAIP-2 string, which we coerce to the minimal\n // Network used to derive the account identifier (same helper the\n // permission-storage side uses, so the two ids match). Normalize first:\n // the wire accepts both the bare reference (`NetX…`) and the full\n // `tezos:NetX…` form, but permissions were stored under the normalized\n // (prefixed) chainId, so a bare reference must be prefixed before the\n // identifier is derived or the lookup misses a valid grant.\n const networkForId: Network =\n typeof message.network === 'string'\n ? networkFromTezosCaip2(normalizeTezosCaip2(message.network))\n : message.network\n const accountIdentifier: string = await getAccountIdentifier(\n message.sourceAddress,\n networkForId\n )\n\n const permission: PermissionEntity | undefined = await getOne(accountIdentifier)\n if (!permission) {\n return false\n }\n\n return permission.scopes.includes(PermissionScope.OPERATION_REQUEST)\n }\n case BeaconMessageType.SignPayloadRequest: {\n const permissions: PermissionEntity[] = await getAll()\n const filteredPermissions: PermissionEntity[] = permissions.filter(\n (permission: PermissionEntity) => permission.address === message.sourceAddress\n )\n\n if (filteredPermissions.length === 0) {\n return false\n }\n\n return filteredPermissions.some((permission: PermissionEntity) =>\n permission.scopes.includes(PermissionScope.SIGN)\n )\n }\n default:\n throw new Error('Message not handled')\n }\n }\n}\n"]}
|
|
@@ -13,6 +13,17 @@ export declare class StorageManager<T extends StorageKey.ACCOUNTS | StorageKey.A
|
|
|
13
13
|
getAll(): Promise<StorageKeyReturnType[T]>;
|
|
14
14
|
getOne(predicate: (element: ArrayElem<StorageKeyReturnType[T]>) => boolean): Promise<ArrayElem<StorageKeyReturnType[T]> | undefined>;
|
|
15
15
|
addOne(element: ArrayElem<StorageKeyReturnType[T]>, predicate: (element: ArrayElem<StorageKeyReturnType[T]>) => boolean, overwrite?: boolean): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Insert or update many elements in a single read-modify-write cycle.
|
|
18
|
+
*
|
|
19
|
+
* Equivalent to calling {@link addOne} for each element, but reads and writes
|
|
20
|
+
* storage once instead of once per element. Elements are reconciled against
|
|
21
|
+
* the store AND against earlier elements in the same batch (so a duplicate
|
|
22
|
+
* within `elements` collapses to one), using `match(stored, incoming)` to
|
|
23
|
+
* decide identity. Used for the v4 multi-network fanout, which persists one
|
|
24
|
+
* account per requested network from a single permission response.
|
|
25
|
+
*/
|
|
26
|
+
addMany(elements: ArrayElem<StorageKeyReturnType[T]>[], match: (stored: ArrayElem<StorageKeyReturnType[T]>, incoming: ArrayElem<StorageKeyReturnType[T]>) => boolean, overwrite?: boolean): Promise<void>;
|
|
16
27
|
remove(predicate: (element: ArrayElem<StorageKeyReturnType[T]>) => boolean): Promise<void>;
|
|
17
28
|
removeAll(): Promise<void>;
|
|
18
29
|
}
|
|
@@ -54,6 +54,34 @@ class StorageManager {
|
|
|
54
54
|
return this.storage.set(this.storageKey, entities);
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Insert or update many elements in a single read-modify-write cycle.
|
|
59
|
+
*
|
|
60
|
+
* Equivalent to calling {@link addOne} for each element, but reads and writes
|
|
61
|
+
* storage once instead of once per element. Elements are reconciled against
|
|
62
|
+
* the store AND against earlier elements in the same batch (so a duplicate
|
|
63
|
+
* within `elements` collapses to one), using `match(stored, incoming)` to
|
|
64
|
+
* decide identity. Used for the v4 multi-network fanout, which persists one
|
|
65
|
+
* account per requested network from a single permission response.
|
|
66
|
+
*/
|
|
67
|
+
addMany(elements_1, match_1) {
|
|
68
|
+
return __awaiter(this, arguments, void 0, function* (elements, match, overwrite = true) {
|
|
69
|
+
if (elements.length === 0) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const entities = yield this.storage.get(this.storageKey);
|
|
73
|
+
for (const element of elements) {
|
|
74
|
+
const index = fixArrayType(entities).findIndex((existing) => match(existing, element));
|
|
75
|
+
if (index === -1) {
|
|
76
|
+
fixArrayType(entities).push(element);
|
|
77
|
+
}
|
|
78
|
+
else if (overwrite) {
|
|
79
|
+
entities[index] = element;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return this.storage.set(this.storageKey, entities);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
57
85
|
remove(predicate) {
|
|
58
86
|
return __awaiter(this, void 0, void 0, function* () {
|
|
59
87
|
const entities = yield this.storage.get(this.storageKey);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageManager.js","sourceRoot":"","sources":["../../../../src/managers/StorageManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,wDAAwD;AACxD,SAAS,YAAY,CAAI,KAAQ;IAC/B,8DAA8D;IAC9D,OAAO,KAAY,CAAA;AACrB,CAAC;AACD,uDAAuD;AAEvD;;;;GAIG;AACH,MAAa,cAAc;IAczB,YAAY,OAAgB,EAAE,UAAa;QACzC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;IAC9B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qBAAM,IAAI,SAAS,EAAE,CAAC;oBACrB,QAAQ,CAAC,KAAK,CAAC,GAAG,OAAO,CAAA;gBAC3B,CAAC;YACH,CAAC;YAED,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;QACpD,CAAC;KAAA;IAEY,MAAM,CACjB,SAAmE;;YAEnE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;YAExD,MAAM,gBAAgB,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAA;YAEtF,8DAA8D;YAC9D,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,gBAAuB,CAAC,CAAA;QACnE,CAAC;KAAA;IAEY,SAAS;;YACpB,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QAC7C,CAAC;KAAA;CACF;AArGD,wCAqGC","sourcesContent":["import { StorageKey, Storage, StorageKeyReturnType } from '@tezos-x/octez.connect-types'\n\n/** Type workaround for https://github.com/Microsoft/TypeScript/issues/7294#issuecomment-465794460 */\nexport type ArrayElem<A> = A extends (infer Elem)[] ? Elem : never\n\n/* eslint-disable prefer-arrow/prefer-arrow-functions */\nfunction fixArrayType<T>(array: T): ArrayElem<T>[] {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return array as any\n}\n/* eslint-enable prefer-arrow/prefer-arrow-functions */\n\n/**\n * @internalapi\n *\n * The StorageManager provides CRUD functionality for specific entities and persists them to the provided storage.\n */\nexport class StorageManager<\n T extends\n | StorageKey.ACCOUNTS\n | StorageKey.APP_METADATA_LIST\n | StorageKey.PERMISSION_LIST\n | StorageKey.TRANSPORT_P2P_PEERS_DAPP\n | StorageKey.TRANSPORT_P2P_PEERS_WALLET\n | StorageKey.TRANSPORT_POSTMESSAGE_PEERS_DAPP\n | StorageKey.TRANSPORT_POSTMESSAGE_PEERS_WALLET\n | StorageKey.TRANSPORT_WALLETCONNECT_PEERS_DAPP\n> {\n private readonly storage: Storage\n private readonly storageKey: T\n\n constructor(storage: Storage, storageKey: T) {\n this.storage = storage\n this.storageKey = storageKey\n }\n\n public async getAll(): Promise<StorageKeyReturnType[T]> {\n return (await this.storage.get(this.storageKey)) ?? []\n }\n\n public async getOne(\n predicate: (element: ArrayElem<StorageKeyReturnType[T]>) => boolean\n ): Promise<ArrayElem<StorageKeyReturnType[T]> | undefined> {\n const entities = await this.storage.get(this.storageKey)\n\n return fixArrayType(entities).find(predicate)\n }\n\n public async addOne(\n element: ArrayElem<StorageKeyReturnType[T]>,\n predicate: (element: ArrayElem<StorageKeyReturnType[T]>) => boolean,\n overwrite: boolean = true\n ): Promise<void> {\n const entities = await this.storage.get(this.storageKey)\n\n if (!fixArrayType(entities).some(predicate)) {\n fixArrayType(entities).push(element)\n } else if (overwrite) {\n for (let i = 0; i < entities.length; i++) {\n if (predicate(fixArrayType(entities)[i])) {\n entities[i] = element\n }\n }\n }\n\n return this.storage.set(this.storageKey, entities)\n }\n\n /**\n * Insert or update many elements in a single read-modify-write cycle.\n *\n * Equivalent to calling {@link addOne} for each element, but reads and writes\n * storage once instead of once per element. Elements are reconciled against\n * the store AND against earlier elements in the same batch (so a duplicate\n * within `elements` collapses to one), using `match(stored, incoming)` to\n * decide identity. Used for the v4 multi-network fanout, which persists one\n * account per requested network from a single permission response.\n */\n public async addMany(\n elements: ArrayElem<StorageKeyReturnType[T]>[],\n match: (\n stored: ArrayElem<StorageKeyReturnType[T]>,\n incoming: ArrayElem<StorageKeyReturnType[T]>\n ) => boolean,\n overwrite: boolean = true\n ): Promise<void> {\n if (elements.length === 0) {\n return\n }\n\n const entities = await this.storage.get(this.storageKey)\n\n for (const element of elements) {\n const index = fixArrayType(entities).findIndex((existing) => match(existing, element))\n if (index === -1) {\n fixArrayType(entities).push(element)\n } else if (overwrite) {\n entities[index] = element\n }\n }\n\n return this.storage.set(this.storageKey, entities)\n }\n\n public async remove(\n predicate: (element: ArrayElem<StorageKeyReturnType[T]>) => boolean\n ): Promise<void> {\n const entities = await this.storage.get(this.storageKey)\n\n const filteredEntities = fixArrayType(entities).filter((entity) => !predicate(entity))\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return this.storage.set(this.storageKey, filteredEntities as any)\n }\n\n public async removeAll(): Promise<void> {\n return this.storage.delete(this.storageKey)\n }\n}\n"]}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Exhaustiveness guard for if/else chains and switch/cases.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Compile time: passing anything but `never` is a type error, so adding a new
|
|
5
|
+
* union member without handling it fails to build. Runtime: an untrusted value
|
|
6
|
+
* (e.g. an unknown message or error type from the wire) can still reach the
|
|
7
|
+
* default branch, so throw an actionable error naming that value instead of
|
|
8
|
+
* silently returning — callers previously received `undefined` and failed
|
|
9
|
+
* later with no context.
|
|
10
|
+
*
|
|
11
|
+
* @param empty The value that should be unreachable
|
|
5
12
|
*/
|
|
6
13
|
export declare function assertNever(empty: never): never;
|
|
@@ -3,12 +3,30 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.assertNever = assertNever;
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Exhaustiveness guard for if/else chains and switch/cases.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* Compile time: passing anything but `never` is a type error, so adding a new
|
|
9
|
+
* union member without handling it fails to build. Runtime: an untrusted value
|
|
10
|
+
* (e.g. an unknown message or error type from the wire) can still reach the
|
|
11
|
+
* default branch, so throw an actionable error naming that value instead of
|
|
12
|
+
* silently returning — callers previously received `undefined` and failed
|
|
13
|
+
* later with no context.
|
|
14
|
+
*
|
|
15
|
+
* @param empty The value that should be unreachable
|
|
9
16
|
*/
|
|
10
17
|
function assertNever(empty) {
|
|
11
|
-
|
|
18
|
+
var _a;
|
|
19
|
+
let repr;
|
|
20
|
+
try {
|
|
21
|
+
repr = (_a = JSON.stringify(empty)) !== null && _a !== void 0 ? _a : String(empty);
|
|
22
|
+
}
|
|
23
|
+
catch (_b) {
|
|
24
|
+
repr = String(empty);
|
|
25
|
+
}
|
|
26
|
+
if (repr.length > 200) {
|
|
27
|
+
repr = `${repr.slice(0, 200)}…`;
|
|
28
|
+
}
|
|
29
|
+
throw new Error(`assertNever: reached unreachable case with unexpected value: ${repr}`);
|
|
12
30
|
}
|
|
13
31
|
/* eslint-enable prefer-arrow/prefer-arrow-functions */
|
|
14
32
|
//# sourceMappingURL=assert-never.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert-never.js","sourceRoot":"","sources":["../../../../src/utils/assert-never.ts"],"names":[],"mappings":";AAAA,wDAAwD;;
|
|
1
|
+
{"version":3,"file":"assert-never.js","sourceRoot":"","sources":["../../../../src/utils/assert-never.ts"],"names":[],"mappings":";AAAA,wDAAwD;;AAcxD,kCAYC;AAxBD;;;;;;;;;;;GAWG;AACH,SAAgB,WAAW,CAAC,KAAY;;IACtC,IAAI,IAAY,CAAA;IAChB,IAAI,CAAC;QACH,IAAI,GAAG,MAAA,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,mCAAI,MAAM,CAAC,KAAK,CAAC,CAAA;IAC/C,CAAC;IAAC,WAAM,CAAC;QACP,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;IACtB,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;QACtB,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,CAAA;IACjC,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,gEAAgE,IAAI,EAAE,CAAC,CAAA;AACzF,CAAC;AAED,uDAAuD","sourcesContent":["/* eslint-disable prefer-arrow/prefer-arrow-functions */\n\n/**\n * Exhaustiveness guard for if/else chains and switch/cases.\n *\n * Compile time: passing anything but `never` is a type error, so adding a new\n * union member without handling it fails to build. Runtime: an untrusted value\n * (e.g. an unknown message or error type from the wire) can still reach the\n * default branch, so throw an actionable error naming that value instead of\n * silently returning — callers previously received `undefined` and failed\n * later with no context.\n *\n * @param empty The value that should be unreachable\n */\nexport function assertNever(empty: never): never {\n let repr: string\n try {\n repr = JSON.stringify(empty) ?? String(empty)\n } catch {\n repr = String(empty)\n }\n if (repr.length > 200) {\n repr = `${repr.slice(0, 200)}…`\n }\n\n throw new Error(`assertNever: reached unreachable case with unexpected value: ${repr}`)\n}\n\n/* eslint-enable prefer-arrow/prefer-arrow-functions */\n"]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CAIP-2 chain id helpers, scoped to the Tezos namespace (`tezos:<reference>`).
|
|
3
|
+
*
|
|
4
|
+
* The wire format accepts both the bare reference (`NetXsqzbfFenSTS`) and the
|
|
5
|
+
* full CAIP-2 string (`tezos:NetXsqzbfFenSTS`); SDK code consistently stores
|
|
6
|
+
* and routes on the full form.
|
|
7
|
+
*/
|
|
8
|
+
import { Network, NetworkType } from '@tezos-x/octez.connect-types';
|
|
9
|
+
/**
|
|
10
|
+
* Returns `chainId` with the `tezos:` prefix added if absent. No validation
|
|
11
|
+
* is performed; use `isValidTezosCaip2` at API boundaries.
|
|
12
|
+
*/
|
|
13
|
+
export declare const normalizeTezosCaip2: (chainId: string) => string;
|
|
14
|
+
/**
|
|
15
|
+
* Whether `value` is a syntactically valid Tezos CAIP-2 chain id
|
|
16
|
+
* (`tezos:<alphanumeric reference>`).
|
|
17
|
+
*/
|
|
18
|
+
export declare const isValidTezosCaip2: (value: string) => boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Build the minimal `Network` for a Tezos CAIP-2 chain id. Single source of
|
|
21
|
+
* truth for the `{ type: CUSTOM, chainId, ... }` shape, so the network used
|
|
22
|
+
* to derive an account identifier is constructed identically everywhere
|
|
23
|
+
* (permission storage, operation-request lookup, stale-scheme scan). `name`
|
|
24
|
+
* defaults to the chain id when the wallet supplies no human label.
|
|
25
|
+
*/
|
|
26
|
+
export declare const networkFromTezosCaip2: (chainId: string, opts?: {
|
|
27
|
+
name?: string;
|
|
28
|
+
rpcUrl?: string;
|
|
29
|
+
}) => Network;
|
|
30
|
+
/**
|
|
31
|
+
* Canonical NetworkType → genesis chain id (CAIP-2 reference) table.
|
|
32
|
+
*
|
|
33
|
+
* Applied ONLY at boundaries that must translate between the named-network
|
|
34
|
+
* vocabulary (WalletConnect session namespaces use `tezos:<name>`) and the
|
|
35
|
+
* genesis-keyed CAIP-2 vocabulary of the beacon v4 multi-network protocol.
|
|
36
|
+
*
|
|
37
|
+
* Sourcing rule: ids are read from the network's own RPC
|
|
38
|
+
* (`/chains/main/chain_id`) and locked by unit test — never guessed. Networks
|
|
39
|
+
* without an entry are not statically mappable and multi-network requests for
|
|
40
|
+
* them can only travel over transports that pass chain ids through opaquely
|
|
41
|
+
* (P2P/postmessage):
|
|
42
|
+
* - WEEKLYNET / DAILYNET rotate their genesis on every reset.
|
|
43
|
+
* - CUSTOM has no fixed genesis by definition.
|
|
44
|
+
* - TALLINNNET / SEOULNET / TEZLINK_SHADOWNET / TEZOSX_PREVIEWNET /
|
|
45
|
+
* TEZOSX_SHADOWNET currently publish no queryable RPC in the teztnets
|
|
46
|
+
* registry; add their ids here (RPC-sourced) when available.
|
|
47
|
+
* If a long-running network relaunches with a new genesis, its entry must be
|
|
48
|
+
* updated in the same change that bumps the supported network.
|
|
49
|
+
*/
|
|
50
|
+
export declare const TEZOS_NETWORK_GENESIS_IDS: Partial<Record<NetworkType, string>>;
|
|
51
|
+
/**
|
|
52
|
+
* Full CAIP-2 chain id (`tezos:NetX…`) for a named network, or `undefined`
|
|
53
|
+
* when the network has no statically known genesis (see
|
|
54
|
+
* {@link TEZOS_NETWORK_GENESIS_IDS}).
|
|
55
|
+
*/
|
|
56
|
+
export declare const tezosCaip2FromNetworkType: (type: NetworkType) => string | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Named network for a CAIP-2 chain id (bare or `tezos:`-prefixed), or
|
|
59
|
+
* `undefined` when the id does not belong to a statically mapped network.
|
|
60
|
+
*/
|
|
61
|
+
export declare const networkTypeFromTezosCaip2: (chainId: string) => NetworkType | undefined;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.networkTypeFromTezosCaip2 = exports.tezosCaip2FromNetworkType = exports.TEZOS_NETWORK_GENESIS_IDS = exports.networkFromTezosCaip2 = exports.isValidTezosCaip2 = exports.normalizeTezosCaip2 = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* CAIP-2 chain id helpers, scoped to the Tezos namespace (`tezos:<reference>`).
|
|
6
|
+
*
|
|
7
|
+
* The wire format accepts both the bare reference (`NetXsqzbfFenSTS`) and the
|
|
8
|
+
* full CAIP-2 string (`tezos:NetXsqzbfFenSTS`); SDK code consistently stores
|
|
9
|
+
* and routes on the full form.
|
|
10
|
+
*/
|
|
11
|
+
const octez_connect_types_1 = require("@tezos-x/octez.connect-types");
|
|
12
|
+
const TEZOS_CAIP2_PREFIX = 'tezos:';
|
|
13
|
+
const TEZOS_CAIP2_RE = /^tezos:[A-Za-z0-9]+$/;
|
|
14
|
+
/**
|
|
15
|
+
* Returns `chainId` with the `tezos:` prefix added if absent. No validation
|
|
16
|
+
* is performed; use `isValidTezosCaip2` at API boundaries.
|
|
17
|
+
*/
|
|
18
|
+
const normalizeTezosCaip2 = (chainId) => chainId.startsWith(TEZOS_CAIP2_PREFIX) ? chainId : `${TEZOS_CAIP2_PREFIX}${chainId}`;
|
|
19
|
+
exports.normalizeTezosCaip2 = normalizeTezosCaip2;
|
|
20
|
+
/**
|
|
21
|
+
* Whether `value` is a syntactically valid Tezos CAIP-2 chain id
|
|
22
|
+
* (`tezos:<alphanumeric reference>`).
|
|
23
|
+
*/
|
|
24
|
+
const isValidTezosCaip2 = (value) => TEZOS_CAIP2_RE.test(value);
|
|
25
|
+
exports.isValidTezosCaip2 = isValidTezosCaip2;
|
|
26
|
+
/**
|
|
27
|
+
* Build the minimal `Network` for a Tezos CAIP-2 chain id. Single source of
|
|
28
|
+
* truth for the `{ type: CUSTOM, chainId, ... }` shape, so the network used
|
|
29
|
+
* to derive an account identifier is constructed identically everywhere
|
|
30
|
+
* (permission storage, operation-request lookup, stale-scheme scan). `name`
|
|
31
|
+
* defaults to the chain id when the wallet supplies no human label.
|
|
32
|
+
*/
|
|
33
|
+
const networkFromTezosCaip2 = (chainId, opts) => {
|
|
34
|
+
var _a;
|
|
35
|
+
return ({
|
|
36
|
+
type: octez_connect_types_1.NetworkType.CUSTOM,
|
|
37
|
+
name: (_a = opts === null || opts === void 0 ? void 0 : opts.name) !== null && _a !== void 0 ? _a : chainId,
|
|
38
|
+
rpcUrl: opts === null || opts === void 0 ? void 0 : opts.rpcUrl,
|
|
39
|
+
chainId
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
exports.networkFromTezosCaip2 = networkFromTezosCaip2;
|
|
43
|
+
/**
|
|
44
|
+
* Canonical NetworkType → genesis chain id (CAIP-2 reference) table.
|
|
45
|
+
*
|
|
46
|
+
* Applied ONLY at boundaries that must translate between the named-network
|
|
47
|
+
* vocabulary (WalletConnect session namespaces use `tezos:<name>`) and the
|
|
48
|
+
* genesis-keyed CAIP-2 vocabulary of the beacon v4 multi-network protocol.
|
|
49
|
+
*
|
|
50
|
+
* Sourcing rule: ids are read from the network's own RPC
|
|
51
|
+
* (`/chains/main/chain_id`) and locked by unit test — never guessed. Networks
|
|
52
|
+
* without an entry are not statically mappable and multi-network requests for
|
|
53
|
+
* them can only travel over transports that pass chain ids through opaquely
|
|
54
|
+
* (P2P/postmessage):
|
|
55
|
+
* - WEEKLYNET / DAILYNET rotate their genesis on every reset.
|
|
56
|
+
* - CUSTOM has no fixed genesis by definition.
|
|
57
|
+
* - TALLINNNET / SEOULNET / TEZLINK_SHADOWNET / TEZOSX_PREVIEWNET /
|
|
58
|
+
* TEZOSX_SHADOWNET currently publish no queryable RPC in the teztnets
|
|
59
|
+
* registry; add their ids here (RPC-sourced) when available.
|
|
60
|
+
* If a long-running network relaunches with a new genesis, its entry must be
|
|
61
|
+
* updated in the same change that bumps the supported network.
|
|
62
|
+
*/
|
|
63
|
+
exports.TEZOS_NETWORK_GENESIS_IDS = {
|
|
64
|
+
[octez_connect_types_1.NetworkType.MAINNET]: 'NetXdQprcVkpaWU',
|
|
65
|
+
[octez_connect_types_1.NetworkType.GHOSTNET]: 'NetXnHfVqm9iesp',
|
|
66
|
+
[octez_connect_types_1.NetworkType.SHADOWNET]: 'NetXsqzbfFenSTS',
|
|
67
|
+
// Tezos X L2 (Michelson runtime) mainnet. Maintainer-supplied id — no
|
|
68
|
+
// public RPC was reachable at the time of adding; re-verify against
|
|
69
|
+
// `/chains/main/chain_id` once one ships.
|
|
70
|
+
[octez_connect_types_1.NetworkType.TEZOSX_MAINNET]: 'NetXohUVN5QWR4f',
|
|
71
|
+
[octez_connect_types_1.NetworkType.USHUAIANET]: 'NetXpX8WSZkAZZA'
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Full CAIP-2 chain id (`tezos:NetX…`) for a named network, or `undefined`
|
|
75
|
+
* when the network has no statically known genesis (see
|
|
76
|
+
* {@link TEZOS_NETWORK_GENESIS_IDS}).
|
|
77
|
+
*/
|
|
78
|
+
const tezosCaip2FromNetworkType = (type) => {
|
|
79
|
+
const genesis = exports.TEZOS_NETWORK_GENESIS_IDS[type];
|
|
80
|
+
return genesis === undefined ? undefined : `${TEZOS_CAIP2_PREFIX}${genesis}`;
|
|
81
|
+
};
|
|
82
|
+
exports.tezosCaip2FromNetworkType = tezosCaip2FromNetworkType;
|
|
83
|
+
/**
|
|
84
|
+
* Named network for a CAIP-2 chain id (bare or `tezos:`-prefixed), or
|
|
85
|
+
* `undefined` when the id does not belong to a statically mapped network.
|
|
86
|
+
*/
|
|
87
|
+
const networkTypeFromTezosCaip2 = (chainId) => {
|
|
88
|
+
const normalized = (0, exports.normalizeTezosCaip2)(chainId);
|
|
89
|
+
const reference = normalized.slice(TEZOS_CAIP2_PREFIX.length);
|
|
90
|
+
return Object.keys(exports.TEZOS_NETWORK_GENESIS_IDS).find((type) => exports.TEZOS_NETWORK_GENESIS_IDS[type] === reference);
|
|
91
|
+
};
|
|
92
|
+
exports.networkTypeFromTezosCaip2 = networkTypeFromTezosCaip2;
|
|
93
|
+
//# sourceMappingURL=caip2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"caip2.js","sourceRoot":"","sources":["../../../../src/utils/caip2.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,sEAAmE;AAEnE,MAAM,kBAAkB,GAAG,QAAQ,CAAA;AAEnC,MAAM,cAAc,GAAG,sBAAsB,CAAA;AAE7C;;;GAGG;AACI,MAAM,mBAAmB,GAAG,CAAC,OAAe,EAAU,EAAE,CAC7D,OAAO,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,kBAAkB,GAAG,OAAO,EAAE,CAAA;AADzE,QAAA,mBAAmB,uBACsD;AAEtF;;;GAGG;AACI,MAAM,iBAAiB,GAAG,CAAC,KAAa,EAAW,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AAA1E,QAAA,iBAAiB,qBAAyD;AAEvF;;;;;;GAMG;AACI,MAAM,qBAAqB,GAAG,CACnC,OAAe,EACf,IAAyC,EAChC,EAAE;;IAAC,OAAA,CAAC;QACb,IAAI,EAAE,iCAAW,CAAC,MAAM;QACxB,IAAI,EAAE,MAAA,IAAI,aAAJ,IAAI,u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yB,6BAOrC","sourcesContent":["/**\n * CAIP-2 chain id helpers, scoped to the Tezos namespace (`tezos:<reference>`).\n *\n * The wire format accepts both the bare reference (`NetXsqzbfFenSTS`) and the\n * full CAIP-2 string (`tezos:NetXsqzbfFenSTS`); SDK code consistently stores\n * and routes on the full form.\n */\nimport { Network, NetworkType } from '@tezos-x/octez.connect-types'\n\nconst TEZOS_CAIP2_PREFIX = 'tezos:'\n\nconst TEZOS_CAIP2_RE = /^tezos:[A-Za-z0-9]+$/\n\n/**\n * Returns `chainId` with the `tezos:` prefix added if absent. No validation\n * is performed; use `isValidTezosCaip2` at API boundaries.\n */\nexport const normalizeTezosCaip2 = (chainId: string): string =>\n chainId.startsWith(TEZOS_CAIP2_PREFIX) ? chainId : `${TEZOS_CAIP2_PREFIX}${chainId}`\n\n/**\n * Whether `value` is a syntactically valid Tezos CAIP-2 chain id\n * (`tezos:<alphanumeric reference>`).\n */\nexport const isValidTezosCaip2 = (value: string): boolean => TEZOS_CAIP2_RE.test(value)\n\n/**\n * Build the minimal `Network` for a Tezos CAIP-2 chain id. Single source of\n * truth for the `{ type: CUSTOM, chainId, ... }` shape, so the network used\n * to derive an account identifier is constructed identically everywhere\n * (permission storage, operation-request lookup, stale-scheme scan). `name`\n * defaults to the chain id when the wallet supplies no human label.\n */\nexport const networkFromTezosCaip2 = (\n chainId: string,\n opts?: { name?: string; rpcUrl?: string }\n): Network => ({\n type: NetworkType.CUSTOM,\n name: opts?.name ?? chainId,\n rpcUrl: opts?.rpcUrl,\n chainId\n})\n\n/**\n * Canonical NetworkType → genesis chain id (CAIP-2 reference) table.\n *\n * Applied ONLY at boundaries that must translate between the named-network\n * vocabulary (WalletConnect session namespaces use `tezos:<name>`) and the\n * genesis-keyed CAIP-2 vocabulary of the beacon v4 multi-network protocol.\n *\n * Sourcing rule: ids are read from the network's own RPC\n * (`/chains/main/chain_id`) and locked by unit test — never guessed. Networks\n * without an entry are not statically mappable and multi-network requests for\n * them can only travel over transports that pass chain ids through opaquely\n * (P2P/postmessage):\n * - WEEKLYNET / DAILYNET rotate their genesis on every reset.\n * - CUSTOM has no fixed genesis by definition.\n * - TALLINNNET / SEOULNET / TEZLINK_SHADOWNET / TEZOSX_PREVIEWNET /\n * TEZOSX_SHADOWNET currently publish no queryable RPC in the teztnets\n * registry; add their ids here (RPC-sourced) when available.\n * If a long-running network relaunches with a new genesis, its entry must be\n * updated in the same change that bumps the supported network.\n */\nexport const TEZOS_NETWORK_GENESIS_IDS: Partial<Record<NetworkType, string>> = {\n [NetworkType.MAINNET]: 'NetXdQprcVkpaWU',\n [NetworkType.GHOSTNET]: 'NetXnHfVqm9iesp',\n [NetworkType.SHADOWNET]: 'NetXsqzbfFenSTS',\n // Tezos X L2 (Michelson runtime) mainnet. Maintainer-supplied id — no\n // public RPC was reachable at the time of adding; re-verify against\n // `/chains/main/chain_id` once one ships.\n [NetworkType.TEZOSX_MAINNET]: 'NetXohUVN5QWR4f',\n [NetworkType.USHUAIANET]: 'NetXpX8WSZkAZZA'\n}\n\n/**\n * Full CAIP-2 chain id (`tezos:NetX…`) for a named network, or `undefined`\n * when the network has no statically known genesis (see\n * {@link TEZOS_NETWORK_GENESIS_IDS}).\n */\nexport const tezosCaip2FromNetworkType = (type: NetworkType): string | undefined => {\n const genesis = TEZOS_NETWORK_GENESIS_IDS[type]\n\n return genesis === undefined ? undefined : `${TEZOS_CAIP2_PREFIX}${genesis}`\n}\n\n/**\n * Named network for a CAIP-2 chain id (bare or `tezos:`-prefixed), or\n * `undefined` when the id does not belong to a statically mapped network.\n */\nexport const networkTypeFromTezosCaip2 = (chainId: string): NetworkType | undefined => {\n const normalized = normalizeTezosCaip2(chainId)\n const reference = normalized.slice(TEZOS_CAIP2_PREFIX.length)\n\n return (Object.keys(TEZOS_NETWORK_GENESIS_IDS) as NetworkType[]).find(\n (type) => TEZOS_NETWORK_GENESIS_IDS[type] === reference\n )\n}\n"]}
|
|
@@ -25,12 +25,26 @@ const utf8_1 = require("@stablelib/utf8");
|
|
|
25
25
|
* @param network
|
|
26
26
|
*/
|
|
27
27
|
const getAccountIdentifier = (address, network) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
// v4 multi-network accounts carry a CAIP-2 chainId. Key the identifier on
|
|
29
|
+
// (address, chainId) alone: chainId is the canonical, stable network key,
|
|
30
|
+
// whereas the human-facing `name`/`rpcUrl` differ between the wallet's
|
|
31
|
+
// permission response and the dApp's later operation requests. Including
|
|
32
|
+
// them would make the persisted identifier irreproducible at lookup time
|
|
33
|
+
// (and collapse distinct chains that happen to share a name). Legacy
|
|
34
|
+
// accounts (no chainId) keep the original scheme so their already-persisted
|
|
35
|
+
// identifiers are unchanged.
|
|
36
|
+
const data = [];
|
|
37
|
+
if (network.chainId) {
|
|
38
|
+
data.push(address, `chainId:${network.chainId}`);
|
|
31
39
|
}
|
|
32
|
-
|
|
33
|
-
data.push(
|
|
40
|
+
else {
|
|
41
|
+
data.push(address, network.type);
|
|
42
|
+
if (network.name) {
|
|
43
|
+
data.push(`name:${network.name}`);
|
|
44
|
+
}
|
|
45
|
+
if (network.rpcUrl) {
|
|
46
|
+
data.push(`rpc:${network.rpcUrl}`);
|
|
47
|
+
}
|
|
34
48
|
}
|
|
35
49
|
const buffer = Buffer.from((0, blake2b_1.hash)((0, utf8_1.encode)(data.join('-')), 10));
|
|
36
50
|
return bs58check_1.default.encode(buffer);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-account-identifier.js","sourceRoot":"","sources":["../../../../src/utils/get-account-identifier.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0DAAiC;AAEjC,gDAAyC;AACzC,0CAAwC;AAExC;;;;;;;GAOG;AACI,MAAM,oBAAoB,GAAG,CAAO,OAAe,EAAE,OAAgB,EAAmB,EAAE;IAC/F,MAAM,IAAI,GAAa,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"get-account-identifier.js","sourceRoot":"","sources":["../../../../src/utils/get-account-identifier.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0DAAiC;AAEjC,gDAAyC;AACzC,0CAAwC;AAExC;;;;;;;GAOG;AACI,MAAM,oBAAoB,GAAG,CAAO,OAAe,EAAE,OAAgB,EAAmB,EAAE;IAC/F,0EAA0E;IAC1E,0EAA0E;IAC1E,uEAAuE;IACvE,yEAAyE;IACzE,yEAAyE;IACzE,qEAAqE;IACrE,4EAA4E;IAC5E,6BAA6B;IAC7B,MAAM,IAAI,GAAa,EAAE,CAAA;IACzB,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACpB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,OAAO,CAAC,OAAO,EAAE,CAAC,CAAA;IAClD,CAAC;SAAM,CAAC;QACN,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;QAChC,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;YACjB,IAAI,CAAC,IAAI,CAAC,QAAQ,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;QACnC,CAAC;QACD,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACnB,IAAI,CAAC,IAAI,CAAC,OAAO,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;QACpC,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,IAAA,cAAI,EAAC,IAAA,aAAM,EAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;IAE5D,OAAO,mBAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;AACjC,CAAC,CAAA,CAAA;AAzBY,QAAA,oBAAoB,wBAyBhC","sourcesContent":["import bs58check from 'bs58check'\nimport { Network } from '@tezos-x/octez.connect-types'\nimport { hash } from '@stablelib/blake2b'\nimport { encode } from '@stablelib/utf8'\n\n/**\n * @internalapi\n *\n * Generate a deterministic account identifier based on an address and a network\n *\n * @param address\n * @param network\n */\nexport const getAccountIdentifier = async (address: string, network: Network): Promise<string> => {\n // v4 multi-network accounts carry a CAIP-2 chainId. Key the identifier on\n // (address, chainId) alone: chainId is the canonical, stable network key,\n // whereas the human-facing `name`/`rpcUrl` differ between the wallet's\n // permission response and the dApp's later operation requests. Including\n // them would make the persisted identifier irreproducible at lookup time\n // (and collapse distinct chains that happen to share a name). Legacy\n // accounts (no chainId) keep the original scheme so their already-persisted\n // identifiers are unchanged.\n const data: string[] = []\n if (network.chainId) {\n data.push(address, `chainId:${network.chainId}`)\n } else {\n data.push(address, network.type)\n if (network.name) {\n data.push(`name:${network.name}`)\n }\n if (network.rpcUrl) {\n data.push(`rpc:${network.rpcUrl}`)\n }\n }\n\n const buffer = Buffer.from(hash(encode(data.join('-')), 10))\n\n return bs58check.encode(buffer)\n}\n"]}
|