mirror of
https://github.com/nostr-connect/connect.git
synced 2025-12-17 05:04:20 +01:00
add NIP-26 delegation (#7)
* add delegate method * enable ci on PR * enable test on ci * lint * lint * off flaky tests
This commit is contained in:
@@ -3,20 +3,20 @@ import { useEffect, useState } from 'react';
|
||||
import { useStatePersist } from 'use-state-persist';
|
||||
|
||||
import * as ReactDOM from 'react-dom';
|
||||
import { broadcastToRelay, Connect, connectToRelay, ConnectURI } from '@nostr-connect/connect';
|
||||
import { broadcastToRelay, Connect, connectToRelay, ConnectURI, TimeRanges } from '../src/index';
|
||||
|
||||
import { QRCodeSVG } from 'qrcode.react';
|
||||
import { getEventHash, getPublicKey, Event } from 'nostr-tools';
|
||||
import { getEventHash, getPublicKey, Event, nip19 } from 'nostr-tools';
|
||||
|
||||
const secretKey = "5acff99d1ad3e1706360d213fd69203312d9b5e91a2d5f2e06100cc6f686e5b3";
|
||||
const connectURI = new ConnectURI({
|
||||
target: getPublicKey(secretKey),
|
||||
relay: 'wss://nostr.vulpem.com',
|
||||
metadata: {
|
||||
name: 'Example',
|
||||
description: '🔉🔉🔉',
|
||||
url: 'https://example.com',
|
||||
icons: ['https://example.com/icon.png'],
|
||||
name: 'Vulpem',
|
||||
description: 'Bitcoin company',
|
||||
url: 'https://vulpem.com',
|
||||
icons: ['https://vulpem.com/favicon.ico'],
|
||||
},
|
||||
});
|
||||
|
||||
@@ -54,7 +54,7 @@ const App = () => {
|
||||
target: pubkey,
|
||||
});
|
||||
const pk = await connect.getPublicKey();
|
||||
setGetPublicKeyReply(pk);
|
||||
setGetPublicKeyReply(nip19.npubEncode(pk));
|
||||
}
|
||||
|
||||
const sendMessage = async () => {
|
||||
@@ -116,19 +116,13 @@ const App = () => {
|
||||
target: pubkey,
|
||||
});
|
||||
|
||||
const sig = await connect.rpc.call({
|
||||
target: pubkey,
|
||||
request: {
|
||||
method: 'delegate',
|
||||
params: [
|
||||
getPublicKey(secretKey),
|
||||
{
|
||||
kind: 0,
|
||||
until: Math.floor(Date.now() / 1000) + 60 * 60 * 24 * 365,
|
||||
}
|
||||
],
|
||||
const sig = await connect.delegate(
|
||||
getPublicKey(secretKey),
|
||||
{
|
||||
kind: 1,
|
||||
until: TimeRanges.ONE_DAY,
|
||||
}
|
||||
});
|
||||
);
|
||||
setDelegateSig(sig);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@@ -158,6 +152,7 @@ const App = () => {
|
||||
});
|
||||
}
|
||||
|
||||
const appEpehemeralPubKey = nip19.npubEncode(getPublicKey(secretKey));
|
||||
return (
|
||||
<div className='hero is-fullheight has-background-black has-text-white'>
|
||||
<section className="container">
|
||||
@@ -165,7 +160,7 @@ const App = () => {
|
||||
<h1 className='title has-text-white'>Nostr Connect Playground</h1>
|
||||
</div>
|
||||
<div className='content'>
|
||||
<p className='subtitle is-6 has-text-white'><b>Nostr ID</b> {getPublicKey(secretKey)}</p>
|
||||
<p className='subtitle is-6 has-text-white'><b>Nostr ID (ephemeral)</b> {appEpehemeralPubKey}</p>
|
||||
</div>
|
||||
<div className='content'>
|
||||
<p className='subtitle is-6 has-text-white'><b>Status</b> {isConnected() ? '🟢 Connected' : '🔴 Disconnected'}</p>
|
||||
|
||||
Reference in New Issue
Block a user