Skip to content

Commit

Permalink
feat(connect): add nostrGetPublicKey method
Browse files Browse the repository at this point in the history
  • Loading branch information
mroz22 committed Dec 11, 2024
1 parent 447efb3 commit ffc5c4b
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/connect/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
39 changes: 39 additions & 0 deletions packages/connect/src/api/nostrGetPublicKey.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
1 change: 1 addition & 0 deletions packages/connect/src/core/method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const getMethod = async (message: IFrameCallMessage): Promise<AbstractMet
if (typeof method !== 'string') {
throw TypedError('Method_InvalidParameter', 'Message method is not set');
}
console.log('methods getMethod', Methods);

Check warning on line 15 in packages/connect/src/core/method.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement

const methodModule = getMethodModule(method);
const methods = methodModule
Expand Down
2 changes: 2 additions & 0 deletions packages/connect/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ export const factory = <

getPublicKey: params => call({ ...params, method: 'getPublicKey' }),

nostrGetPublicKey: params => call({ ...params, method: 'nostrGetPublicKey' }),

nemGetAddress: params =>
call({
...params,
Expand Down
4 changes: 4 additions & 0 deletions packages/connect/src/types/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;

Expand Down
10 changes: 10 additions & 0 deletions packages/connect/src/types/api/nostrGetPublicKey.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Static } from '@trezor/schema-utils';

Check warning on line 1 in packages/connect/src/types/api/nostrGetPublicKey.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

There should be at least one empty line between import groups
import { PROTO } from '../../constants';
import { Params, Response, GetPublicKey } from '../params';

export type NostrGetPublicKey = Static<typeof GetPublicKey>;
export const NostrGetPublicKey = GetPublicKey;

export declare function nostrGetPublicKey(
params: Params<GetPublicKey>,
): Response<PROTO.NostrPubkey>;

0 comments on commit ffc5c4b

Please sign in to comment.