Skip to content

Commit

Permalink
Add support for nostr.getrelays
Browse files Browse the repository at this point in the history
  • Loading branch information
sondreb committed Dec 16, 2022
1 parent 8fc70e2 commit 9adb44c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
3 changes: 3 additions & 0 deletions angular/src/shared/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { AccountBalanceHandler } from './account-balance-handler';
import { WalletsHandler } from './wallets-handler';
import { NostrPublicKeyHandler } from './nostr-public-key-handler';
import { NostrSignEventHandler } from './nostr-sign-event-handler';
import { NostrGetRelaysHandler } from './nostr-get-relays-handler';

// TODO: Make this more generic where the handlers are registered as form of factory.
export class Handlers {
Expand Down Expand Up @@ -40,6 +41,8 @@ export class Handlers {
return new NostrPublicKeyHandler(backgroundManager);
case 'nostr.signevent':
return new NostrSignEventHandler(backgroundManager);
case 'nostr.getrelays':
return new NostrGetRelaysHandler(backgroundManager);
// case 'signVerifiableCredential': // Signing of Verifiable Credential, JSON encoded as signed JSON Web Token.
// return new SignVerifiableCredentialHandler();
// case 'signTypedData': // Not implemented yet, will be inspired by EIP-712: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md
Expand Down
41 changes: 41 additions & 0 deletions angular/src/shared/handlers/nostr-get-relays-handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { BackgroundManager } from '../background-manager';
import { ActionPrepareResult, ActionResponse, Permission } from '../interfaces';
import { ActionHandler, ActionState } from './action-handler';

export class NostrGetRelaysHandler implements ActionHandler {
action = ['nostr.getrelays'];

constructor(private backgroundManager: BackgroundManager) {}

async prepare(state: ActionState): Promise<ActionPrepareResult> {
return {
content: [
'wss://nostr-pub.wellorder.net',
'wss://nostr-relay.untethr.me',
'wss://nostr.semisol.dev',
'wss://nostr-pub.semisol.dev',
'wss://nostr-verified.wellorder.net',
'wss://nostr.drss.io',
'wss://relay.damus.io',
'wss://nostr.openchain.fr',
'wss://nostr.delo.software',
'wss://relay.nostr.info',
'wss://relay.minds.com/nostr/v1/ws',
'wss://nostr.zaprite.io',
'wss://nostr.oxtr.dev',
'wss://nostr.ono.re',
'wss://relay.grunch.dev',
'wss://nostr.sandwich.farm',
'wss://relay.nostr.ch',
],
consent: false,
};
}

async execute(state: ActionState, permission: Permission): Promise<ActionResponse> {
return {
request: state.message.request,
response: state.content,
};
}
}
6 changes: 6 additions & 0 deletions angular/src/shared/handlers/nostr-public-key-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import { ActionPrepareResult, ActionResponse, Permission } from '../interfaces';
import { ActionHandler, ActionState } from './action-handler';
import { SigningUtilities } from '../identity/signing-utilities';

// Some Nostr resources and tools:

// https://metadata.nostr.com/
// https://alphaama.com/
// https://nostr-army-knife.netlify.app/

export class NostrPublicKeyHandler implements ActionHandler {
action = ['nostr.publickey'];
utility = new SigningUtilities();
Expand Down
9 changes: 9 additions & 0 deletions extension/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ class BlockcoreRequestProvider implements Web5RequestProvider {
return call.response;
}

async getRelays(): Promise<string[]> {
const call = (await this.#call('request', {
method: 'nostr.getrelays',
params: [{}],
})) as any;

return call.response || {};
}

// TODO: Add support for NIP-04 (encrypt/decrypt), example: https://github.com/getAlby/lightning-browser-extension/blob/master/src/extension/ln/nostr/index.ts
}

Expand Down

0 comments on commit 9adb44c

Please sign in to comment.