From 975a0fe335074dfdf145aeeaea22488a8b58dcbd Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 13 Dec 2023 14:44:37 +0000 Subject: [PATCH] chore(release): set `package.json` to 1.0.0-beta.8 [skip ci] # [1.0.0-beta.8](https://github.com/ChainSafe/cypress-polkadot-wallet/compare/v1.0.0-beta.7...v1.0.0-beta.8) (2023-12-13) ### Bug Fixes * refactor ([323b312](https://github.com/ChainSafe/cypress-polkadot-wallet/commit/323b31202db131c33ccffbea03d9b03c510dbc37)) --- CHANGELOG.md | 7 ++++ packages/plugin/dist/extension.d.ts | 45 ++++++++++++++++++++++++ packages/plugin/dist/extension.js | 1 - packages/plugin/dist/index.d.ts | 54 +++++++++++++++++++++++++++++ packages/plugin/dist/index.js | 36 +++++++++++++++++-- packages/plugin/dist/types.d.ts | 5 +++ packages/plugin/dist/types.js | 1 + 7 files changed, 145 insertions(+), 4 deletions(-) create mode 100644 packages/plugin/dist/extension.d.ts create mode 100644 packages/plugin/dist/index.d.ts create mode 100644 packages/plugin/dist/types.d.ts create mode 100644 packages/plugin/dist/types.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b4fe6c..1c8fb49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# [1.0.0-beta.8](https://github.com/ChainSafe/cypress-polkadot-wallet/compare/v1.0.0-beta.7...v1.0.0-beta.8) (2023-12-13) + + +### Bug Fixes + +* refactor ([323b312](https://github.com/ChainSafe/cypress-polkadot-wallet/commit/323b31202db131c33ccffbea03d9b03c510dbc37)) + # [1.0.0-beta.7](https://github.com/ChainSafe/cypress-polkadot-wallet/compare/v1.0.0-beta.6...v1.0.0-beta.7) (2023-12-13) diff --git a/packages/plugin/dist/extension.d.ts b/packages/plugin/dist/extension.d.ts new file mode 100644 index 0000000..a2f4921 --- /dev/null +++ b/packages/plugin/dist/extension.d.ts @@ -0,0 +1,45 @@ +import { Injected, InjectedAccounts } from '@polkadot/extension-inject/types'; +import { Keyring } from '@polkadot/keyring'; +import { SignerPayloadJSON, SignerResult } from '@polkadot/types/types'; +import { InjectedAccountWitMnemonic } from './types'; +export interface AuthRequest { + id: number; + origin: string; + resolve: (accountAddresses: string[]) => void; + reject: (reason: string) => void; +} +export interface TxRequest { + id: number; + payload: SignerPayloadJSON; + resolve: () => void; + reject: (reason: string) => void; +} +export type TxRequests = Record; +export type AuthRequests = Record; +export type EnableRequest = number; +export declare class Extension { + authRequests: AuthRequests; + accounts: InjectedAccountWitMnemonic[]; + txRequests: TxRequests; + keyring: Keyring | undefined; + allowedOrigins: Record; + reset: () => void; + init: (accounts: InjectedAccountWitMnemonic[], allowedOrigin?: string) => Promise; + getInjectedEnable: () => { + 'polkadot-js': { + enable: (origin: string) => Promise<{ + accounts: InjectedAccounts; + signer: { + signPayload: (payload: SignerPayloadJSON) => Promise; + }; + }> | Promise; + version: string; + }; + }; + getAuthRequests: () => AuthRequests; + enableAuth: (id: number, accountAddresses: string[]) => void; + rejectAuth: (id: number, reason: string) => void; + getTxRequests: () => TxRequests; + approveTx: (id: number) => void; + rejectTx: (id: number, reason: string) => void; +} diff --git a/packages/plugin/dist/extension.js b/packages/plugin/dist/extension.js index 825e715..eb09492 100644 --- a/packages/plugin/dist/extension.js +++ b/packages/plugin/dist/extension.js @@ -106,4 +106,3 @@ export class Extension { this.txRequests[id].reject(reason); }; } -//# sourceMappingURL=extension.js.map \ No newline at end of file diff --git a/packages/plugin/dist/index.d.ts b/packages/plugin/dist/index.d.ts new file mode 100644 index 0000000..b8943df --- /dev/null +++ b/packages/plugin/dist/index.d.ts @@ -0,0 +1,54 @@ +/// +import { AuthRequests, TxRequests } from './extension'; +import { InjectedAccountWitMnemonic } from './types'; +declare global { + namespace Cypress { + interface Chainable { + /** + * Initialized the Polkadot extension. If an origin is passed there is no need to authorize the first connection for Dapps of this origin + * @param {InjectedAccount[]} accounts - Accounts to load into the extension. + * @param {string | undefined} origin - Dapp name to automatically share accounts without needing to authorize + * @param {string} origin - Dapp name to allow the accounts for automatically + * @example cy.initExtension([{ address: '7NPoMQbiA6trJKkjB35uk96MeJD4PGWkLQLH7k7hXEkZpiba', name: 'Alice', type: 'sr25519'}], 'Multix') + */ + initExtension: (accounts: InjectedAccountWitMnemonic[], origin?: string) => Chainable; + /** + * Read the authentication request queue + * @example cy.getAuthRequests().then((authQueue) => { cy.wrap(Object.values(authQueue).length).should("eq", 1) }) + */ + getAuthRequests: () => Chainable; + /** + * Authorize a specific request + * @param {number} id - the id of the request to authorize. This id is part of the getAuthRequests object response. + * @param {string[]} accountAddresses - the account addresses to share with the applications. These addresses must be part of the ones shared in the `initExtension` + * @example cy.enableAuth(1694443839903, ["7NPoMQbiA6trJKkjB35uk96MeJD4PGWkLQLH7k7hXEkZpiba"]) + */ + enableAuth: (id: number, accountAddresses: string[]) => void; + /** + * Reject a specific authentication request + * @param {number} id - the id of the request to reject. This id is part of the getAuthRequests object response. + * @param {reason} reason - the reason for the rejection + * @example cy.rejectAuth(1694443839903, "Cancelled") + */ + rejectAuth: (id: number, reason: string) => void; + /** + * Read the tx request queue + * @example cy.getTxRequests().then((txQueue) => { cy.wrap(Object.values(txQueue).length).should("eq", 1) }) + */ + getTxRequests: () => Chainable; + /** + * Authorize a specific transaction + * @param {number} id - the id of the request to approve. This id is part of the getTxRequests object response. + * @example cy.approveTx(1694443839903) + */ + approveTx: (id: number) => void; + /** + * Reject a specific transaction + * @param {number} id - the id of the tx request to reject. This id is part of the getTxRequests object response. + * @param {reason} reason - the reason for the rejection + * @example cy.rejectTx(1694443839903, "Cancelled") + */ + rejectTx: (id: number, reason: string) => void; + } + } +} diff --git a/packages/plugin/dist/index.js b/packages/plugin/dist/index.js index c8728a0..40237b2 100644 --- a/packages/plugin/dist/index.js +++ b/packages/plugin/dist/index.js @@ -1,3 +1,33 @@ -export * from './commands'; -export * from './extension'; -//# sourceMappingURL=index.js.map \ No newline at end of file +import { Extension } from './extension'; +const extension = new Extension(); +const injectExtension = (win, extension) => { + Object.defineProperty(win, 'injectedWeb3', { + get: () => extension.getInjectedEnable(), + set: () => { } + }); +}; +Cypress.Commands.add('initExtension', (accounts, origin) => { + cy.log('Initializing extension'); + cy.wrap(extension.init(accounts, origin)); + return cy.window().then((win) => { + injectExtension(win, extension); + }); +}); +Cypress.Commands.add('getAuthRequests', () => { + return cy.wrap(extension.getAuthRequests()); +}); +Cypress.Commands.add('enableAuth', (id, accountAddresses) => { + return extension.enableAuth(id, accountAddresses); +}); +Cypress.Commands.add('rejectAuth', (id, reason) => { + return extension.rejectAuth(id, reason); +}); +Cypress.Commands.add('getTxRequests', () => { + return cy.wrap(extension.getTxRequests()); +}); +Cypress.Commands.add('approveTx', (id) => { + return extension.approveTx(id); +}); +Cypress.Commands.add('rejectTx', (id, reason) => { + return extension.rejectTx(id, reason); +}); diff --git a/packages/plugin/dist/types.d.ts b/packages/plugin/dist/types.d.ts new file mode 100644 index 0000000..7bc784b --- /dev/null +++ b/packages/plugin/dist/types.d.ts @@ -0,0 +1,5 @@ +import { InjectedAccount } from '@polkadot/extension-inject/types'; +export interface InjectedAccountWitMnemonic extends InjectedAccount { + mnemonic: string; + publicKey?: string; +} diff --git a/packages/plugin/dist/types.js b/packages/plugin/dist/types.js new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/packages/plugin/dist/types.js @@ -0,0 +1 @@ +export {};