@tezos-x/octez.connect-core 4.8.4 → 4.8.5
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/clients/client/Client.d.ts +6 -1
- package/dist/cjs/clients/client/Client.js +17 -4
- package/dist/cjs/clients/client/Client.js.map +1 -1
- package/dist/cjs/constants.js +1 -1
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/errors/PeerUnreachableBeaconError.d.ts +9 -0
- package/dist/cjs/errors/PeerUnreachableBeaconError.js +17 -0
- package/dist/cjs/errors/PeerUnreachableBeaconError.js.map +1 -0
- package/dist/cjs/errors/get-error.js +3 -0
- package/dist/cjs/errors/get-error.js.map +1 -1
- package/dist/cjs/index.d.ts +2 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/storage/ChromeStorage.js +6 -15
- package/dist/cjs/storage/ChromeStorage.js.map +1 -1
- package/dist/cjs/storage/IndexedDBStorage.js +8 -1
- package/dist/cjs/storage/IndexedDBStorage.js.map +1 -1
- package/dist/cjs/storage/LocalStorage.js +5 -16
- package/dist/cjs/storage/LocalStorage.js.map +1 -1
- package/dist/cjs/storage/WCStorage.d.ts +1 -2
- package/dist/cjs/storage/WCStorage.js +40 -19
- package/dist/cjs/storage/WCStorage.js.map +1 -1
- package/dist/cjs/storage/storage-normalization.d.ts +9 -0
- package/dist/cjs/storage/storage-normalization.js +135 -0
- package/dist/cjs/storage/storage-normalization.js.map +1 -0
- package/dist/cjs/transports/Transport.js +6 -2
- package/dist/cjs/transports/Transport.js.map +1 -1
- package/dist/cjs/utils/multi-tab-channel.d.ts +1 -0
- package/dist/cjs/utils/multi-tab-channel.js +15 -0
- package/dist/cjs/utils/multi-tab-channel.js.map +1 -1
- package/dist/esm/clients/client/Client.d.ts +6 -1
- package/dist/esm/clients/client/Client.js +17 -4
- package/dist/esm/clients/client/Client.js.map +1 -1
- package/dist/esm/constants.js +1 -1
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/errors/PeerUnreachableBeaconError.d.ts +9 -0
- package/dist/esm/errors/PeerUnreachableBeaconError.js +13 -0
- package/dist/esm/errors/PeerUnreachableBeaconError.js.map +1 -0
- package/dist/esm/errors/get-error.js +3 -0
- package/dist/esm/errors/get-error.js.map +1 -1
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/storage/ChromeStorage.js +6 -15
- package/dist/esm/storage/ChromeStorage.js.map +1 -1
- package/dist/esm/storage/IndexedDBStorage.js +8 -1
- package/dist/esm/storage/IndexedDBStorage.js.map +1 -1
- package/dist/esm/storage/LocalStorage.js +6 -17
- package/dist/esm/storage/LocalStorage.js.map +1 -1
- package/dist/esm/storage/WCStorage.d.ts +1 -2
- package/dist/esm/storage/WCStorage.js +40 -17
- package/dist/esm/storage/WCStorage.js.map +1 -1
- package/dist/esm/storage/storage-normalization.d.ts +9 -0
- package/dist/esm/storage/storage-normalization.js +128 -0
- package/dist/esm/storage/storage-normalization.js.map +1 -0
- package/dist/esm/transports/Transport.js +6 -2
- package/dist/esm/transports/Transport.js.map +1 -1
- package/dist/esm/utils/multi-tab-channel.d.ts +1 -0
- package/dist/esm/utils/multi-tab-channel.js +13 -0
- package/dist/esm/utils/multi-tab-channel.js.map +1 -1
- package/package.json +3 -3
|
@@ -4,6 +4,10 @@ import { BeaconClient } from '../beacon-client/BeaconClient';
|
|
|
4
4
|
import { AccountManager } from '../../managers/AccountManager';
|
|
5
5
|
import { ClientOptions } from './ClientOptions';
|
|
6
6
|
import { Transport } from '../../transports/Transport';
|
|
7
|
+
interface TransportCleanupTarget {
|
|
8
|
+
readonly type: TransportType;
|
|
9
|
+
removeListener(listener: (message: string, connectionInfo: ConnectionContext) => void): Promise<void>;
|
|
10
|
+
}
|
|
7
11
|
/**
|
|
8
12
|
* @internalapi
|
|
9
13
|
*
|
|
@@ -38,7 +42,7 @@ export declare abstract class Client extends BeaconClient {
|
|
|
38
42
|
*/
|
|
39
43
|
get ready(): Promise<void>;
|
|
40
44
|
constructor(config: ClientOptions);
|
|
41
|
-
protected cleanup(): Promise<void>;
|
|
45
|
+
protected cleanup(transports?: TransportCleanupTarget[]): Promise<void>;
|
|
42
46
|
/**
|
|
43
47
|
* Return all locally known accounts
|
|
44
48
|
*/
|
|
@@ -89,3 +93,4 @@ export declare abstract class Client extends BeaconClient {
|
|
|
89
93
|
protected addListener(transport: Transport<any>): Promise<void>;
|
|
90
94
|
protected sendDisconnectToPeer(peer: PeerInfo, transport?: Transport<any>): Promise<void>;
|
|
91
95
|
}
|
|
96
|
+
export {};
|
|
@@ -64,16 +64,29 @@ class Client extends BeaconClient_1.BeaconClient {
|
|
|
64
64
|
throw new Error(`not overwritten${JSON.stringify(message)} - ${JSON.stringify(connectionInfo)}`);
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
|
-
cleanup() {
|
|
67
|
+
cleanup(transports) {
|
|
68
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
69
|
if (!this.transportListeners.size) {
|
|
70
70
|
return;
|
|
71
71
|
}
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
if (!transports) {
|
|
73
|
+
if (this._transport.isResolved()) {
|
|
74
|
+
const transport = yield this.transport;
|
|
75
|
+
yield Promise.all(Array.from(this.transportListeners.values()).map((listener) => transport.removeListener(listener)));
|
|
76
|
+
}
|
|
75
77
|
this.transportListeners.clear();
|
|
78
|
+
return;
|
|
76
79
|
}
|
|
80
|
+
// Explicit transport cleanup is scoped: callers tearing down secondary
|
|
81
|
+
// transports should not unregister listeners for transports left alive.
|
|
82
|
+
yield Promise.all(transports.map((transport) => __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
const listener = this.transportListeners.get(transport.type);
|
|
84
|
+
if (!listener) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
yield transport.removeListener(listener);
|
|
88
|
+
this.transportListeners.delete(transport.type);
|
|
89
|
+
})));
|
|
77
90
|
});
|
|
78
91
|
}
|
|
79
92
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Client.js","sourceRoot":"","sources":["../../../../src/clients/client/Client.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sEAA2E;AAC3E,sEAaqC;AACrC,gEAA4D;AAC5D,kEAA8D;AAC9D,6DAAuD;AACvD,+CAA2C;AAG3C,iDAA6C;AAE7C,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC,QAAQ,CAAC,CAAA;AAEnC;;;;;GAKG;AACH,MAAsB,MAAO,SAAQ,2BAAY;IA8B/C,IAAc,SAAS;QACrB,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAA;IAChC,CAAC;IAED;;OAEG;IACH,IAAW,gBAAgB;;QACzB,OAAO,MAAA,MAAA,IAAI,CAAC,UAAU,CAAC,aAAa,0CAAE,gBAAgB,mCAAI,qCAAe,CAAC,aAAa,CAAA;IACzF,CAAC;IAED;;OAEG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;IAC7C,CAAC;IAED,YAAY,MAAqB;;QAC/B,KAAK,CAAC,MAAM,CAAC,CAAA;QAzCf;;WAEG;QACgB,cAAS,GAAW,CAAC,CAAA;QACxC;;WAEG;QACgB,6BAAwB,GAAW,CAAC,CAAA;QAEvD;;WAEG;QACO,mBAAc,GAAa,EAAE,CAAA;QAI/B,uBAAkB,GAGtB,IAAI,GAAG,EAAE,CAAA;QAEH,eAAU,GAAmC,IAAI,oCAAc,EAAE,CAAA;QAsBzE,IAAI,CAAC,cAAc,GAAG,IAAI,+BAAc,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QACxD,IAAI,CAAC,WAAW,GAAG,MAAA,MAAM,CAAC,WAAW,mCAAI,EAAE,CAAA;QAE3C,IAAI,CAAC,cAAc,GAAG,CACpB,O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AAE,CAAC;oBAChC,MAAM,mBAAmB,GAAG,CAAC,MAAM,IAAI,uBAAU,EAAE,CAAC,WAAW,CAC7D,OAAO,CACR,CAAyB,CAAA;oBAC1B,IAAI,CAAC,cAAc,CAAC,mBAAmB,EAAE,cAAc,CAAC,CAAA;gBAC1D,CAAC;YACH,CAAC,CAAA,CAAA;YAED,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;YAEzD,SAAS,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC,CAAA;QAC1F,CAAC;KAAA;IAEe,oBAAoB,CAAC,IAAc,EAAE,SAA0B;;YAC7E,MAAM,OAAO,GAAsB;gBACjC,EAAE,EAAE,MAAM,IAAA,kCAAY,GAAE;gBACxB,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,QAAQ,EAAE,MAAM,IAAA,2BAAW,EAAC,MAAM,IAAI,CAAC,QAAQ,CAAC;gBAChD,IAAI,EAAE,uCAAiB,CAAC,UAAU;aACnC,CAAA;YAED,MAAM,OAAO,GAAG,MAAM,IAAI,uBAAU,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;YACzD,MAAM,iBAAiB,GAAG,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,CAAA;YAE7D,MAAM,iBAAiB,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QAC7C,CAAC;KAAA;CACF;AA1OD,wBA0OC","sourcesContent":["import { ExposedPromise, generateGUID } from '@tezos-x/octez.connect-utils'\nimport {\n ConnectionContext,\n TransportType,\n TransportStatus,\n BeaconBaseMessage,\n AccountInfo,\n PeerInfo,\n BeaconMessageType,\n DisconnectMessage,\n AppMetadata,\n BeaconRequestMessage,\n BeaconMessageWrapper,\n NodeDistributions\n} from '@tezos-x/octez.connect-types'\nimport { BeaconClient } from '../beacon-client/BeaconClient'\nimport { AccountManager } from '../../managers/AccountManager'\nimport { getSenderId } from '../../utils/get-sender-id'\nimport { Logger } from '../../utils/Logger'\nimport { ClientOptions } from './ClientOptions'\nimport { Transport } from '../../transports/Transport'\nimport { Serializer } from '../../Serializer'\n\nconst logger = new Logger('Client')\n\n/**\n * @internalapi\n *\n * This abstract class handles the a big part of the logic that is shared between the dapp and wallet client.\n * For example, it selects and manages the transport and accounts.\n */\nexport abstract class Client extends BeaconClient {\n protected readonly accountManager: AccountManager\n\n protected handleResponse: (\n _event: BeaconRequestMessage | BeaconMessageWrapper<BeaconBaseMessage>,\n connectionInfo: ConnectionContext\n ) => void\n\n /**\n * How many requests can be sent after another\n */\n protected readonly rateLimit: number = 2\n /**\n * The time window in seconds in which the \"rateLimit\" is checked\n */\n protected readonly rateLimitWindowInSeconds: number = 5\n\n /**\n * Stores the times when requests have been made to determine if the rate limit has been reached\n */\n protected requestCounter: number[] = []\n\n protected readonly matrixNodes: NodeDistributions\n\n private transportListeners: Map<\n TransportType,\n (message: any, connectionInfo: ConnectionContext) => Promise<void>\n > = new Map()\n\n protected _transport: ExposedPromise<Transport<any>> = new ExposedPromise()\n protected get transport(): Promise<Transport<any>> {\n return this._transport.promise\n }\n\n /**\n * Returns the connection status of the Client\n */\n public get connectionStatus(): TransportStatus {\n return this._transport.promiseResult?.connectionStatus ?? TransportStatus.NOT_CONNECTED\n }\n\n /**\n * Returns whether or not the transaport is ready\n */\n public get ready(): Promise<void> {\n return this.transport.then(() => undefined)\n }\n\n constructor(config: ClientOptions) {\n super(config)\n\n this.accountManager = new AccountManager(config.storage)\n this.matrixNodes = config.matrixNodes ?? {}\n\n this.handleResponse = (\n message: BeaconBaseMessage | BeaconMessageWrapper<BeaconBaseMessage>,\n connectionInfo: ConnectionContext\n ): void => {\n throw new Error(\n `not overwritten${JSON.stringify(message)} - ${JSON.stringify(connectionInfo)}`\n )\n }\n }\n protected async cleanup() {\n if (!this.transportListeners.size) {\n return\n }\n\n if (this._transport.isResolved()) {\n const transport = await this.transport\n await Promise.all(\n Array.from(this.transportListeners.values()).map((listener) =>\n transport.removeListener(listener)\n )\n )\n this.transportListeners.clear()\n }\n }\n\n /**\n * Return all locally known accounts\n */\n public async getAccounts(): Promise<AccountInfo[]> {\n return this.accountManager.getAccounts()\n }\n\n /**\n * Return the account by ID\n * @param accountIdentifier The ID of an account\n */\n public async getAccount(accountIdentifier: string): Promise<AccountInfo | undefined> {\n return this.accountManager.getAccount(accountIdentifier)\n }\n\n /**\n * Remove the account by ID\n * @param accountIdentifier The ID of an account\n */\n public async removeAccount(accountIdentifier: string): Promise<void> {\n return this.accountManager.removeAccount(accountIdentifier)\n }\n\n /**\n * Remove all locally stored accounts\n */\n public async removeAllAccounts(): Promise<void> {\n return this.accountManager.removeAllAccounts()\n }\n\n /**\n * Add a new request (current timestamp) to the pending requests, remove old ones and check if we are above the limit\n */\n public async addRequestAndCheckIfRateLimited(): Promise<boolean> {\n const now: number = new Date().getTime()\n this.requestCounter = this.requestCounter.filter(\n (date) => date + this.rateLimitWindowInSeconds * 1000 > now\n )\n\n this.requestCounter.push(now)\n\n return this.requestCounter.length > this.rateLimit\n }\n\n /**\n * This method initializes the client. It will check if the connection should be established to a\n * browser extension or if the P2P transport should be used.\n *\n * @param transport A transport that can be provided by the user\n */\n public async init(transport: Transport<any>): Promise<TransportType> {\n if (this._transport.isResolved()) {\n return (await this.transport).type\n }\n\n await this.setTransport(transport) // Let users define their own transport\n\n return transport.type\n }\n\n /**\n * Returns the metadata of this DApp\n */\n public async getOwnAppMetadata(): Promise<AppMetadata> {\n return {\n senderId: await getSenderId(await this.beaconId),\n name: this.name,\n icon: this.iconUrl\n }\n }\n\n /**\n * Return all known peers\n */\n public async getPeers(): Promise<PeerInfo[]> {\n return (await this.transport).getPeers()\n }\n\n /**\n * Add a new peer to the known peers\n * @param peer The new peer to add\n */\n public async addPeer(peer: PeerInfo): Promise<void> {\n return (await this.transport).addPeer(peer)\n }\n\n public async destroy(): Promise<void> {\n if (this._transport.isResolved()) {\n const transport = await this.transport\n await this.cleanup()\n await transport.disconnect()\n if (transport.type === TransportType.WALLETCONNECT) {\n await (transport as any).doClientCleanup() // any because I cannot import the type definition\n }\n }\n await super.destroy()\n }\n\n /**\n * A \"setter\" for when the transport needs to be changed.\n */\n protected async setTransport(transport?: Transport<any>): Promise<void> {\n if (transport) {\n if (this._transport.isSettled()) {\n // If the promise has already been resolved we need to create a new one.\n this._transport = ExposedPromise.resolve(transport)\n } else {\n this._transport.resolve(transport)\n }\n } else {\n if (this._transport.isSettled()) {\n // If the promise has already been resolved we need to create a new one.\n this._transport = new ExposedPromise()\n }\n }\n }\n\n protected async addListener(transport: Transport<any>): Promise<void> {\n // in beacon we subscribe to the transport on client init only\n // unsubscribing from the transport is only beneficial when running\n // a single page dApp.\n // However, while running a multiple tabs setup, if one of the dApps disconnects\n // the others wont't recover until after a page refresh\n\n if (this.transportListeners.has(transport.type)) {\n await transport.removeListener(this.transportListeners.get(transport.type)!)\n }\n\n const subscription = async (message: any, connectionInfo: ConnectionContext) => {\n if (typeof message === 'string') {\n const deserializedMessage = (await new Serializer().deserialize(\n message\n )) as BeaconRequestMessage\n this.handleResponse(deserializedMessage, connectionInfo)\n }\n }\n\n this.transportListeners.set(transport.type, subscription)\n\n transport.addListener(subscription).catch((error) => logger.error('addListener', error))\n }\n\n protected async sendDisconnectToPeer(peer: PeerInfo, transport?: Transport<any>): Promise<void> {\n const request: DisconnectMessage = {\n id: await generateGUID(),\n version: peer.version,\n senderId: await getSenderId(await this.beaconId),\n type: BeaconMessageType.Disconnect\n }\n\n const payload = await new Serializer().serialize(request)\n const selectedTransport = transport ?? (await this.transport)\n\n await selectedTransport.send(payload, peer)\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Client.js","sourceRoot":"","sources":["../../../../src/clients/client/Client.ts"],"names":[],"mappings":";;;;;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CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,CAAA;YAE7D,MAAM,iBAAiB,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QAC7C,CAAC;KAAA;CACF;AA7PD,wBA6PC","sourcesContent":["import { ExposedPromise, generateGUID } from '@tezos-x/octez.connect-utils'\nimport {\n ConnectionContext,\n TransportType,\n TransportStatus,\n BeaconBaseMessage,\n AccountInfo,\n PeerInfo,\n BeaconMessageType,\n DisconnectMessage,\n AppMetadata,\n BeaconRequestMessage,\n BeaconMessageWrapper,\n NodeDistributions\n} from '@tezos-x/octez.connect-types'\nimport { BeaconClient } from '../beacon-client/BeaconClient'\nimport { AccountManager } from '../../managers/AccountManager'\nimport { getSenderId } from '../../utils/get-sender-id'\nimport { Logger } from '../../utils/Logger'\nimport { ClientOptions } from './ClientOptions'\nimport { Transport } from '../../transports/Transport'\nimport { Serializer } from '../../Serializer'\n\nconst logger = new Logger('Client')\n\ninterface TransportCleanupTarget {\n readonly type: TransportType\n removeListener(\n listener: (message: string, connectionInfo: ConnectionContext) => void\n ): Promise<void>\n}\n\n/**\n * @internalapi\n *\n * This abstract class handles the a big part of the logic that is shared between the dapp and wallet client.\n * For example, it selects and manages the transport and accounts.\n */\nexport abstract class Client extends BeaconClient {\n protected readonly accountManager: AccountManager\n\n protected handleResponse: (\n _event: BeaconRequestMessage | BeaconMessageWrapper<BeaconBaseMessage>,\n connectionInfo: ConnectionContext\n ) => void\n\n /**\n * How many requests can be sent after another\n */\n protected readonly rateLimit: number = 2\n /**\n * The time window in seconds in which the \"rateLimit\" is checked\n */\n protected readonly rateLimitWindowInSeconds: number = 5\n\n /**\n * Stores the times when requests have been made to determine if the rate limit has been reached\n */\n protected requestCounter: number[] = []\n\n protected readonly matrixNodes: NodeDistributions\n\n private transportListeners: Map<\n TransportType,\n (message: any, connectionInfo: ConnectionContext) => Promise<void>\n > = new Map()\n\n protected _transport: ExposedPromise<Transport<any>> = new ExposedPromise()\n protected get transport(): Promise<Transport<any>> {\n return this._transport.promise\n }\n\n /**\n * Returns the connection status of the Client\n */\n public get connectionStatus(): TransportStatus {\n return this._transport.promiseResult?.connectionStatus ?? TransportStatus.NOT_CONNECTED\n }\n\n /**\n * Returns whether or not the transaport is ready\n */\n public get ready(): Promise<void> {\n return this.transport.then(() => undefined)\n }\n\n constructor(config: ClientOptions) {\n super(config)\n\n this.accountManager = new AccountManager(config.storage)\n this.matrixNodes = config.matrixNodes ?? {}\n\n this.handleResponse = (\n message: BeaconBaseMessage | BeaconMessageWrapper<BeaconBaseMessage>,\n connectionInfo: ConnectionContext\n ): void => {\n throw new Error(\n `not overwritten${JSON.stringify(message)} - ${JSON.stringify(connectionInfo)}`\n )\n }\n }\n protected async cleanup(transports?: TransportCleanupTarget[]) {\n if (!this.transportListeners.size) {\n return\n }\n\n if (!transports) {\n if (this._transport.isResolved()) {\n const transport = await this.transport\n await Promise.all(\n Array.from(this.transportListeners.values()).map((listener) =>\n transport.removeListener(listener)\n )\n )\n }\n this.transportListeners.clear()\n\n return\n }\n\n // Explicit transport cleanup is scoped: callers tearing down secondary\n // transports should not unregister listeners for transports left alive.\n await Promise.all(\n transports.map(async (transport) => {\n const listener = this.transportListeners.get(transport.type)\n\n if (!listener) {\n return\n }\n\n await transport.removeListener(listener)\n this.transportListeners.delete(transport.type)\n })\n )\n }\n\n /**\n * Return all locally known accounts\n */\n public async getAccounts(): Promise<AccountInfo[]> {\n return this.accountManager.getAccounts()\n }\n\n /**\n * Return the account by ID\n * @param accountIdentifier The ID of an account\n */\n public async getAccount(accountIdentifier: string): Promise<AccountInfo | undefined> {\n return this.accountManager.getAccount(accountIdentifier)\n }\n\n /**\n * Remove the account by ID\n * @param accountIdentifier The ID of an account\n */\n public async removeAccount(accountIdentifier: string): Promise<void> {\n return this.accountManager.removeAccount(accountIdentifier)\n }\n\n /**\n * Remove all locally stored accounts\n */\n public async removeAllAccounts(): Promise<void> {\n return this.accountManager.removeAllAccounts()\n }\n\n /**\n * Add a new request (current timestamp) to the pending requests, remove old ones and check if we are above the limit\n */\n public async addRequestAndCheckIfRateLimited(): Promise<boolean> {\n const now: number = new Date().getTime()\n this.requestCounter = this.requestCounter.filter(\n (date) => date + this.rateLimitWindowInSeconds * 1000 > now\n )\n\n this.requestCounter.push(now)\n\n return this.requestCounter.length > this.rateLimit\n }\n\n /**\n * This method initializes the client. It will check if the connection should be established to a\n * browser extension or if the P2P transport should be used.\n *\n * @param transport A transport that can be provided by the user\n */\n public async init(transport: Transport<any>): Promise<TransportType> {\n if (this._transport.isResolved()) {\n return (await this.transport).type\n }\n\n await this.setTransport(transport) // Let users define their own transport\n\n return transport.type\n }\n\n /**\n * Returns the metadata of this DApp\n */\n public async getOwnAppMetadata(): Promise<AppMetadata> {\n return {\n senderId: await getSenderId(await this.beaconId),\n name: this.name,\n icon: this.iconUrl\n }\n }\n\n /**\n * Return all known peers\n */\n public async getPeers(): Promise<PeerInfo[]> {\n return (await this.transport).getPeers()\n }\n\n /**\n * Add a new peer to the known peers\n * @param peer The new peer to add\n */\n public async addPeer(peer: PeerInfo): Promise<void> {\n return (await this.transport).addPeer(peer)\n }\n\n public async destroy(): Promise<void> {\n if (this._transport.isResolved()) {\n const transport = await this.transport\n await this.cleanup()\n await transport.disconnect()\n if (transport.type === TransportType.WALLETCONNECT) {\n await (transport as any).doClientCleanup() // any because I cannot import the type definition\n }\n }\n await super.destroy()\n }\n\n /**\n * A \"setter\" for when the transport needs to be changed.\n */\n protected async setTransport(transport?: Transport<any>): Promise<void> {\n if (transport) {\n if (this._transport.isSettled()) {\n // If the promise has already been resolved we need to create a new one.\n this._transport = ExposedPromise.resolve(transport)\n } else {\n this._transport.resolve(transport)\n }\n } else {\n if (this._transport.isSettled()) {\n // If the promise has already been resolved we need to create a new one.\n this._transport = new ExposedPromise()\n }\n }\n }\n\n protected async addListener(transport: Transport<any>): Promise<void> {\n // in beacon we subscribe to the transport on client init only\n // unsubscribing from the transport is only beneficial when running\n // a single page dApp.\n // However, while running a multiple tabs setup, if one of the dApps disconnects\n // the others wont't recover until after a page refresh\n\n if (this.transportListeners.has(transport.type)) {\n await transport.removeListener(this.transportListeners.get(transport.type)!)\n }\n\n const subscription = async (message: any, connectionInfo: ConnectionContext) => {\n if (typeof message === 'string') {\n const deserializedMessage = (await new Serializer().deserialize(\n message\n )) as BeaconRequestMessage\n this.handleResponse(deserializedMessage, connectionInfo)\n }\n }\n\n this.transportListeners.set(transport.type, subscription)\n\n transport.addListener(subscription).catch((error) => logger.error('addListener', error))\n }\n\n protected async sendDisconnectToPeer(peer: PeerInfo, transport?: Transport<any>): Promise<void> {\n const request: DisconnectMessage = {\n id: await generateGUID(),\n version: peer.version,\n senderId: await getSenderId(await this.beaconId),\n type: BeaconMessageType.Disconnect\n }\n\n const payload = await new Serializer().serialize(request)\n const selectedTransport = transport ?? (await this.transport)\n\n await selectedTransport.send(payload, peer)\n }\n}\n"]}
|
package/dist/cjs/constants.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BACKEND_URL = exports.NOTIFICATION_ORACLE_URL = exports.BEACON_VERSION = exports.SDK_VERSION = void 0;
|
|
4
|
-
exports.SDK_VERSION = '4.8.
|
|
4
|
+
exports.SDK_VERSION = '4.8.5';
|
|
5
5
|
exports.BEACON_VERSION = '3';
|
|
6
6
|
exports.NOTIFICATION_ORACLE_URL = 'https://beacon-notification-oracle.dev.gke.papers.tech';
|
|
7
7
|
exports.BACKEND_URL = 'https://beacon-backend.prod.gke.papers.tech';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAW,OAAO,CAAA;AAC7B,QAAA,cAAc,GAAW,GAAG,CAAA;AAE5B,QAAA,uBAAuB,GAClC,wDAAwD,CAAA;AAE7C,QAAA,WAAW,GAAW,6CAA6C,CAAA","sourcesContent":["export const SDK_VERSION: string = '4.8.
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAW,OAAO,CAAA;AAC7B,QAAA,cAAc,GAAW,GAAG,CAAA;AAE5B,QAAA,uBAAuB,GAClC,wDAAwD,CAAA;AAE7C,QAAA,WAAW,GAAW,6CAA6C,CAAA","sourcesContent":["export const SDK_VERSION: string = '4.8.5'\nexport const BEACON_VERSION: string = '3'\n\nexport const NOTIFICATION_ORACLE_URL: string =\n 'https://beacon-notification-oracle.dev.gke.papers.tech'\n\nexport const BACKEND_URL: string = 'https://beacon-backend.prod.gke.papers.tech'\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PeerUnreachableBeaconError = void 0;
|
|
4
|
+
const octez_connect_types_1 = require("@tezos-x/octez.connect-types");
|
|
5
|
+
const BeaconError_1 = require("./BeaconError");
|
|
6
|
+
/**
|
|
7
|
+
* @category Error
|
|
8
|
+
*/
|
|
9
|
+
class PeerUnreachableBeaconError extends BeaconError_1.BeaconError {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(octez_connect_types_1.BeaconErrorType.PEER_UNREACHABLE, 'The wallet did not answer the request. Reset the connection and pair the wallet again.');
|
|
12
|
+
this.name = 'PeerUnreachableBeaconError';
|
|
13
|
+
this.title = 'Peer Unreachable';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.PeerUnreachableBeaconError = PeerUnreachableBeaconError;
|
|
17
|
+
//# sourceMappingURL=PeerUnreachableBeaconError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PeerUnreachableBeaconError.js","sourceRoot":"","sources":["../../../src/errors/PeerUnreachableBeaconError.ts"],"names":[],"mappings":";;;AAAA,sEAA8D;AAC9D,+CAA2C;AAE3C;;GAEG;AACH,MAAa,0BAA2B,SAAQ,yBAAW;IAIzD;QACE,KAAK,CACH,qCAAe,CAAC,gBAAgB,EAChC,wFAAwF,CACzF,CAAA;QAPI,SAAI,GAAW,4BAA4B,CAAA;QAC3C,UAAK,GAAW,kBAAkB,CAAA;IAOzC,CAAC;CACF;AAVD,gEAUC","sourcesContent":["import { BeaconErrorType } from '@tezos-x/octez.connect-types'\nimport { BeaconError } from './BeaconError'\n\n/**\n * @category Error\n */\nexport class PeerUnreachableBeaconError extends BeaconError {\n public name: string = 'PeerUnreachableBeaconError'\n public title: string = 'Peer Unreachable'\n\n constructor() {\n super(\n BeaconErrorType.PEER_UNREACHABLE,\n 'The wallet did not answer the request. Reset the connection and pair the wallet again.'\n )\n }\n}\n"]}
|
|
@@ -15,6 +15,7 @@ const NoAddressBeaconError_1 = require("./NoAddressBeaconError");
|
|
|
15
15
|
const NoPrivateKeyBeaconError_1 = require("./NoPrivateKeyBeaconError");
|
|
16
16
|
const NotGrantedBeaconError_1 = require("./NotGrantedBeaconError");
|
|
17
17
|
const ParametersInvalidBeaconError_1 = require("./ParametersInvalidBeaconError");
|
|
18
|
+
const PeerUnreachableBeaconError_1 = require("./PeerUnreachableBeaconError");
|
|
18
19
|
const SignatureTypeNotSupportedBeaconError_1 = require("./SignatureTypeNotSupportedBeaconError");
|
|
19
20
|
const TooManyOperationsBeaconError_1 = require("./TooManyOperationsBeaconError");
|
|
20
21
|
const TransactionInvalidBeaconError_1 = require("./TransactionInvalidBeaconError");
|
|
@@ -43,6 +44,8 @@ const getError = (errorType, errorData) => {
|
|
|
43
44
|
// return new EncryptionTypeNotSupportedBeaconError()
|
|
44
45
|
case octez_connect_types_1.BeaconErrorType.ABORTED_ERROR:
|
|
45
46
|
return new AbortedBeaconError_1.AbortedBeaconError();
|
|
47
|
+
case octez_connect_types_1.BeaconErrorType.PEER_UNREACHABLE:
|
|
48
|
+
return new PeerUnreachableBeaconError_1.PeerUnreachableBeaconError();
|
|
46
49
|
case octez_connect_types_1.BeaconErrorType.UNKNOWN_ERROR:
|
|
47
50
|
return new UnknownBeaconError_1.UnknownBeaconError();
|
|
48
51
|
default:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-error.js","sourceRoot":"","sources":["../../../src/errors/get-error.ts"],"names":[],"mappings":";;;AAAA,sBAAsB;AACtB,+CAA2C;
|
|
1
|
+
{"version":3,"file":"get-error.js","sourceRoot":"","sources":["../../../src/errors/get-error.ts"],"names":[],"mappings":";;;AAAA,sBAAsB;AACtB,+CAA2C;AAgBlC,4FAhBA,yBAAW,OAgBA;AAfpB,iEAA6D;AAgBpD,qGAhBA,2CAAoB,OAgBA;AAf7B,qFAAiF;AAelD,+GAftB,+DAA8B,OAesB;AAd7D,sEAA8D;AAC9D,wDAAmD;AACnD,6DAAyD;AACzD,iEAA6D;AAC7D,uEAAmE;AACnE,mEAA+D;AAC/D,iFAA6E;AAC7E,6EAAyE;AACzE,iGAA6F;AAC7F,iFAA6E;AAC7E,mFAA+E;AAC/E,6DAAyD;AAKzD,MAAM,QAAQ,GAAG,CAAC,SAA0B,EAAE,SAAkB,EAAe,EAAE;IAC/E,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,qCAAe,CAAC,eAAe;YAClC,OAAO,IAAI,2CAAoB,EAAE,CAAA;QACnC,KAAK,qCAAe,CAAC,qBAAqB;YACxC,OAAO,IAAI,+DAA8B,EAAE,CAAA;QAC7C,KAAK,qCAAe,CAAC,gBAAgB;YACnC,OAAO,IAAI,2CAAoB,EAAE,CAAA;QACnC,KAAK,qCAAe,CAAC,0BAA0B;YAC7C,OAAO,IAAI,iDAAuB,EAAE,CAAA;QACtC,KAAK,qCAAe,CAAC,iBAAiB;YACpC,OAAO,IAAI,6CAAqB,EAAE,CAAA;QACpC,KAAK,qCAAe,CAAC,wBAAwB;YAC3C,OAAO,IAAI,2DAA4B,EAAE,CAAA;QAC3C,KAAK,qCAAe,CAAC,mBAAmB;YACtC,OAAO,IAAI,2DAA4B,EAAE,CAAA;QAC3C,KAAK,qCAAe,CAAC,yBAAyB;YAC5C,OAAO,IAAI,6DAA6B,CAAC,SAAS,CAAC,CAAA;QACrD,KAAK,qCAAe,CAAC,4BAA4B;YAC/C,OAAO,IAAI,2EAAoC,EAAE,CAAA;QACnD,sDAAsD;QACtD,uDAAuD;QACvD,KAAK,qCAAe,CAAC,aAAa;YAChC,OAAO,IAAI,uCAAkB,EAAE,CAAA;QACjC,KAAK,qCAAe,CAAC,gBAAgB;YACnC,OAAO,IAAI,uDAA0B,EAAE,CAAA;QACzC,KAAK,qCAAe,CAAC,aAAa;YAChC,OAAO,IAAI,uCAAkB,EAAE,CAAA;QACjC;YACE,IAAA,0BAAW,EAAC,SAAS,CAAC,CAAA;IAC1B,CAAC;AACH,CAAC,CAAA;AAED,kBAAe,QAAQ,CAAA","sourcesContent":["// src/errors/index.ts\nimport { BeaconError } from './BeaconError'\nimport { BroadcastBeaconError } from './BroadcastBeaconError'\nimport { NetworkNotSupportedBeaconError } from './NetworkNotSupportedBeaconError'\nimport { BeaconErrorType } from '@tezos-x/octez.connect-types'\nimport { assertNever } from '../utils/assert-never'\nimport { AbortedBeaconError } from './AbortedBeaconError'\nimport { NoAddressBeaconError } from './NoAddressBeaconError'\nimport { NoPrivateKeyBeaconError } from './NoPrivateKeyBeaconError'\nimport { NotGrantedBeaconError } from './NotGrantedBeaconError'\nimport { ParametersInvalidBeaconError } from './ParametersInvalidBeaconError'\nimport { PeerUnreachableBeaconError } from './PeerUnreachableBeaconError'\nimport { SignatureTypeNotSupportedBeaconError } from './SignatureTypeNotSupportedBeaconError'\nimport { TooManyOperationsBeaconError } from './TooManyOperationsBeaconError'\nimport { TransactionInvalidBeaconError } from './TransactionInvalidBeaconError'\nimport { UnknownBeaconError } from './UnknownBeaconError'\n\nexport { BeaconError } // plus each subclass, if you like:\nexport { BroadcastBeaconError, NetworkNotSupportedBeaconError /* … */ }\n\nconst getError = (errorType: BeaconErrorType, errorData: unknown): BeaconError => {\n switch (errorType) {\n case BeaconErrorType.BROADCAST_ERROR:\n return new BroadcastBeaconError()\n case BeaconErrorType.NETWORK_NOT_SUPPORTED:\n return new NetworkNotSupportedBeaconError()\n case BeaconErrorType.NO_ADDRESS_ERROR:\n return new NoAddressBeaconError()\n case BeaconErrorType.NO_PRIVATE_KEY_FOUND_ERROR:\n return new NoPrivateKeyBeaconError()\n case BeaconErrorType.NOT_GRANTED_ERROR:\n return new NotGrantedBeaconError()\n case BeaconErrorType.PARAMETERS_INVALID_ERROR:\n return new ParametersInvalidBeaconError()\n case BeaconErrorType.TOO_MANY_OPERATIONS:\n return new TooManyOperationsBeaconError()\n case BeaconErrorType.TRANSACTION_INVALID_ERROR:\n return new TransactionInvalidBeaconError(errorData)\n case BeaconErrorType.SIGNATURE_TYPE_NOT_SUPPORTED:\n return new SignatureTypeNotSupportedBeaconError()\n // case BeaconErrorType.ENCRYPTION_TYPE_NOT_SUPPORTED:\n // return new EncryptionTypeNotSupportedBeaconError()\n case BeaconErrorType.ABORTED_ERROR:\n return new AbortedBeaconError()\n case BeaconErrorType.PEER_UNREACHABLE:\n return new PeerUnreachableBeaconError()\n case BeaconErrorType.UNKNOWN_ERROR:\n return new UnknownBeaconError()\n default:\n assertNever(errorType)\n }\n}\n\nexport default getError\n"]}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { ParametersInvalidBeaconError } from './errors/ParametersInvalidBeaconEr
|
|
|
13
13
|
import { TooManyOperationsBeaconError } from './errors/TooManyOperationsBeaconError';
|
|
14
14
|
import { TransactionInvalidBeaconError } from './errors/TransactionInvalidBeaconError';
|
|
15
15
|
import { UnknownBeaconError } from './errors/UnknownBeaconError';
|
|
16
|
+
import { PeerUnreachableBeaconError } from './errors/PeerUnreachableBeaconError';
|
|
16
17
|
import { Transport } from './transports/Transport';
|
|
17
18
|
import { ChromeStorage } from './storage/ChromeStorage';
|
|
18
19
|
import { LocalStorage } from './storage/LocalStorage';
|
|
@@ -42,7 +43,7 @@ import { StorageValidator } from './storage/StorageValidator';
|
|
|
42
43
|
import { MultiTabChannel } from './utils/multi-tab-channel';
|
|
43
44
|
import getError from './errors/get-error';
|
|
44
45
|
export { BeaconClient, BeaconClientOptions, Client, ClientOptions, ClientEvents };
|
|
45
|
-
export { getError, BeaconError, AbortedBeaconError, BroadcastBeaconError, NetworkNotSupportedBeaconError, NoAddressBeaconError, NoPrivateKeyBeaconError, NotGrantedBeaconError, ParametersInvalidBeaconError, TooManyOperationsBeaconError, TransactionInvalidBeaconError, SignatureTypeNotSupportedBeaconError, UnknownBeaconError };
|
|
46
|
+
export { getError, BeaconError, AbortedBeaconError, BroadcastBeaconError, NetworkNotSupportedBeaconError, NoAddressBeaconError, NoPrivateKeyBeaconError, NotGrantedBeaconError, ParametersInvalidBeaconError, TooManyOperationsBeaconError, TransactionInvalidBeaconError, SignatureTypeNotSupportedBeaconError, PeerUnreachableBeaconError, UnknownBeaconError };
|
|
46
47
|
export { Transport, MessageBasedClient, CommunicationClient };
|
|
47
48
|
export { ChromeStorage, LocalStorage, WCStorage, IndexedDBStorage, StorageValidator, getStorage };
|
|
48
49
|
export { PeerManager, AccountManager, AppMetadataManager, PermissionManager };
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BACKEND_URL = exports.NOTIFICATION_ORACLE_URL = exports.getDebugEnabled = exports.setDebugEnabled = exports.getLogger = exports.setLogger = exports.Logger = exports.Serializer = exports.MultiTabChannel = exports.windowRef = exports.getAccountIdentifier = exports.getSenderId = exports.BEACON_VERSION = exports.SDK_VERSION = exports.PermissionManager = exports.AppMetadataManager = exports.AccountManager = exports.PeerManager = exports.getStorage = exports.StorageValidator = exports.IndexedDBStorage = exports.WCStorage = exports.LocalStorage = exports.ChromeStorage = exports.CommunicationClient = exports.MessageBasedClient = exports.Transport = exports.UnknownBeaconError = exports.SignatureTypeNotSupportedBeaconError = exports.TransactionInvalidBeaconError = exports.TooManyOperationsBeaconError = exports.ParametersInvalidBeaconError = exports.NotGrantedBeaconError = exports.NoPrivateKeyBeaconError = exports.NoAddressBeaconError = exports.NetworkNotSupportedBeaconError = exports.BroadcastBeaconError = exports.AbortedBeaconError = exports.BeaconError = exports.getError = exports.Client = exports.BeaconClient = void 0;
|
|
3
|
+
exports.BACKEND_URL = exports.NOTIFICATION_ORACLE_URL = exports.getDebugEnabled = exports.setDebugEnabled = exports.getLogger = exports.setLogger = exports.Logger = exports.Serializer = exports.MultiTabChannel = exports.windowRef = exports.getAccountIdentifier = exports.getSenderId = exports.BEACON_VERSION = exports.SDK_VERSION = exports.PermissionManager = exports.AppMetadataManager = exports.AccountManager = exports.PeerManager = exports.getStorage = exports.StorageValidator = exports.IndexedDBStorage = exports.WCStorage = exports.LocalStorage = exports.ChromeStorage = exports.CommunicationClient = exports.MessageBasedClient = exports.Transport = exports.UnknownBeaconError = exports.PeerUnreachableBeaconError = exports.SignatureTypeNotSupportedBeaconError = exports.TransactionInvalidBeaconError = exports.TooManyOperationsBeaconError = exports.ParametersInvalidBeaconError = exports.NotGrantedBeaconError = exports.NoPrivateKeyBeaconError = exports.NoAddressBeaconError = exports.NetworkNotSupportedBeaconError = exports.BroadcastBeaconError = exports.AbortedBeaconError = exports.BeaconError = exports.getError = exports.Client = exports.BeaconClient = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* General docs
|
|
6
6
|
* @module public
|
|
@@ -27,6 +27,8 @@ const TransactionInvalidBeaconError_1 = require("./errors/TransactionInvalidBeac
|
|
|
27
27
|
Object.defineProperty(exports, "TransactionInvalidBeaconError", { enumerable: true, get: function () { return TransactionInvalidBeaconError_1.TransactionInvalidBeaconError; } });
|
|
28
28
|
const UnknownBeaconError_1 = require("./errors/UnknownBeaconError");
|
|
29
29
|
Object.defineProperty(exports, "UnknownBeaconError", { enumerable: true, get: function () { return UnknownBeaconError_1.UnknownBeaconError; } });
|
|
30
|
+
const PeerUnreachableBeaconError_1 = require("./errors/PeerUnreachableBeaconError");
|
|
31
|
+
Object.defineProperty(exports, "PeerUnreachableBeaconError", { enumerable: true, get: function () { return PeerUnreachableBeaconError_1.PeerUnreachableBeaconError; } });
|
|
30
32
|
const Transport_1 = require("./transports/Transport");
|
|
31
33
|
Object.defineProperty(exports, "Transport", { enumerable: true, get: function () { return Transport_1.Transport; } });
|
|
32
34
|
const ChromeStorage_1 = require("./storage/ChromeStorage");
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -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;AAgDJ,uFAhDnC,eAAM,OAgDmC;AA/ClD,sDAAkD;AAoDhD,4FApDO,yBAAW,OAoDP;AAnDb,wEAAoE;AAqDlE,qGArDO,2CAAoB,OAqDP;AApDtB,4FAAwF;AAqDtF,+GArDO,+DAA8B,OAqDP;AApDhC,wEAAoE;AAqDlE,qGArDO,2CAAoB,OAqDP;AApDtB,8EAA0E;AAqDxE,wGArDO,iDAAuB,OAqDP;AApDzB,0EAAsE;AAqDpE,sGArDO,6CAAqB,OAqDP;AApDvB,wFAAoF;AAqDlF,6GArDO,2DAA4B,OAqDP;AApD9B,wFAAoF;AAqDlF,6GArDO,2DAA4B,OAqDP;AApD9B,0FAAsF;AAqDpF,8GArDO,6DAA6B,OAqDP;AApD/B,oEAAgE;AAwD9D,mGAxDO,uCAAkB,OAwDP;AAvDpB,oFAAgF;AAqD9E,2GArDO,uDAA0B,OAqDP;AApD5B,sDAAkD;AA0DzC,0FA1DA,qBAAS,OA0DA;AAzDlB,2DAAuD;AA4D9C,8FA5DA,6BAAa,OA4DA;AA3DtB,yDAAqD;AA2D7B,6F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C;AASvC,mBATK,mBAAQ,CASL;AAsCV,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 { PeerUnreachableBeaconError } from './errors/PeerUnreachableBeaconError'\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 { SDK_VERSION, BEACON_VERSION } from './constants'\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 { 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 PeerUnreachableBeaconError,\n // EncryptionTypeNotSupportedBeaconError,\n UnknownBeaconError\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 { SDK_VERSION, BEACON_VERSION }\n\n// Utils\nexport { getSenderId, getAccountIdentifier, windowRef, MultiTabChannel }\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,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.ChromeStorage = void 0;
|
|
13
|
-
const
|
|
13
|
+
const storage_normalization_1 = require("./storage-normalization");
|
|
14
14
|
/**
|
|
15
15
|
* @internalapi
|
|
16
16
|
*
|
|
@@ -30,25 +30,16 @@ class ChromeStorage {
|
|
|
30
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
31
|
return new Promise((resolve) => {
|
|
32
32
|
chrome.storage.local.get(null, (storageContent) => {
|
|
33
|
-
|
|
34
|
-
if (value !== undefined) {
|
|
35
|
-
resolve(value);
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
const defaultValue = octez_connect_types_1.defaultValues[key];
|
|
39
|
-
if (typeof defaultValue === 'object') {
|
|
40
|
-
resolve(JSON.parse(JSON.stringify(defaultValue)));
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
resolve(defaultValue);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
33
|
+
resolve((0, storage_normalization_1.normalizeParsedStoredValue)(key, storageContent[key]));
|
|
46
34
|
});
|
|
47
35
|
});
|
|
48
36
|
});
|
|
49
37
|
}
|
|
50
38
|
set(key, value) {
|
|
51
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
if (value === undefined) {
|
|
41
|
+
return this.delete(key);
|
|
42
|
+
}
|
|
52
43
|
return new Promise((resolve) => {
|
|
53
44
|
chrome.storage.local.set({ [key]: value }, () => {
|
|
54
45
|
resolve();
|
|
@@ -59,7 +50,7 @@ class ChromeStorage {
|
|
|
59
50
|
delete(key) {
|
|
60
51
|
return __awaiter(this, void 0, void 0, function* () {
|
|
61
52
|
return new Promise((resolve) => {
|
|
62
|
-
chrome.storage.local.
|
|
53
|
+
chrome.storage.local.remove(String(key), () => {
|
|
63
54
|
resolve();
|
|
64
55
|
});
|
|
65
56
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChromeStorage.js","sourceRoot":"","sources":["../../../src/storage/ChromeStorage.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"ChromeStorage.js","sourceRoot":"","sources":["../../../src/storage/ChromeStorage.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,mEAAoE;AAEpE;;;;GAIG;AACH,MAAa,aAAa;IACjB,MAAM,CAAO,WAAW;;YAC7B,OAAO,CACL,OAAO,MAAM,KAAK,WAAW;gBAC7B,OAAO,MAAM,KAAK,WAAW;gBAC7B,OAAO,CAAC,MAAM,CAAC;gBACf,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;gBACvB,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAC3B,CAAA;QACH,CAAC;KAAA;IAEY,GAAG,CAAuB,GAAM;;YAC3C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;gBAC7B,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,cAA6C,EAAE,EAAE;oBAC/E,OAAO,CAAC,IAAA,kDAA0B,EAAC,GAAG,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;gBAC/D,CAAC,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;QACJ,CAAC;KAAA;IAEY,GAAG,CAAuB,GAAM,EAAE,KAA8B;;YAC3E,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;YACzB,CAAC;YAED,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;gBAC7B,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE;oBAC9C,OAAO,EAAE,CAAA;gBACX,CAAC,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;QACJ,CAAC;KAAA;IAEY,MAAM,CAAuB,GAAM;;YAC9C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;gBAC7B,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE;oBAC5C,OAAO,EAAE,CAAA;gBACX,CAAC,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;QACJ,CAAC;KAAA;IAEY,yBAAyB,CACpC,SAKQ;;YAER,OAAO;QACT,CAAC;KAAA;IAEM,cAAc,CAAC,GAAW;QAC/B,OAAO,GAAG,CAAA;IACZ,CAAC;CACF;AArDD,sCAqDC","sourcesContent":["import { Storage, StorageKey, StorageKeyReturnType } from '@tezos-x/octez.connect-types'\nimport { normalizeParsedStoredValue } from './storage-normalization'\n\n/**\n * @internalapi\n *\n * A storage that can be used in chrome extensions\n */\nexport class ChromeStorage implements Storage {\n public static async isSupported(): Promise<boolean> {\n return (\n typeof window !== 'undefined' &&\n typeof chrome !== 'undefined' &&\n Boolean(chrome) &&\n Boolean(chrome.runtime) &&\n Boolean(chrome.runtime.id)\n )\n }\n\n public async get<K extends StorageKey>(key: K): Promise<StorageKeyReturnType[K]> {\n return new Promise((resolve) => {\n chrome.storage.local.get(null, (storageContent: Partial<StorageKeyReturnType>) => {\n resolve(normalizeParsedStoredValue(key, storageContent[key]))\n })\n })\n }\n\n public async set<K extends StorageKey>(key: K, value: StorageKeyReturnType[K]): Promise<void> {\n if (value === undefined) {\n return this.delete(key)\n }\n\n return new Promise((resolve) => {\n chrome.storage.local.set({ [key]: value }, () => {\n resolve()\n })\n })\n }\n\n public async delete<K extends StorageKey>(key: K): Promise<void> {\n return new Promise((resolve) => {\n chrome.storage.local.remove(String(key), () => {\n resolve()\n })\n })\n }\n\n public async subscribeToStorageChanged(\n _callback: (arg: {\n eventType: 'storageCleared' | 'entryModified'\n key: string | null\n oldValue: string | null\n newValue: string | null\n }) => {}\n ): Promise<void> {\n // TODO\n }\n\n public getPrefixedKey(key: string): string {\n return key\n }\n}\n"]}
|
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.IndexedDBStorage = void 0;
|
|
13
13
|
const octez_connect_types_1 = require("@tezos-x/octez.connect-types");
|
|
14
14
|
const Logger_1 = require("../utils/Logger");
|
|
15
|
+
const storage_normalization_1 = require("./storage-normalization");
|
|
15
16
|
const logger = new Logger_1.Logger('IndexedDBStorage');
|
|
16
17
|
class IndexedDBStorage extends octez_connect_types_1.Storage {
|
|
17
18
|
/**
|
|
@@ -113,13 +114,19 @@ class IndexedDBStorage extends octez_connect_types_1.Storage {
|
|
|
113
114
|
});
|
|
114
115
|
}
|
|
115
116
|
get(key, storeName = this.storeNames[0]) {
|
|
116
|
-
|
|
117
|
+
const storedValue = this.transaction('readonly', storeName, (store) => new Promise((resolve, reject) => {
|
|
117
118
|
const getRequest = store.get(key);
|
|
118
119
|
getRequest.onsuccess = () => resolve(getRequest.result);
|
|
119
120
|
getRequest.onerror = () => reject(getRequest.error);
|
|
120
121
|
}));
|
|
122
|
+
return (0, storage_normalization_1.isStorageKey)(key)
|
|
123
|
+
? storedValue.then((value) => (0, storage_normalization_1.normalizeParsedStoredValue)(key, value))
|
|
124
|
+
: storedValue;
|
|
121
125
|
}
|
|
122
126
|
set(key, value, storeName = this.storeNames[0]) {
|
|
127
|
+
if (value === undefined) {
|
|
128
|
+
return this.delete(key, storeName);
|
|
129
|
+
}
|
|
123
130
|
return this.transaction('readwrite', storeName, (store) => new Promise((resolve, reject) => {
|
|
124
131
|
const putRequest = store.put(value, key);
|
|
125
132
|
putRequest.onsuccess = () => resolve();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IndexedDBStorage.js","sourceRoot":"","sources":["../../../src/storage/IndexedDBStorage.ts"],"names":[],"mappings":";;;;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B,GAAG,QAAQ,CAAC,WAAW,CAAC,eAAe,EAAE,WAAW,CAAC,CAAA;wBAC5E,MAAM,WAAW,GAAG,iBAAiB,CAAC,WAAW,CAAC,eAAe,CAAC,CAAA;wBAElE,IAAI;6BACD,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;6BACnD,OAAO,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;4BACtB,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAA;wBACpC,CAAC,CAAC,CAAA;wBAEJ,iBAAiB,CAAC,OAAO,GAAG,CAAC,KAAU,EAAE,EAAE;4BACzC,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;wBACzD,CAAC,CAAA;oBACH,CAAC,CAAA,CAAA;gBACH,CAAC,CAAA,CAAA;gBACD,iBAAiB,CAAC,OAAO,GAAG,GAAG,EAAE;oBAC/B,MAAM,CAAC,KAAK,CAAC,mCAAmC,EAAE,iBAAiB,CAAC,KAAK,CAAC,CAAA;gBAC5E,CAAC,CAAA;gBACD,aAAa,CAAC,OAAO,GAAG,GAAG,EAAE;oBAC3B,MAAM,CAAC,KAAK,CAAC,+BAA+B,EAAE,aAAa,CAAC,KAAK,CAAC,CAAA;gBACpE,CAAC,CAAA;YACH,CAAC,CAAA,CAAC,CAAA;QACJ,CAAC;KAAA;CACF;AAnTD,4CAmTC","sourcesContent":["import { Storage, StorageKey, StorageKeyReturnType } from '@tezos-x/octez.connect-types'\nimport { Logger } from '../utils/Logger'\n\nconst logger = new Logger('IndexedDBStorage')\n\nexport class IndexedDBStorage extends Storage {\n private db: IDBDatabase | null = null\n private isSupported: boolean = true\n\n /**\n * @param dbName Name of the database.\n * @param storeNames An array of object store names to create in the database.\n * The first store in the array will be used as the default if none is specified.\n */\n constructor(\n private readonly dbName: string = 'WALLET_CONNECT_V2_INDEXED_DB',\n private readonly storeNames: string[] = ['keyvaluestorage']\n ) {\n super()\n this.initDB()\n .then((db) => (this.db = db))\n .catch((err) => logger.error(err.message))\n }\n\n private isIndexedDBSupported() {\n if (typeof window !== 'undefined' && 'indexedDB' in window) {\n logger.log('isIndexedDBSupported', 'IndexedDB is supported in this browser.')\n return true\n } else {\n logger.error('isIndexedDBSupported', 'IndexedDB is not supported in this browser.')\n return false\n }\n }\n\n private async initDB(): Promise<IDBDatabase> {\n return new Promise((resolve, reject) => {\n this.isSupported = this.isIndexedDBSupported()\n if (!this.isSupported) {\n reject('IndexedDB is not supported.')\n return\n }\n\n const openRequest = indexedDB.open(this.dbName)\n\n openRequest.onupgradeneeded = () => {\n const db = openRequest.result\n // Create all required object stores\n this.storeNames.forEach((storeName) => {\n if (!db.objectStoreNames.contains(storeName)) {\n db.createObjectStore(storeName)\n }\n })\n }\n\n openRequest.onsuccess = (event: any) => {\n const db = event.target.result as IDBDatabase\n // Check if all stores exist – if not, perform an upgrade.\n const missingStores = this.storeNames.filter(\n (storeName) => !db.objectStoreNames.contains(storeName)\n )\n if (missingStores.length > 0) {\n db.close()\n const newVersion = db.version + 1\n const upgradeRequest = indexedDB.open(this.dbName, newVersion)\n\n upgradeRequest.onupgradeneeded = () => {\n const upgradedDB = upgradeRequest.result\n missingStores.forEach((storeName) => {\n if (!upgradedDB.objectStoreNames.contains(storeName)) {\n upgradedDB.createObjectStore(storeName)\n }\n })\n }\n\n upgradeRequest.onsuccess = (event: any) => {\n this.db = event.target.result as IDBDatabase\n resolve(this.db)\n }\n\n upgradeRequest.onerror = (event: any) => reject(event.target.error)\n } else {\n this.db = db\n resolve(db)\n }\n }\n\n openRequest.onerror = (event: any) => reject(event.target.error)\n })\n }\n\n /**\n * Performs a transaction on the given object store.\n * @param mode Transaction mode.\n * @param storeName The name of the object store.\n * @param operation The operation to perform with the object store.\n */\n private async transaction<T>(\n mode: IDBTransactionMode,\n storeName: string,\n operation: (store: IDBObjectStore) => Promise<T>\n ): Promise<T> {\n return new Promise((resolve, reject) => {\n if (!this.isSupported) {\n reject('IndexedDB is not supported.')\n return\n }\n\n if (!this.db?.objectStoreNames.contains(storeName)) {\n reject(`${storeName} not found. error: ${new Error().stack}`)\n return\n }\n\n const transaction = this.db.transaction(storeName, mode)\n const objectStore = transaction.objectStore(storeName)\n operation(objectStore).then(resolve).catch(reject)\n })\n }\n\n /**\n * Retrieves a value by key from the specified object store.\n * If no store is specified, the default (first in the list) is used.\n */\n public get<K extends StorageKey>(key: K, storeName?: string): Promise<StorageKeyReturnType[K]>\n public get(key: string, storeName?: string): Promise<string | undefined>\n public get(key: StorageKey | string, storeName: string = this.storeNames[0]): Promise<any> {\n return this.transaction(\n 'readonly',\n storeName,\n (store) =>\n new Promise((resolve, reject) => {\n const getRequest = store.get(key)\n getRequest.onsuccess = () => resolve(getRequest.result)\n getRequest.onerror = () => reject(getRequest.error)\n })\n )\n }\n\n /**\n * Stores a key/value pair in the specified object store.\n */\n public set<K extends StorageKey>(\n key: K,\n value: StorageKeyReturnType[K],\n storeName?: string\n ): Promise<void>\n public set(key: string, value: string, storeName?: string): Promise<void>\n public set(\n key: StorageKey | string,\n value: any,\n storeName: string = this.storeNames[0]\n ): Promise<void> {\n return this.transaction(\n 'readwrite',\n storeName,\n (store) =>\n new Promise((resolve, reject) => {\n const putRequest = store.put(value, key)\n putRequest.onsuccess = () => resolve()\n putRequest.onerror = () => reject(putRequest.error)\n })\n )\n }\n\n /**\n * Deletes an entry by key from the specified object store.\n */\n public delete<K extends StorageKey>(key: K, storeName?: string): Promise<void>\n public delete(key: string, storeName?: string): Promise<void>\n public delete(key: StorageKey | string, storeName: string = this.storeNames[0]): Promise<void> {\n return this.transaction(\n 'readwrite',\n storeName,\n (store) =>\n new Promise((resolve, reject) => {\n const deleteRequest = store.delete(key)\n deleteRequest.onsuccess = () => resolve()\n deleteRequest.onerror = () => reject(deleteRequest.error)\n })\n )\n }\n\n /**\n * Retrieves all values from the specified object store.\n */\n public getAll(storeName?: string): Promise<string[]> {\n return this.transaction(\n 'readonly',\n storeName || this.storeNames[0],\n (store) =>\n new Promise((resolve, reject) => {\n const getAllRequest = store.getAll()\n getAllRequest.onsuccess = () => resolve(getAllRequest.result)\n getAllRequest.onerror = () => reject(getAllRequest.error)\n })\n )\n }\n\n /**\n * Retrieves all keys from the specified object store.\n */\n public getAllKeys(storeName?: string): Promise<IDBValidKey[]> {\n return this.transaction(\n 'readonly',\n storeName || this.storeNames[0],\n (store) =>\n new Promise((resolve, reject) => {\n const getAllKeysRequest = store.getAllKeys()\n getAllKeysRequest.onsuccess = () => resolve(getAllKeysRequest.result)\n getAllKeysRequest.onerror = () => reject(getAllKeysRequest.error)\n })\n )\n }\n\n /**\n * Clears all entries from the specified object store.\n */\n public clearStore(storeName?: string): Promise<void> {\n return this.transaction(\n 'readwrite',\n storeName || this.storeNames[0],\n (store) =>\n new Promise((resolve, reject) => {\n const clearRequest = store.clear()\n clearRequest.onsuccess = () => resolve()\n clearRequest.onerror = () => reject(clearRequest.error)\n })\n )\n }\n\n getPrefixedKey<K extends StorageKey>(key: K): string {\n logger.debug('getPrefixedKey', key)\n throw new Error('Method not implemented.')\n }\n\n subscribeToStorageChanged(\n callback: (arg: {\n eventType: 'storageCleared' | 'entryModified'\n key: string | null\n oldValue: string | null\n newValue: string | null\n }) => {}\n ): Promise<void> {\n logger.debug('subscribeToStorageEvent', callback)\n throw new Error('Method not implemented.')\n }\n\n /**\n * Copies all key/value pairs from the source store into a target store.\n * @param targetDBName Name of the target database.\n * @param targetStoreName Name of the target object store.\n * @param skipKeys Keys to skip.\n * @param sourceStoreName (Optional) Source store name – defaults to the default store.\n */\n public async fillStore(\n targetDBName: string,\n targetStoreName: string,\n skipKeys: string[] = [],\n sourceStoreName: string = this.storeNames[0]\n ): Promise<void> {\n if (!this.isSupported) {\n logger.error('fillStore', 'IndexedDB not supported.')\n return\n }\n\n const targetDBRequest = indexedDB.open(targetDBName)\n\n targetDBRequest.onerror = (event: any) => {\n throw new Error(`Failed to open target database: ${event.target.error}`)\n }\n\n const targetDB = await new Promise<IDBDatabase>((resolve, reject) => {\n targetDBRequest.onsuccess = (event) => resolve((event.target as IDBOpenDBRequest).result)\n targetDBRequest.onerror = (event: any) => reject(event.target.error)\n })\n\n // Copy items from the source store to the target store, skipping any specified keys.\n await this.transaction('readonly', sourceStoreName, async (sourceStore) => {\n const getAllRequest = sourceStore.getAll()\n const getAllKeysRequest = sourceStore.getAllKeys()\n\n getAllRequest.onsuccess = async () => {\n getAllKeysRequest.onsuccess = async () => {\n const items = getAllRequest.result\n const keys = getAllKeysRequest.result\n\n if (!targetDB.objectStoreNames.contains(targetStoreName)) {\n logger.error(`${targetStoreName} not found. ${new Error().stack}`)\n return\n }\n\n const targetTransaction = targetDB.transaction(targetStoreName, 'readwrite')\n const targetStore = targetTransaction.objectStore(targetStoreName)\n\n keys\n .filter((key) => !skipKeys.includes(key.toString()))\n .forEach((key, index) => {\n targetStore.put(items[index], key)\n })\n\n targetTransaction.onerror = (event: any) => {\n logger.error('Transaction error: ', event.target.error)\n }\n }\n }\n getAllKeysRequest.onerror = () => {\n logger.error('Failed to getAllKeys from source:', getAllKeysRequest.error)\n }\n getAllRequest.onerror = () => {\n logger.error('Failed to getAll from source:', getAllRequest.error)\n }\n })\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"IndexedDBStorage.js","sourceRoot":"","sources":["../../../src/storage/IndexedDBStorage.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sEAAwF;AACxF,4CAAwC;AACxC,mEAAkF;AAElF,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC,kBAAkB,CAAC,CAAA;AAE7C,MAAa,gBAAiB,SAAQ,6BAAO;IAI3C;;;;OAIG;IACH,YACmB,SAAiB,8BAA8B,EAC/C,aAAuB,CAAC,iBAAiB,CAAC;QAE3D,KAAK,EAAE,CAAA;QAHU,WAAM,GA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AAC,KAAK,EAAE,CAAC,CAAA;4BAClE,OAAM;wBACR,CAAC;wBAED,MAAM,iBAAiB,GAAG,QAAQ,CAAC,WAAW,CAAC,eAAe,EAAE,WAAW,CAAC,CAAA;wBAC5E,MAAM,WAAW,GAAG,iBAAiB,CAAC,WAAW,CAAC,eAAe,CAAC,CAAA;wBAElE,IAAI;6BACD,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;6BACnD,OAAO,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;4BACtB,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAA;wBACpC,CAAC,CAAC,CAAA;wBAEJ,iBAAiB,CAAC,OAAO,GAAG,CAAC,KAAU,EAAE,EAAE;4BACzC,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;wBACzD,CAAC,CAAA;oBACH,CAAC,CAAA,CAAA;gBACH,CAAC,CAAA,CAAA;gBACD,iBAAiB,CAAC,OAAO,GAAG,GAAG,EAAE;oBAC/B,MAAM,CAAC,KAAK,CAAC,mCAAmC,EAAE,iBAAiB,CAAC,KAAK,CAAC,CAAA;gBAC5E,CAAC,CAAA;gBACD,aAAa,CAAC,OAAO,GAAG,GAAG,EAAE;oBAC3B,MAAM,CAAC,KAAK,CAAC,+BAA+B,EAAE,aAAa,CAAC,KAAK,CAAC,CAAA;gBACpE,CAAC,CAAA;YACH,CAAC,CAAA,CAAC,CAAA;QACJ,CAAC;KAAA;CACF;AA3TD,4CA2TC","sourcesContent":["import { Storage, StorageKey, StorageKeyReturnType } from '@tezos-x/octez.connect-types'\nimport { Logger } from '../utils/Logger'\nimport { isStorageKey, normalizeParsedStoredValue } from './storage-normalization'\n\nconst logger = new Logger('IndexedDBStorage')\n\nexport class IndexedDBStorage extends Storage {\n private db: IDBDatabase | null = null\n private isSupported: boolean = true\n\n /**\n * @param dbName Name of the database.\n * @param storeNames An array of object store names to create in the database.\n * The first store in the array will be used as the default if none is specified.\n */\n constructor(\n private readonly dbName: string = 'WALLET_CONNECT_V2_INDEXED_DB',\n private readonly storeNames: string[] = ['keyvaluestorage']\n ) {\n super()\n this.initDB()\n .then((db) => (this.db = db))\n .catch((err) => logger.error(err.message))\n }\n\n private isIndexedDBSupported() {\n if (typeof window !== 'undefined' && 'indexedDB' in window) {\n logger.log('isIndexedDBSupported', 'IndexedDB is supported in this browser.')\n return true\n } else {\n logger.error('isIndexedDBSupported', 'IndexedDB is not supported in this browser.')\n return false\n }\n }\n\n private async initDB(): Promise<IDBDatabase> {\n return new Promise((resolve, reject) => {\n this.isSupported = this.isIndexedDBSupported()\n if (!this.isSupported) {\n reject('IndexedDB is not supported.')\n return\n }\n\n const openRequest = indexedDB.open(this.dbName)\n\n openRequest.onupgradeneeded = () => {\n const db = openRequest.result\n // Create all required object stores\n this.storeNames.forEach((storeName) => {\n if (!db.objectStoreNames.contains(storeName)) {\n db.createObjectStore(storeName)\n }\n })\n }\n\n openRequest.onsuccess = (event: any) => {\n const db = event.target.result as IDBDatabase\n // Check if all stores exist – if not, perform an upgrade.\n const missingStores = this.storeNames.filter(\n (storeName) => !db.objectStoreNames.contains(storeName)\n )\n if (missingStores.length > 0) {\n db.close()\n const newVersion = db.version + 1\n const upgradeRequest = indexedDB.open(this.dbName, newVersion)\n\n upgradeRequest.onupgradeneeded = () => {\n const upgradedDB = upgradeRequest.result\n missingStores.forEach((storeName) => {\n if (!upgradedDB.objectStoreNames.contains(storeName)) {\n upgradedDB.createObjectStore(storeName)\n }\n })\n }\n\n upgradeRequest.onsuccess = (event: any) => {\n this.db = event.target.result as IDBDatabase\n resolve(this.db)\n }\n\n upgradeRequest.onerror = (event: any) => reject(event.target.error)\n } else {\n this.db = db\n resolve(db)\n }\n }\n\n openRequest.onerror = (event: any) => reject(event.target.error)\n })\n }\n\n /**\n * Performs a transaction on the given object store.\n * @param mode Transaction mode.\n * @param storeName The name of the object store.\n * @param operation The operation to perform with the object store.\n */\n private async transaction<T>(\n mode: IDBTransactionMode,\n storeName: string,\n operation: (store: IDBObjectStore) => Promise<T>\n ): Promise<T> {\n return new Promise((resolve, reject) => {\n if (!this.isSupported) {\n reject('IndexedDB is not supported.')\n return\n }\n\n if (!this.db?.objectStoreNames.contains(storeName)) {\n reject(`${storeName} not found. error: ${new Error().stack}`)\n return\n }\n\n const transaction = this.db.transaction(storeName, mode)\n const objectStore = transaction.objectStore(storeName)\n operation(objectStore).then(resolve).catch(reject)\n })\n }\n\n /**\n * Retrieves a value by key from the specified object store.\n * If no store is specified, the default (first in the list) is used.\n */\n public get<K extends StorageKey>(key: K, storeName?: string): Promise<StorageKeyReturnType[K]>\n public get(key: string, storeName?: string): Promise<string | undefined>\n public get(key: StorageKey | string, storeName: string = this.storeNames[0]): Promise<any> {\n const storedValue = this.transaction(\n 'readonly',\n storeName,\n (store) =>\n new Promise((resolve, reject) => {\n const getRequest = store.get(key)\n getRequest.onsuccess = () => resolve(getRequest.result)\n getRequest.onerror = () => reject(getRequest.error)\n })\n )\n\n return isStorageKey(key)\n ? storedValue.then((value) => normalizeParsedStoredValue(key, value))\n : storedValue\n }\n\n /**\n * Stores a key/value pair in the specified object store.\n */\n public set<K extends StorageKey>(\n key: K,\n value: StorageKeyReturnType[K],\n storeName?: string\n ): Promise<void>\n public set(key: string, value: string, storeName?: string): Promise<void>\n public set(\n key: StorageKey | string,\n value: any,\n storeName: string = this.storeNames[0]\n ): Promise<void> {\n if (value === undefined) {\n return this.delete(key, storeName)\n }\n\n return this.transaction(\n 'readwrite',\n storeName,\n (store) =>\n new Promise((resolve, reject) => {\n const putRequest = store.put(value, key)\n putRequest.onsuccess = () => resolve()\n putRequest.onerror = () => reject(putRequest.error)\n })\n )\n }\n\n /**\n * Deletes an entry by key from the specified object store.\n */\n public delete<K extends StorageKey>(key: K, storeName?: string): Promise<void>\n public delete(key: string, storeName?: string): Promise<void>\n public delete(key: StorageKey | string, storeName: string = this.storeNames[0]): Promise<void> {\n return this.transaction(\n 'readwrite',\n storeName,\n (store) =>\n new Promise((resolve, reject) => {\n const deleteRequest = store.delete(key)\n deleteRequest.onsuccess = () => resolve()\n deleteRequest.onerror = () => reject(deleteRequest.error)\n })\n )\n }\n\n /**\n * Retrieves all values from the specified object store.\n */\n public getAll(storeName?: string): Promise<string[]> {\n return this.transaction(\n 'readonly',\n storeName || this.storeNames[0],\n (store) =>\n new Promise((resolve, reject) => {\n const getAllRequest = store.getAll()\n getAllRequest.onsuccess = () => resolve(getAllRequest.result)\n getAllRequest.onerror = () => reject(getAllRequest.error)\n })\n )\n }\n\n /**\n * Retrieves all keys from the specified object store.\n */\n public getAllKeys(storeName?: string): Promise<IDBValidKey[]> {\n return this.transaction(\n 'readonly',\n storeName || this.storeNames[0],\n (store) =>\n new Promise((resolve, reject) => {\n const getAllKeysRequest = store.getAllKeys()\n getAllKeysRequest.onsuccess = () => resolve(getAllKeysRequest.result)\n getAllKeysRequest.onerror = () => reject(getAllKeysRequest.error)\n })\n )\n }\n\n /**\n * Clears all entries from the specified object store.\n */\n public clearStore(storeName?: string): Promise<void> {\n return this.transaction(\n 'readwrite',\n storeName || this.storeNames[0],\n (store) =>\n new Promise((resolve, reject) => {\n const clearRequest = store.clear()\n clearRequest.onsuccess = () => resolve()\n clearRequest.onerror = () => reject(clearRequest.error)\n })\n )\n }\n\n getPrefixedKey<K extends StorageKey>(key: K): string {\n logger.debug('getPrefixedKey', key)\n throw new Error('Method not implemented.')\n }\n\n subscribeToStorageChanged(\n callback: (arg: {\n eventType: 'storageCleared' | 'entryModified'\n key: string | null\n oldValue: string | null\n newValue: string | null\n }) => {}\n ): Promise<void> {\n logger.debug('subscribeToStorageEvent', callback)\n throw new Error('Method not implemented.')\n }\n\n /**\n * Copies all key/value pairs from the source store into a target store.\n * @param targetDBName Name of the target database.\n * @param targetStoreName Name of the target object store.\n * @param skipKeys Keys to skip.\n * @param sourceStoreName (Optional) Source store name – defaults to the default store.\n */\n public async fillStore(\n targetDBName: string,\n targetStoreName: string,\n skipKeys: string[] = [],\n sourceStoreName: string = this.storeNames[0]\n ): Promise<void> {\n if (!this.isSupported) {\n logger.error('fillStore', 'IndexedDB not supported.')\n return\n }\n\n const targetDBRequest = indexedDB.open(targetDBName)\n\n targetDBRequest.onerror = (event: any) => {\n throw new Error(`Failed to open target database: ${event.target.error}`)\n }\n\n const targetDB = await new Promise<IDBDatabase>((resolve, reject) => {\n targetDBRequest.onsuccess = (event) => resolve((event.target as IDBOpenDBRequest).result)\n targetDBRequest.onerror = (event: any) => reject(event.target.error)\n })\n\n // Copy items from the source store to the target store, skipping any specified keys.\n await this.transaction('readonly', sourceStoreName, async (sourceStore) => {\n const getAllRequest = sourceStore.getAll()\n const getAllKeysRequest = sourceStore.getAllKeys()\n\n getAllRequest.onsuccess = async () => {\n getAllKeysRequest.onsuccess = async () => {\n const items = getAllRequest.result\n const keys = getAllKeysRequest.result\n\n if (!targetDB.objectStoreNames.contains(targetStoreName)) {\n logger.error(`${targetStoreName} not found. ${new Error().stack}`)\n return\n }\n\n const targetTransaction = targetDB.transaction(targetStoreName, 'readwrite')\n const targetStore = targetTransaction.objectStore(targetStoreName)\n\n keys\n .filter((key) => !skipKeys.includes(key.toString()))\n .forEach((key, index) => {\n targetStore.put(items[index], key)\n })\n\n targetTransaction.onerror = (event: any) => {\n logger.error('Transaction error: ', event.target.error)\n }\n }\n }\n getAllKeysRequest.onerror = () => {\n logger.error('Failed to getAllKeys from source:', getAllKeysRequest.error)\n }\n getAllRequest.onerror = () => {\n logger.error('Failed to getAll from source:', getAllRequest.error)\n }\n })\n }\n}\n"]}
|
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.LocalStorage = void 0;
|
|
13
13
|
const octez_connect_types_1 = require("@tezos-x/octez.connect-types");
|
|
14
|
+
const storage_normalization_1 = require("./storage-normalization");
|
|
14
15
|
/**
|
|
15
16
|
* @internalapi
|
|
16
17
|
*
|
|
@@ -29,26 +30,14 @@ class LocalStorage extends octez_connect_types_1.Storage {
|
|
|
29
30
|
get(key) {
|
|
30
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
32
|
const value = localStorage.getItem(this.getPrefixedKey(key));
|
|
32
|
-
|
|
33
|
-
if (typeof octez_connect_types_1.defaultValues[key] === 'object') {
|
|
34
|
-
return JSON.parse(JSON.stringify(octez_connect_types_1.defaultValues[key]));
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
return octez_connect_types_1.defaultValues[key];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
try {
|
|
42
|
-
return JSON.parse(value);
|
|
43
|
-
}
|
|
44
|
-
catch (jsonParseError) {
|
|
45
|
-
return value; // TODO: Validate storage
|
|
46
|
-
}
|
|
47
|
-
}
|
|
33
|
+
return (0, storage_normalization_1.normalizeStoredValue)(key, value);
|
|
48
34
|
});
|
|
49
35
|
}
|
|
50
36
|
set(key, value) {
|
|
51
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
if (value === undefined) {
|
|
39
|
+
return this.delete(key);
|
|
40
|
+
}
|
|
52
41
|
if (typeof value === 'string') {
|
|
53
42
|
return localStorage.setItem(this.getPrefixedKey(key), value);
|
|
54
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalStorage.js","sourceRoot":"","sources":["../../../src/storage/LocalStorage.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"LocalStorage.js","sourceRoot":"","sources":["../../../src/storage/LocalStorage.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sEAAwF;AACxF,mEAA8D;AAE9D;;;;GAIG;AACH,MAAa,YAAa,SAAQ,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AAK,CAAC,GAAG,EAAE,CAAC;oBACf,QAAQ,CAAC;wBACP,SAAS,EAAE,gBAAgB;wBAC3B,GAAG,EAAE,IAAI;wBACT,QAAQ,EAAE,IAAI;wBACd,QAAQ,EAAE,IAAI;qBACf,CAAC,CAAA;gBACJ,CAAC;qBAAM,CAAC;oBACN,QAAQ,CAAC;wBACP,SAAS,EAAE,eAAe;wBAC1B,GAAG,EAAE,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC;wBACnC,QAAQ,EAAE,KAAK,CAAC,QAAQ;wBACxB,QAAQ,EAAE,KAAK,CAAC,QAAQ;qBACzB,CAAC,CAAA;gBACJ,CAAC;YACH,CAAC,EACD,KAAK,CACN,CAAA;QACH,CAAC;KAAA;IAEM,cAAc,CAAC,GAAW;QAC/B,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAA;IACpD,CAAC;CACF;AAhED,oCAgEC","sourcesContent":["import { Storage, StorageKey, StorageKeyReturnType } from '@tezos-x/octez.connect-types'\nimport { normalizeStoredValue } from './storage-normalization'\n\n/**\n * @internalapi\n *\n * A storage that can be used in the browser\n */\nexport class LocalStorage extends Storage {\n constructor(private readonly prefix?: string) {\n super()\n }\n public static async isSupported(): Promise<boolean> {\n return Promise.resolve(Boolean(typeof window !== 'undefined') && Boolean(window.localStorage))\n }\n\n public async get<K extends StorageKey>(key: K): Promise<StorageKeyReturnType[K]> {\n const value = localStorage.getItem(this.getPrefixedKey(key))\n\n return normalizeStoredValue(key, value)\n }\n\n public async set<K extends StorageKey>(key: K, value: StorageKeyReturnType[K]): Promise<void> {\n if (value === undefined) {\n return this.delete(key)\n }\n\n if (typeof value === 'string') {\n return localStorage.setItem(this.getPrefixedKey(key), value)\n } else {\n return localStorage.setItem(this.getPrefixedKey(key), JSON.stringify(value))\n }\n }\n\n public async delete<K extends StorageKey>(key: K): Promise<void> {\n return Promise.resolve(localStorage.removeItem(this.getPrefixedKey(key)))\n }\n\n public async subscribeToStorageChanged(\n callback: (arg: {\n eventType: 'storageCleared' | 'entryModified'\n key: string | null\n oldValue: string | null\n newValue: string | null\n }) => {}\n ): Promise<void> {\n window.addEventListener(\n 'storage',\n (event) => {\n if (!event.key) {\n callback({\n eventType: 'storageCleared',\n key: null,\n oldValue: null,\n newValue: null\n })\n } else {\n callback({\n eventType: 'entryModified',\n key: this.getPrefixedKey(event.key),\n oldValue: event.oldValue,\n newValue: event.newValue\n })\n }\n },\n false\n )\n }\n\n public getPrefixedKey(key: string): string {\n return this.prefix ? `${this.prefix}-${key}` : key\n }\n}\n"]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export declare class WCStorage {
|
|
2
|
-
private readonly localStorage;
|
|
3
2
|
private readonly indexedDB;
|
|
4
|
-
private channel;
|
|
3
|
+
private readonly channel;
|
|
5
4
|
onMessageHandler: ((type: string) => void) | undefined;
|
|
6
5
|
onErrorHandler: ((data: any) => void) | undefined;
|
|
7
6
|
constructor();
|