From ffc5c4bdc828fd7149201a5791693fbdb30fcf64 Mon Sep 17 00:00:00 2001 From: Martin Varmuza Date: Wed, 11 Dec 2024 16:24:45 +0100 Subject: [PATCH] feat(connect): add nostrGetPublicKey method --- packages/connect/src/api/index.ts | 1 + packages/connect/src/api/nostrGetPublicKey.ts | 39 +++++++++++++++++++ packages/connect/src/core/method.ts | 1 + packages/connect/src/factory.ts | 2 + packages/connect/src/types/api/index.ts | 4 ++ .../src/types/api/nostrGetPublicKey.ts | 10 +++++ 6 files changed, 57 insertions(+) create mode 100644 packages/connect/src/api/nostrGetPublicKey.ts create mode 100644 packages/connect/src/types/api/nostrGetPublicKey.ts diff --git a/packages/connect/src/api/index.ts b/packages/connect/src/api/index.ts index eeb7d84f5bc..63231d5fbb8 100644 --- a/packages/connect/src/api/index.ts +++ b/packages/connect/src/api/index.ts @@ -36,6 +36,7 @@ export { default as getFirmwareHash } from './getFirmwareHash'; export { default as getOwnershipId } from './getOwnershipId'; export { default as getOwnershipProof } from './getOwnershipProof'; export { default as getPublicKey } from './getPublicKey'; +export { default as nostrGetPublicKey } from './nostrGetPublicKey'; export { default as getSettings } from './getSettings'; // export { default as init } from './init'; // export { default as manifest } from './manifest'; diff --git a/packages/connect/src/api/nostrGetPublicKey.ts b/packages/connect/src/api/nostrGetPublicKey.ts new file mode 100644 index 00000000000..d69a02fc6e9 --- /dev/null +++ b/packages/connect/src/api/nostrGetPublicKey.ts @@ -0,0 +1,39 @@ +import { Assert } from '@trezor/schema-utils'; + +import { AbstractMethod } from '../core/AbstractMethod'; +import { validatePath } from '../utils/pathUtils'; +import { NostrGetPublicKey as NostrGetPubkeySchema } from '../types/api/nostrGetPublicKey'; + +export default class NostrGetPublicKey extends AbstractMethod<'nostrGetPublicKey', Params> { + init() { + this.requiredPermissions = ['read']; + + // create a bundle with only one batch if bundle doesn't exists + + // validate bundle type + Assert(NostrGetPubkeySchema, this.payload); + + const address_n = validatePath(this.payload.path); + + this.params = { + address_n, + }; + } + + get info() { + return 'Export nostr public key'; + } + + get confirmation() { + return { + view: 'export-xpub' as const, + label: 'hello', + }; + } + + async run() { + const cmd = this.device.getCommands(); + const response = await cmd.typedCall('NostrGetPubkey', 'NostrPubkey', this.params); + return response.message; + } +} diff --git a/packages/connect/src/core/method.ts b/packages/connect/src/core/method.ts index 936715cc3a0..5cd29e1402a 100644 --- a/packages/connect/src/core/method.ts +++ b/packages/connect/src/core/method.ts @@ -12,6 +12,7 @@ export const getMethod = async (message: IFrameCallMessage): Promise call({ ...params, method: 'getPublicKey' }), + nostrGetPublicKey: params => call({ ...params, method: 'nostrGetPublicKey' }), + nemGetAddress: params => call({ ...params, diff --git a/packages/connect/src/types/api/index.ts b/packages/connect/src/types/api/index.ts index 12900e124d6..f2ed7801f26 100644 --- a/packages/connect/src/types/api/index.ts +++ b/packages/connect/src/types/api/index.ts @@ -51,6 +51,7 @@ import { getFirmwareHash } from './getFirmwareHash'; import { getOwnershipId } from './getOwnershipId'; import { getOwnershipProof } from './getOwnershipProof'; import { getPublicKey } from './getPublicKey'; +import { nostrGetPublicKey } from './nostrGetPublicKey'; import { getSettings } from './getSettings'; import { init } from './init'; import { manifest } from './manifest'; @@ -248,6 +249,9 @@ export interface TrezorConnect { // https://connect.trezor.io/9/methods/bitcoin/getPublicKey/ getPublicKey: typeof getPublicKey; + // todo: + nostrGetPublicKey: typeof nostrGetPublicKey; + // todo: link docs getSettings: typeof getSettings; diff --git a/packages/connect/src/types/api/nostrGetPublicKey.ts b/packages/connect/src/types/api/nostrGetPublicKey.ts new file mode 100644 index 00000000000..5a888476557 --- /dev/null +++ b/packages/connect/src/types/api/nostrGetPublicKey.ts @@ -0,0 +1,10 @@ +import { Static } from '@trezor/schema-utils'; +import { PROTO } from '../../constants'; +import { Params, Response, GetPublicKey } from '../params'; + +export type NostrGetPublicKey = Static; +export const NostrGetPublicKey = GetPublicKey; + +export declare function nostrGetPublicKey( + params: Params, +): Response;