@metamask-previews/eth-snap-keyring 4.3.2-672cc7b
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/CHANGELOG.md +344 -0
- package/README.md +71 -0
- package/dist/CaseInsensitiveMap.d.ts +62 -0
- package/dist/CaseInsensitiveMap.js +82 -0
- package/dist/CaseInsensitiveMap.js.map +1 -0
- package/dist/DeferredPromise.d.ts +15 -0
- package/dist/DeferredPromise.js +30 -0
- package/dist/DeferredPromise.js.map +1 -0
- package/dist/SnapIdMap.d.ts +202 -0
- package/dist/SnapIdMap.js +242 -0
- package/dist/SnapIdMap.js.map +1 -0
- package/dist/SnapKeyring.d.ts +182 -0
- package/dist/SnapKeyring.js +599 -0
- package/dist/SnapKeyring.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +4 -0
- package/dist/logger.js +8 -0
- package/dist/logger.js.map +1 -0
- package/dist/types.d.ts +12 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/dist/util.d.ts +52 -0
- package/dist/util.js +76 -0
- package/dist/util.js.map +1 -0
- package/package.json +72 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SnapKeyring.js","sourceRoot":"","sources":["../src/SnapKeyring.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,uCAAoD;AAEpD,yDAA8D;AAc9D,yEAWwC;AACxC,uEAA4E;AAI5E,uDAAqE;AAErE,2CAIyB;AACzB,mCAAsC;AACtC,+BAAkC;AAElC,uDAAoD;AACpD,qCAAgD;AAChD,2CAAwC;AAExC,mCAA4C;AAC5C,iCAMgB;AAEH,QAAA,iBAAiB,GAAG,cAAc,CAAC;AA2ChD;;GAEG;AACH,MAAa,WAAY,SAAQ,qBAAY;IAgC3C;;;;;;OAMG;IACH,YAAY,UAA0B,EAAE,SAA+B;QACrE,KAAK,EAAE,CAAC;;Q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SAAS,MAAM,cAAc,CAAC,CAAC;KAChD;IACD,MAAM,cAAc,GAAG,uBAAA,IAAI,kEAAuB,MAA3B,IAAI,EAAwB,IAAI,CAAC,CAAC;IACzD,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QACpC,MAAM,IAAI,KAAK,CACb,wBAAwB,MAAM,uCAAuC,MAAM,GAAG,CAC/E,CAAC;KACH;AACH,CAAC,qEA8Pe,OAAe;IAI7B,OAAO,CACL,CAAC,GAAG,uBAAA,IAAI,6BAAU,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAChD,IAAA,uBAAgB,EAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAC3C,IAAI,IAAA,iBAAU,EAAC,YAAY,OAAO,aAAa,CAAC,CAClD,CAAC;AACJ,CAAC,uEASC,MAAc;IAEd,MAAM,IAAI,GAAG,uBAAA,IAAI,+BAAY,CAAC,aAAa,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC1D,OAAO,IAAI;QACT,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;QACzE,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC,mFAQsB,IAAU;IAC/B,OAAO,CACL,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,EAAE,cAAc;QACrE,EAAE,CACH,CAAC;AACJ,CAAC;AArxBM,gBAAI,GAAW,yBAAiB,CAAC","sourcesContent":["import type { TypedTransaction } from '@ethereumjs/tx';\nimport { TransactionFactory } from '@ethereumjs/tx';\nimport type { TypedDataV1, TypedMessage } from '@metamask/eth-sig-util';\nimport { SignTypedDataVersion } from '@metamask/eth-sig-util';\nimport type {\n KeyringAccount,\n KeyringExecutionContext,\n KeyringResponse,\n} from '@metamask/keyring-api';\nimport type {\n BtcMethod,\n EthBaseTransaction,\n EthBaseUserOperation,\n EthUserOperation,\n EthUserOperationPatch,\n InternalAccount,\n} from '@metamask/keyring-internal-api';\nimport {\n AccountCreatedEventStruct,\n AccountDeletedEventStruct,\n AccountUpdatedEventStruct,\n EthBaseUserOperationStruct,\n EthBytesStruct,\n EthMethod,\n EthUserOperationPatchStruct,\n KeyringEvent,\n RequestApprovedEventStruct,\n RequestRejectedEventStruct,\n} from '@metamask/keyring-internal-api';\nimport { KeyringSnapControllerClient } from '@metamask/keyring-snap-client';\nimport type { SnapController } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { Snap } from '@metamask/snaps-utils';\nimport { assert, mask, object, string } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport {\n bigIntToHex,\n KnownCaipNamespace,\n toCaipChainId,\n} from '@metamask/utils';\nimport { EventEmitter } from 'events';\nimport { v4 as uuid } from 'uuid';\n\nimport { DeferredPromise } from './DeferredPromise';\nimport { projectLogger as log } from './logger';\nimport { SnapIdMap } from './SnapIdMap';\nimport type { SnapMessage } from './types';\nimport { SnapMessageStruct } from './types';\nimport {\n equalsIgnoreCase,\n strictMask,\n throwError,\n toJson,\n unique,\n} from './util';\n\nexport const SNAP_KEYRING_TYPE = 'Snap Keyring';\n\n// TODO: to be removed when this is added to the keyring-api\n\ntype AccountMethod = EthMethod | BtcMethod;\n\n/**\n * Snap keyring state.\n *\n * This state is persisted by the keyring controller and passed to the Snap\n * keyring when it's created.\n */\nexport type KeyringState = {\n accounts: Record<string, { account: KeyringAccount; snapId: SnapId }>;\n};\n\n/**\n * Snap keyring callbacks.\n *\n * These callbacks are used to interact with other components.\n */\nexport type SnapKeyringCallbacks = {\n saveState: () => Promise<void>;\n\n addressExists(address: string): Promise<boolean>;\n\n addAccount(\n address: string,\n snapId: SnapId,\n handleUserInput: (accepted: boolean) => Promise<void>,\n accountNameSuggestion?: string,\n displayConfirmation?: boolean,\n ): Promise<void>;\n\n removeAccount(\n address: string,\n snapId: SnapId,\n handleUserInput: (accepted: boolean) => Promise<void>,\n ): Promise<void>;\n\n redirectUser(snapId: SnapId, url: string, message: string): Promise<void>;\n};\n\n/**\n * Keyring bridge implementation to support Snaps.\n */\nexport class SnapKeyring extends EventEmitter {\n static type: string = SNAP_KEYRING_TYPE;\n\n type: string;\n\n /**\n * Client used to call the Snap keyring.\n */\n #snapClient: KeyringSnapControllerClient;\n\n /**\n * Mapping between account IDs and an object that contains the associated\n * account object and Snap ID.\n */\n #accounts: SnapIdMap<{\n account: KeyringAccount;\n snapId: SnapId;\n }>;\n\n /**\n * Mapping between request IDs and their deferred promises.\n */\n #requests: SnapIdMap<{\n promise: DeferredPromise<any>;\n snapId: SnapId;\n }>;\n\n /**\n * Callbacks used to interact with other components.\n */\n #callbacks: SnapKeyringCallbacks;\n\n /**\n * Create a new Snap keyring.\n *\n * @param controller - Snaps controller.\n * @param callbacks - Callbacks used to interact with other components.\n * @returns A new Snap keyring.\n */\n constructor(controller: SnapController, callbacks: SnapKeyringCallbacks) {\n super();\n this.type = SnapKeyring.type;\n this.#snapClient = new KeyringSnapControllerClient({ controller });\n this.#requests = new SnapIdMap();\n this.#accounts = new SnapIdMap();\n this.#callbacks = callbacks;\n }\n\n /**\n * Handle an Account Created event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountCreated(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, AccountCreatedEventStruct);\n const { account, accountNameSuggestion, displayConfirmation } =\n message.params;\n\n // The UI still uses the account address to identify accounts, so we need\n // to block the creation of duplicate accounts for now to prevent accounts\n // from being overwritten.\n if (await this.#callbacks.addressExists(account.address.toLowerCase())) {\n throw new Error(`Account address '${account.address}' already exists`);\n }\n\n // A Snap could try to create an account with a different address but with\n // an existing ID, so the above test only is not enough.\n if (this.#accounts.has(snapId, account.id)) {\n throw new Error(`Account '${account.id}' already exists`);\n }\n\n await this.#callbacks.addAccount(\n account.address.toLowerCase(),\n snapId,\n async (accepted: boolean) => {\n if (accepted) {\n this.#accounts.set(account.id, { account, snapId });\n await this.#callbacks.saveState();\n }\n },\n accountNameSuggestion,\n displayConfirmation,\n );\n return null;\n }\n\n /**\n * Handle an Account Updated event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountUpdated(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, AccountUpdatedEventStruct);\n const { account: newAccount } = message.params;\n const { account: oldAccount } =\n this.#accounts.get(snapId, newAccount.id) ??\n throwError(`Account '${newAccount.id}' not found`);\n\n // The address of the account cannot be changed. In the future, we will\n // support changing the address of an account since it will be required to\n // support UTXO-based chains.\n if (!equalsIgnoreCase(oldAccount.address, newAccount.address)) {\n throw new Error(`Cannot change address of account '${newAccount.id}'`);\n }\n\n this.#accounts.set(newAccount.id, { account: newAccount, snapId });\n await this.#callbacks.saveState();\n return null;\n }\n\n /**\n * Handle an Account Deleted event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountDeleted(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, AccountDeletedEventStruct);\n const { id } = message.params;\n const entry = this.#accounts.get(snapId, id);\n\n // We can ignore the case where the account was already removed from the\n // keyring, making the deletion idempotent.\n //\n // This happens when the keyring calls the Snap to delete an account, and\n // the Snap calls the keyring back with an `AccountDeleted` event.\n if (entry === undefined) {\n return null;\n }\n\n // At this point we know that the account exists, so we can safely\n // destructure it.\n const {\n account: { address },\n } = entry;\n\n await this.#callbacks.removeAccount(\n address.toLowerCase(),\n snapId,\n async (accepted) => {\n if (accepted) {\n await this.#callbacks.saveState();\n }\n },\n );\n return null;\n }\n\n /**\n * Handle an Request Approved event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleRequestApproved(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, RequestApprovedEventStruct);\n const { id, result } = message.params;\n const { promise } =\n this.#requests.get(snapId, id) ?? throwError(`Request '${id}' not found`);\n\n this.#requests.delete(snapId, id);\n promise.resolve(result);\n return null;\n }\n\n /**\n * Handle an Request Rejected event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleRequestRejected(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, RequestRejectedEventStruct);\n const { id } = message.params;\n const { promise } =\n this.#requests.get(snapId, id) ?? throwError(`Request '${id}' not found`);\n\n this.#requests.delete(snapId, id);\n promise.reject(new Error(`Request rejected by user or snap.`));\n return null;\n }\n\n /**\n * Handle a message from a Snap.\n *\n * @param snapId - ID of the Snap.\n * @param message - Message sent by the Snap.\n * @returns The execution result.\n */\n async handleKeyringSnapMessage(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<Json> {\n assert(message, SnapMessageStruct);\n switch (message.method) {\n case KeyringEvent.AccountCreated: {\n return this.#handleAccountCreated(snapId, message);\n }\n\n case KeyringEvent.AccountUpdated: {\n return this.#handleAccountUpdated(snapId, message);\n }\n\n case KeyringEvent.AccountDeleted: {\n return this.#handleAccountDeleted(snapId, message);\n }\n\n case KeyringEvent.RequestApproved: {\n return this.#handleRequestApproved(snapId, message);\n }\n\n case KeyringEvent.RequestRejected: {\n return this.#handleRequestRejected(snapId, message);\n }\n\n default:\n throw new Error(`Method not supported: ${message.method}`);\n }\n }\n\n /**\n * Serialize the keyring state.\n *\n * @returns Serialized keyring state.\n */\n async serialize(): Promise<KeyringState> {\n return {\n accounts: this.#accounts.toObject(),\n };\n }\n\n /**\n * Deserialize the keyring state into this keyring.\n *\n * @param state - Serialized keyring state.\n */\n async deserialize(state: KeyringState | undefined): Promise<void> {\n // If the state is undefined, it means that this is a new keyring, so we\n // don't need to do anything.\n if (state === undefined) {\n return;\n }\n this.#accounts = SnapIdMap.fromObject(state.accounts);\n }\n\n /**\n * Get the addresses of the accounts in this keyring.\n *\n * @returns The addresses of the accounts in this keyring.\n */\n async getAccounts(): Promise<string[]> {\n return unique(\n [...this.#accounts.values()].map(({ account }) =>\n account.address.toLowerCase(),\n ),\n );\n }\n\n /**\n * Get the addresses of the accounts associated with a given Snap.\n *\n * @param snapId - Snap ID to filter by.\n * @returns The addresses of the accounts associated with the given Snap.\n */\n async getAccountsBySnapId(snapId: SnapId): Promise<string[]> {\n return unique(\n [...this.#accounts.values()]\n .filter(({ snapId: accountSnapId }) => accountSnapId === snapId)\n .map(({ account }) => account.address.toLowerCase()),\n );\n }\n\n /**\n * Submit a request to a Snap.\n *\n * @param opts - Request options.\n * @param opts.address - Account address.\n * @param opts.method - Method to call.\n * @param opts.params - Method parameters.\n * @param opts.chainId - Selected chain ID (CAIP-2).\n * @param opts.expectSync - Whether the request should be synchronous.\n * @returns Promise that resolves to the result of the method call.\n */\n async #submitRequest<Response extends Json>({\n address,\n method,\n params,\n chainId = '',\n expectSync = false,\n }: {\n address: string;\n method: string;\n params?: Json[] | Record<string, Json>;\n chainId?: string;\n expectSync?: boolean;\n }): Promise<Json> {\n const { account, snapId } = this.#resolveAddress(address);\n if (!this.#hasMethod(account, method as AccountMethod)) {\n throw new Error(\n `Method '${method}' not supported for account ${account.address}`,\n );\n }\n\n const requestId = uuid();\n\n // Create the promise before calling the Snap to prevent a race condition\n // where the Snap responds before we have a chance to create it.\n const promise = this.#createRequestPromise<Response>(requestId, snapId);\n\n const response = await this.#submitSnapRequest({\n snapId,\n requestId,\n account,\n method: method as AccountMethod,\n params,\n chainId,\n });\n\n // Some methods, like the ones used to prepare and patch user operations,\n // require the Snap to answer synchronously in order to work with the\n // confirmation flow. This check lets the caller enforce this behavior.\n if (expectSync && response.pending) {\n throw new Error(\n `Request '${requestId}' to snap '${snapId}' is pending and expectSync is true.`,\n );\n }\n\n // If the Snap answers synchronously, the promise must be removed from the\n // map to prevent a leak.\n if (!response.pending) {\n return this.#handleSyncResponse(response, requestId, snapId);\n }\n\n // If the Snap answers asynchronously, we will inform the user with a redirect\n if (response.redirect?.message || response.redirect?.url) {\n await this.#handleAsyncResponse(response.redirect, snapId);\n }\n\n return promise.promise;\n }\n\n /**\n * Check if an account supports the given method.\n *\n * @param account - The account object to check for method support.\n * @param method - The Ethereum method to validate.\n * @returns `true` if the method is supported, `false` otherwise.\n */\n #hasMethod(account: KeyringAccount, method: AccountMethod): boolean {\n return (account.methods as AccountMethod[]).includes(method);\n }\n\n /**\n * Creates a promise for a request and adds it to the map of requests.\n *\n * @param requestId - The unique identifier for the request.\n * @param snapId - The Snap ID associated with the request.\n * @returns A DeferredPromise instance.\n */\n #createRequestPromise<Response>(\n requestId: string,\n snapId: SnapId,\n ): DeferredPromise<Response> {\n const promise = new DeferredPromise<Response>();\n this.#requests.set(requestId, { promise, snapId });\n return promise;\n }\n\n /**\n * Submits a request to a Snap.\n *\n * @param options - The options for the Snap request.\n * @param options.snapId - The Snap ID to submit the request to.\n * @param options.requestId - The unique identifier for the request.\n * @param options.account - The account to use for the request.\n * @param options.method - The Ethereum method to call.\n * @param options.params - The parameters to pass to the method, can be undefined.\n * @param options.chainId - The chain ID to use for the request, can be an empty string.\n * @returns A promise that resolves to the keyring response from the Snap.\n * @throws An error if the Snap fails to respond or if there's an issue with the request submission.\n */\n async #submitSnapRequest({\n snapId,\n requestId,\n account,\n method,\n params,\n chainId,\n }: {\n snapId: SnapId;\n requestId: string;\n account: KeyringAccount;\n method: AccountMethod;\n params?: Json[] | Record<string, Json> | undefined;\n chainId: string;\n }): Promise<KeyringResponse> {\n try {\n const request = {\n id: requestId,\n scope: chainId,\n account: account.id,\n request: {\n method,\n ...(params !== undefined && { params }),\n },\n };\n\n log('Submit Snap request: ', request);\n\n return await this.#snapClient.withSnapId(snapId).submitRequest(request);\n } catch (error) {\n log('Snap Request failed: ', { requestId });\n\n // If the Snap failed to respond, delete the promise to prevent a leak.\n this.#requests.delete(snapId, requestId);\n throw error;\n }\n }\n\n /**\n * Handles the synchronous response from a Snap. If the response indicates the request is not pending, it removes the request from the map.\n *\n * @param response - The response from the Snap.\n * @param response.pending - A boolean indicating if the request is pending should always be false in this context.\n * @param response.result - The result data from the Snap response.\n * @param requestId - The unique identifier for the request.\n * @param snapId - The Snap ID associated with the request.\n * @returns The result from the Snap response.\n */\n #handleSyncResponse(\n response: { pending: false; result: Json },\n requestId: string,\n snapId: SnapId,\n ): Json {\n this.#requests.delete(snapId, requestId);\n return response.result;\n }\n\n /**\n * Handles the async redirect and response from a Snap. Validates the redirect URL and informs the user with a message and URL if provided.\n *\n * @param redirect - The redirect information including message and URL.\n * @param redirect.message - The message to show to the user if provided.\n * @param redirect.url - The URL to redirect the user to if provided.\n * @param snapId - The Snap ID associated with the request.\n * @throws An error if the redirect URL is not an allowed origin for the Snap.\n */\n async #handleAsyncResponse(\n redirect: { message?: string; url?: string },\n snapId: SnapId,\n ) {\n const { message = '', url = '' } = redirect;\n if (url) {\n this.#validateRedirectUrl(url, snapId);\n }\n await this.#callbacks.redirectUser(snapId, url, message);\n }\n\n /**\n * Validates if the redirect URL is in the Snap's allowed origins.\n *\n * @param url - The URL to validate.\n * @param snapId - The Snap ID to check allowed origins for.\n * @throws An error if the URL's origin is not in the Snap's allowed origins.\n */\n #validateRedirectUrl(url: string, snapId: SnapId) {\n const { origin } = new URL(url);\n const snap = this.#snapClient.getController().get(snapId);\n if (!snap) {\n throw new Error(`Snap '${snapId}' not found.`);\n }\n const allowedOrigins = this.#getSnapAllowedOrigins(snap);\n if (!allowedOrigins.includes(origin)) {\n throw new Error(\n `Redirect URL domain '${origin}' is not an allowed origin by snap '${snapId}'`,\n );\n }\n }\n\n /**\n * Sign a transaction.\n *\n * @param address - Sender's address.\n * @param transaction - Transaction.\n * @param _opts - Transaction options (not used).\n */\n async signTransaction(\n address: string,\n transaction: TypedTransaction,\n _opts = {},\n ): Promise<Json | TypedTransaction> {\n const chainId = transaction.common.chainId();\n const tx = toJson({\n ...transaction.toJSON(),\n from: address,\n type: `0x${transaction.type.toString(16)}`,\n chainId: bigIntToHex(chainId),\n });\n\n const signedTx = await this.#submitRequest({\n address,\n method: EthMethod.SignTransaction,\n params: [tx],\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, `${chainId}`),\n });\n\n // ! It's *** CRITICAL *** that we mask the signature here, otherwise the\n // ! Snap could overwrite the transaction.\n const signature = mask(\n signedTx,\n object({\n r: string(),\n s: string(),\n v: string(),\n }),\n );\n\n return TransactionFactory.fromTxData({\n ...(tx as Record<string, Json>),\n r: signature.r,\n s: signature.s,\n v: signature.v,\n });\n }\n\n /**\n * Sign a typed data message.\n *\n * @param address - Signer's address.\n * @param data - Data to sign.\n * @param opts - Signing options.\n * @returns The signature.\n */\n async signTypedData(\n address: string,\n data: Record<string, unknown>[] | TypedDataV1 | TypedMessage<any>,\n opts = { version: SignTypedDataVersion.V1 },\n ): Promise<string> {\n const methods = {\n [SignTypedDataVersion.V1]: EthMethod.SignTypedDataV1,\n [SignTypedDataVersion.V3]: EthMethod.SignTypedDataV3,\n [SignTypedDataVersion.V4]: EthMethod.SignTypedDataV4,\n };\n\n // Use 'V1' by default to match other keyring implementations. V1 will be\n // used if the version is not specified or not supported.\n const method = methods[opts.version] || EthMethod.SignTypedDataV1;\n\n // Extract chain ID as if it was a typed message (as defined by EIP-712), if\n // input is not a typed message, then chain ID will be undefined!\n const chainId = (data as TypedMessage<any>).domain?.chainId;\n\n return strictMask(\n await this.#submitRequest({\n address,\n method,\n params: toJson<Json[]>([address, data]),\n ...(chainId === undefined\n ? {}\n : {\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, `${chainId}`),\n }),\n }),\n EthBytesStruct,\n );\n }\n\n /**\n * Sign a message.\n *\n * @param address - Signer's address.\n * @param hash - Data to sign.\n * @returns The signature.\n */\n async signMessage(address: string, hash: any): Promise<string> {\n return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.Sign,\n params: toJson<Json[]>([address, hash]),\n }),\n EthBytesStruct,\n );\n }\n\n /**\n * Sign a personal message.\n *\n * Note: KeyringController says this should return a Buffer but it actually\n * expects a string.\n *\n * @param address - Signer's address.\n * @param data - Data to sign.\n * @returns Promise of the signature.\n */\n async signPersonalMessage(address: string, data: any): Promise<string> {\n return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.PersonalSign,\n params: toJson<Json[]>([data, address]),\n }),\n EthBytesStruct,\n );\n }\n\n /**\n * Convert a base transaction to a base UserOperation.\n *\n * @param address - Address of the sender.\n * @param transactions - Base transactions to include in the UserOperation.\n * @param context - Keyring execution context.\n * @returns A pseudo-UserOperation that can be used to construct a real.\n */\n async prepareUserOperation(\n address: string,\n transactions: EthBaseTransaction[],\n context: KeyringExecutionContext,\n ): Promise<EthBaseUserOperation> {\n return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.PrepareUserOperation,\n params: toJson<Json[]>(transactions),\n expectSync: true,\n // We assume the chain ID is already well formatted\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, context.chainId),\n }),\n EthBaseUserOperationStruct,\n );\n }\n\n /**\n * Patches properties of a UserOperation. Currently, only the\n * `paymasterAndData` can be patched.\n *\n * @param address - Address of the sender.\n * @param userOp - UserOperation to patch.\n * @param context - Keyring execution context.\n * @returns A patch to apply to the UserOperation.\n */\n async patchUserOperation(\n address: string,\n userOp: EthUserOperation,\n context: KeyringExecutionContext,\n ): Promise<EthUserOperationPatch> {\n return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.PatchUserOperation,\n params: toJson<Json[]>([userOp]),\n expectSync: true,\n // We assume the chain ID is already well formatted\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, context.chainId),\n }),\n EthUserOperationPatchStruct,\n );\n }\n\n /**\n * Signs an UserOperation.\n *\n * @param address - Address of the sender.\n * @param userOp - UserOperation to sign.\n * @param context - Leyring execution context.\n * @returns The signature of the UserOperation.\n */\n async signUserOperation(\n address: string,\n userOp: EthUserOperation,\n context: KeyringExecutionContext,\n ): Promise<string> {\n return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.SignUserOperation,\n params: toJson<Json[]>([userOp]),\n // We assume the chain ID is already well formatted\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, context.chainId),\n }),\n EthBytesStruct,\n );\n }\n\n /**\n * Gets the private data associated with the given address so\n * that it may be exported.\n *\n * If this keyring contains duplicate public keys the first\n * matching address is exported.\n *\n * Used by the UI to export an account.\n *\n * @param _address - Address of the account to export.\n */\n exportAccount(_address: string): [Uint8Array, Json] | undefined {\n throw new Error('Exporting accounts from snaps is not supported.');\n }\n\n /**\n * Removes the account matching the given address.\n *\n * @param address - Address of the account to remove.\n */\n async removeAccount(address: string): Promise<void> {\n const { account, snapId } = this.#resolveAddress(address);\n\n // Always remove the account from the maps, even if the Snap is going to\n // fail to delete it.\n this.#accounts.delete(snapId, account.id);\n\n try {\n await this.#snapClient.withSnapId(snapId).deleteAccount(account.id);\n } catch (error) {\n // If the Snap failed to delete the account, log the error and continue\n // with the account deletion, otherwise the account will be stuck in the\n // keyring.\n console.error(\n `Account '${address}' may not have been removed from snap '${snapId}':`,\n error,\n );\n }\n }\n\n /**\n * Resolve an address to an account and Snap ID.\n *\n * @param address - Address of the account to resolve.\n * @returns Account and Snap ID. Throws if the account or Snap ID is not\n * found.\n */\n #resolveAddress(address: string): {\n account: KeyringAccount;\n snapId: SnapId;\n } {\n return (\n [...this.#accounts.values()].find(({ account }) =>\n equalsIgnoreCase(account.address, address),\n ) ?? throwError(`Account '${address}' not found`)\n );\n }\n\n /**\n * Get the metadata of a Snap keyring account.\n *\n * @param snapId - Snap ID.\n * @returns The Snap metadata or undefined if the Snap cannot be found.\n */\n #getSnapMetadata(\n snapId: SnapId,\n ): InternalAccount['metadata']['snap'] | undefined {\n const snap = this.#snapClient.getController().get(snapId);\n return snap\n ? { id: snapId, name: snap.manifest.proposedName, enabled: snap.enabled }\n : undefined;\n }\n\n /**\n * Get the allowed origins of a Snap.\n *\n * @param snap - Snap.\n * @returns The allowed origins of the Snap.\n */\n #getSnapAllowedOrigins(snap: Snap): string[] {\n return (\n snap.manifest.initialPermissions['endowment:keyring']?.allowedOrigins ??\n []\n );\n }\n\n /**\n * Return an internal account object for a given address.\n *\n * @param address - Address of the account to return.\n * @returns An internal account object for the given address.\n */\n getAccountByAddress(address: string): InternalAccount | undefined {\n const accounts = this.listAccounts();\n return accounts.find(({ address: accountAddress }) =>\n equalsIgnoreCase(accountAddress, address),\n );\n }\n\n /**\n * List all Snap keyring accounts.\n *\n * @returns An array containing all Snap keyring accounts.\n */\n listAccounts(): InternalAccount[] {\n return [...this.#accounts.values()].map(({ account, snapId }) => {\n const snap = this.#getSnapMetadata(snapId);\n return {\n ...account,\n // TODO: Do not convert the address to lowercase.\n //\n // This is a workaround to support the current UI which expects the\n // account address to be lowercase. This workaround should be removed\n // once we migrated the UI to use the account ID instead of the account\n // address.\n address: account.address.toLowerCase(),\n metadata: {\n name: '',\n importTime: 0,\n keyring: {\n type: this.type,\n },\n ...(snap !== undefined && { snap }),\n },\n };\n });\n }\n}\n"]}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./SnapKeyring"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,gDAA8B","sourcesContent":["export * from './types';\nexport * from './SnapKeyring';\n"]}
|
package/dist/logger.d.ts
ADDED
package/dist/logger.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* istanbul ignore file */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.createModuleLogger = exports.projectLogger = void 0;
|
|
5
|
+
const utils_1 = require("@metamask/utils");
|
|
6
|
+
Object.defineProperty(exports, "createModuleLogger", { enumerable: true, get: function () { return utils_1.createModuleLogger; } });
|
|
7
|
+
exports.projectLogger = (0, utils_1.createProjectLogger)('eth-snap-keyring');
|
|
8
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";AAAA,0BAA0B;;;AAE1B,2CAA0E;AAIjE,mGAJqB,0BAAkB,OAIrB;AAFd,QAAA,aAAa,GAAG,IAAA,2BAAmB,EAAC,kBAAkB,CAAC,CAAC","sourcesContent":["/* istanbul ignore file */\n\nimport { createProjectLogger, createModuleLogger } from '@metamask/utils';\n\nexport const projectLogger = createProjectLogger('eth-snap-keyring');\n\nexport { createModuleLogger };\n"]}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Infer } from '@metamask/superstruct';
|
|
2
|
+
export declare const SnapMessageStruct: import("@metamask/superstruct").Struct<{
|
|
3
|
+
method: string;
|
|
4
|
+
params?: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json> | undefined;
|
|
5
|
+
}, {
|
|
6
|
+
method: import("@metamask/superstruct").Struct<string, null>;
|
|
7
|
+
params: import("@metamask/superstruct").Struct<import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json> | undefined, null>;
|
|
8
|
+
}>;
|
|
9
|
+
/**
|
|
10
|
+
* Message sent by the snap to manage accounts and requests.
|
|
11
|
+
*/
|
|
12
|
+
export declare type SnapMessage = Infer<typeof SnapMessageStruct>;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SnapMessageStruct = void 0;
|
|
4
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
5
|
+
const utils_1 = require("@metamask/utils");
|
|
6
|
+
exports.SnapMessageStruct = (0, superstruct_1.object)({
|
|
7
|
+
method: (0, superstruct_1.string)(),
|
|
8
|
+
params: (0, superstruct_1.optional)((0, superstruct_1.union)([(0, superstruct_1.array)(utils_1.JsonStruct), (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct)])),
|
|
9
|
+
});
|
|
10
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AACA,uDAO+B;AAC/B,2CAA6C;AAEhC,QAAA,iBAAiB,GAAG,IAAA,oBAAM,EAAC;IACtC,MAAM,EAAE,IAAA,oBAAM,GAAE;IAChB,MAAM,EAAE,IAAA,sBAAQ,EAAC,IAAA,mBAAK,EAAC,CAAC,IAAA,mBAAK,EAAC,kBAAU,CAAC,EAAE,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC,CAAC,CAAC,CAAC;CAC3E,CAAC,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport {\n array,\n object,\n optional,\n record,\n string,\n union,\n} from '@metamask/superstruct';\nimport { JsonStruct } from '@metamask/utils';\n\nexport const SnapMessageStruct = object({\n method: string(),\n params: optional(union([array(JsonStruct), record(string(), JsonStruct)])),\n});\n\n/**\n * Message sent by the snap to manage accounts and requests.\n */\nexport type SnapMessage = Infer<typeof SnapMessageStruct>;\n"]}
|
package/dist/util.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Struct } from '@metamask/superstruct';
|
|
2
|
+
import type { Json } from '@metamask/utils';
|
|
3
|
+
/**
|
|
4
|
+
* Assert that a value is valid according to a struct.
|
|
5
|
+
*
|
|
6
|
+
* It is similar to superstruct's mask function, but it does not ignore extra
|
|
7
|
+
* properties.
|
|
8
|
+
*
|
|
9
|
+
* @param value - Value to check.
|
|
10
|
+
* @param struct - Struct to validate the value against.
|
|
11
|
+
* @param message - Error message to throw if the value is not valid.
|
|
12
|
+
* @returns The value if it is valid.
|
|
13
|
+
*/
|
|
14
|
+
export declare function strictMask<Type, Schema>(value: unknown, struct: Struct<Type, Schema>, message?: string): Type;
|
|
15
|
+
/**
|
|
16
|
+
* Remove duplicate entries from an array.
|
|
17
|
+
*
|
|
18
|
+
* @param array - Array to remove duplicates from.
|
|
19
|
+
* @returns Array with duplicates removed.
|
|
20
|
+
*/
|
|
21
|
+
export declare function unique<Type>(array: Type[] | Iterable<Type>): Type[];
|
|
22
|
+
/**
|
|
23
|
+
* Convert a value to a valid JSON object.
|
|
24
|
+
*
|
|
25
|
+
* The function chains JSON.stringify and JSON.parse to ensure that the result
|
|
26
|
+
* is a valid JSON object. In objects, undefined values are removed, and in
|
|
27
|
+
* arrays, they are replaced with null.
|
|
28
|
+
*
|
|
29
|
+
* @param value - Value to convert to JSON.
|
|
30
|
+
* @returns JSON representation of the value.
|
|
31
|
+
*/
|
|
32
|
+
export declare function toJson<Type extends Json = Json>(value: any): Type;
|
|
33
|
+
/**
|
|
34
|
+
* Asserts that the given value is defined.
|
|
35
|
+
*
|
|
36
|
+
* @param value - Value to check.
|
|
37
|
+
*/
|
|
38
|
+
export declare function ensureDefined<Type>(value: Type | undefined): asserts value is Type;
|
|
39
|
+
/**
|
|
40
|
+
* Helper function that throws an error.
|
|
41
|
+
*
|
|
42
|
+
* @param message - Error message to throw.
|
|
43
|
+
*/
|
|
44
|
+
export declare function throwError(message: string): never;
|
|
45
|
+
/**
|
|
46
|
+
* Compares two strings for equality, ignoring case.
|
|
47
|
+
*
|
|
48
|
+
* @param a - The first string to compare.
|
|
49
|
+
* @param b - The second string to compare.
|
|
50
|
+
* @returns `true` if the strings are equal, ignoring case. `false` otherwise.
|
|
51
|
+
*/
|
|
52
|
+
export declare function equalsIgnoreCase(a: string, b: string): boolean;
|
package/dist/util.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.equalsIgnoreCase = exports.throwError = exports.ensureDefined = exports.toJson = exports.unique = exports.strictMask = void 0;
|
|
4
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
5
|
+
/**
|
|
6
|
+
* Assert that a value is valid according to a struct.
|
|
7
|
+
*
|
|
8
|
+
* It is similar to superstruct's mask function, but it does not ignore extra
|
|
9
|
+
* properties.
|
|
10
|
+
*
|
|
11
|
+
* @param value - Value to check.
|
|
12
|
+
* @param struct - Struct to validate the value against.
|
|
13
|
+
* @param message - Error message to throw if the value is not valid.
|
|
14
|
+
* @returns The value if it is valid.
|
|
15
|
+
*/
|
|
16
|
+
function strictMask(value, struct, message) {
|
|
17
|
+
(0, superstruct_1.assert)(value, struct, message);
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
exports.strictMask = strictMask;
|
|
21
|
+
/**
|
|
22
|
+
* Remove duplicate entries from an array.
|
|
23
|
+
*
|
|
24
|
+
* @param array - Array to remove duplicates from.
|
|
25
|
+
* @returns Array with duplicates removed.
|
|
26
|
+
*/
|
|
27
|
+
function unique(array) {
|
|
28
|
+
return [...new Set(array)];
|
|
29
|
+
}
|
|
30
|
+
exports.unique = unique;
|
|
31
|
+
/**
|
|
32
|
+
* Convert a value to a valid JSON object.
|
|
33
|
+
*
|
|
34
|
+
* The function chains JSON.stringify and JSON.parse to ensure that the result
|
|
35
|
+
* is a valid JSON object. In objects, undefined values are removed, and in
|
|
36
|
+
* arrays, they are replaced with null.
|
|
37
|
+
*
|
|
38
|
+
* @param value - Value to convert to JSON.
|
|
39
|
+
* @returns JSON representation of the value.
|
|
40
|
+
*/
|
|
41
|
+
function toJson(value) {
|
|
42
|
+
return JSON.parse(JSON.stringify(value));
|
|
43
|
+
}
|
|
44
|
+
exports.toJson = toJson;
|
|
45
|
+
/**
|
|
46
|
+
* Asserts that the given value is defined.
|
|
47
|
+
*
|
|
48
|
+
* @param value - Value to check.
|
|
49
|
+
*/
|
|
50
|
+
function ensureDefined(value) {
|
|
51
|
+
if (value === undefined) {
|
|
52
|
+
throw new Error('Argument is undefined');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.ensureDefined = ensureDefined;
|
|
56
|
+
/**
|
|
57
|
+
* Helper function that throws an error.
|
|
58
|
+
*
|
|
59
|
+
* @param message - Error message to throw.
|
|
60
|
+
*/
|
|
61
|
+
function throwError(message) {
|
|
62
|
+
throw new Error(message);
|
|
63
|
+
}
|
|
64
|
+
exports.throwError = throwError;
|
|
65
|
+
/**
|
|
66
|
+
* Compares two strings for equality, ignoring case.
|
|
67
|
+
*
|
|
68
|
+
* @param a - The first string to compare.
|
|
69
|
+
* @param b - The second string to compare.
|
|
70
|
+
* @returns `true` if the strings are equal, ignoring case. `false` otherwise.
|
|
71
|
+
*/
|
|
72
|
+
function equalsIgnoreCase(a, b) {
|
|
73
|
+
return a.toLowerCase() === b.toLowerCase();
|
|
74
|
+
}
|
|
75
|
+
exports.equalsIgnoreCase = equalsIgnoreCase;
|
|
76
|
+
//# sourceMappingURL=util.js.map
|
package/dist/util.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;AACA,uDAA+C;AAG/C;;;;;;;;;;GAUG;AACH,SAAgB,UAAU,CACxB,KAAc,EACd,MAA4B,EAC5B,OAAgB;IAEhB,IAAA,oBAAM,EAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,KAAK,CAAC;AACf,CAAC;AAPD,gCAOC;AAED;;;;;GAKG;AACH,SAAgB,MAAM,CAAO,KAA8B;IACzD,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;AAC7B,CAAC;AAFD,wBAEC;AAED;;;;;;;;;GASG;AACH,SAAgB,MAAM,CAA2B,KAAU;IACzD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAS,CAAC;AACnD,CAAC;AAFD,wBAEC;AAED;;;;GAIG;AACH,SAAgB,aAAa,CAC3B,KAAuB;IAEvB,IAAI,KAAK,KAAK,SAAS,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;KAC1C;AACH,CAAC;AAND,sCAMC;AAED;;;;GAIG;AACH,SAAgB,UAAU,CAAC,OAAe;IACxC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AAC3B,CAAC;AAFD,gCAEC;AAED;;;;;;GAMG;AACH,SAAgB,gBAAgB,CAAC,CAAS,EAAE,CAAS;IACnD,OAAO,CAAC,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;AAC7C,CAAC;AAFD,4CAEC","sourcesContent":["import type { Struct } from '@metamask/superstruct';\nimport { assert } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\n\n/**\n * Assert that a value is valid according to a struct.\n *\n * It is similar to superstruct's mask function, but it does not ignore extra\n * properties.\n *\n * @param value - Value to check.\n * @param struct - Struct to validate the value against.\n * @param message - Error message to throw if the value is not valid.\n * @returns The value if it is valid.\n */\nexport function strictMask<Type, Schema>(\n value: unknown,\n struct: Struct<Type, Schema>,\n message?: string,\n): Type {\n assert(value, struct, message);\n return value;\n}\n\n/**\n * Remove duplicate entries from an array.\n *\n * @param array - Array to remove duplicates from.\n * @returns Array with duplicates removed.\n */\nexport function unique<Type>(array: Type[] | Iterable<Type>): Type[] {\n return [...new Set(array)];\n}\n\n/**\n * Convert a value to a valid JSON object.\n *\n * The function chains JSON.stringify and JSON.parse to ensure that the result\n * is a valid JSON object. In objects, undefined values are removed, and in\n * arrays, they are replaced with null.\n *\n * @param value - Value to convert to JSON.\n * @returns JSON representation of the value.\n */\nexport function toJson<Type extends Json = Json>(value: any): Type {\n return JSON.parse(JSON.stringify(value)) as Type;\n}\n\n/**\n * Asserts that the given value is defined.\n *\n * @param value - Value to check.\n */\nexport function ensureDefined<Type>(\n value: Type | undefined,\n): asserts value is Type {\n if (value === undefined) {\n throw new Error('Argument is undefined');\n }\n}\n\n/**\n * Helper function that throws an error.\n *\n * @param message - Error message to throw.\n */\nexport function throwError(message: string): never {\n throw new Error(message);\n}\n\n/**\n * Compares two strings for equality, ignoring case.\n *\n * @param a - The first string to compare.\n * @param b - The second string to compare.\n * @returns `true` if the strings are equal, ignoring case. `false` otherwise.\n */\nexport function equalsIgnoreCase(a: string, b: string): boolean {\n return a.toLowerCase() === b.toLowerCase();\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@metamask-previews/eth-snap-keyring",
|
|
3
|
+
"version": "4.3.2-672cc7b",
|
|
4
|
+
"description": "Snaps keyring bridge.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/MetaMask/eth-snap-keyring.git"
|
|
8
|
+
},
|
|
9
|
+
"main": "dist/index.js",
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist/"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "yarn workspace $(jq -r '.name' ../keyring-api/package.json) build:force && tsc --build tsconfig.build.json",
|
|
16
|
+
"build:clean": "rimraf dist && yarn build",
|
|
17
|
+
"build:docs": "typedoc",
|
|
18
|
+
"build:force": "tsc --build tsconfig.build.json --force",
|
|
19
|
+
"changelog:update": "../../scripts/update-changelog.sh @metamask/eth-snap-keyring",
|
|
20
|
+
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/eth-snap-keyring",
|
|
21
|
+
"publish:preview": "yarn npm publish --tag preview",
|
|
22
|
+
"test": "jest && jest-it-up",
|
|
23
|
+
"test:clean": "jest --clearCache",
|
|
24
|
+
"test:verbose": "jest --verbose",
|
|
25
|
+
"test:watch": "jest --watch"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@ethereumjs/tx": "^4.2.0",
|
|
29
|
+
"@metamask/eth-sig-util": "^7.0.3",
|
|
30
|
+
"@metamask/keyring-api": "^8.1.0",
|
|
31
|
+
"@metamask/keyring-internal-api": "0.0.1",
|
|
32
|
+
"@metamask/keyring-snap-client": "0.0.1",
|
|
33
|
+
"@metamask/keyring-snap-sdk": "0.0.1",
|
|
34
|
+
"@metamask/snaps-controllers": "^9.3.0",
|
|
35
|
+
"@metamask/snaps-sdk": "^6.1.0",
|
|
36
|
+
"@metamask/snaps-utils": "^7.8.0",
|
|
37
|
+
"@metamask/superstruct": "^3.1.0",
|
|
38
|
+
"@metamask/utils": "^9.1.0",
|
|
39
|
+
"@types/uuid": "^9.0.1",
|
|
40
|
+
"deepmerge": "^4.2.2",
|
|
41
|
+
"uuid": "^9.0.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@lavamoat/allow-scripts": "^3.0.4",
|
|
45
|
+
"@metamask/auto-changelog": "^3.4.4",
|
|
46
|
+
"@types/jest": "^28.1.6",
|
|
47
|
+
"@types/node": "^17.0.23",
|
|
48
|
+
"depcheck": "^1.4.3",
|
|
49
|
+
"jest": "^28.1.3",
|
|
50
|
+
"jest-it-up": "^2.0.2",
|
|
51
|
+
"rimraf": "^3.0.2",
|
|
52
|
+
"ts-jest": "^28.0.7",
|
|
53
|
+
"ts-node": "^10.7.0",
|
|
54
|
+
"typedoc": "^0.23.15",
|
|
55
|
+
"typescript": "~4.8.4"
|
|
56
|
+
},
|
|
57
|
+
"engines": {
|
|
58
|
+
"node": "^18.18 || >=20"
|
|
59
|
+
},
|
|
60
|
+
"publishConfig": {
|
|
61
|
+
"access": "public",
|
|
62
|
+
"registry": "https://registry.npmjs.org/"
|
|
63
|
+
},
|
|
64
|
+
"lavamoat": {
|
|
65
|
+
"allowScripts": {
|
|
66
|
+
"@metamask/snaps-utils>@metamask/permission-controller>@metamask/controller-utils>ethereumjs-util>ethereum-cryptography>keccak": false,
|
|
67
|
+
"@metamask/snaps-utils>@metamask/permission-controller>@metamask/controller-utils>ethereumjs-util>ethereum-cryptography>secp256k1": false,
|
|
68
|
+
"@metamask/snaps-controllers>@metamask/phishing-controller>@metamask/controller-utils>ethereumjs-util>ethereum-cryptography>keccak": false,
|
|
69
|
+
"@metamask/snaps-controllers>@metamask/phishing-controller>@metamask/controller-utils>ethereumjs-util>ethereum-cryptography>secp256k1": false
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|