mirror of
https://github.com/nostr-connect/connect.git
synced 2025-12-17 13:14:20 +01:00
fix ConnectURI.from() (#1)
* v0.1.1 * fix connect uri * lint * remove size gh action * gh action: only ubuntu
This commit is contained in:
2
.github/workflows/main.yml
vendored
2
.github/workflows/main.yml
vendored
@@ -8,7 +8,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node: ['14.x', '16.x', '18.x']
|
node: ['14.x', '16.x', '18.x']
|
||||||
os: [ubuntu-latest, windows-latest, macOS-latest]
|
os: [ubuntu-latest]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repo
|
- name: Checkout repo
|
||||||
|
|||||||
12
.github/workflows/size.yml
vendored
12
.github/workflows/size.yml
vendored
@@ -1,12 +0,0 @@
|
|||||||
name: size
|
|
||||||
on: [pull_request]
|
|
||||||
jobs:
|
|
||||||
size:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
env:
|
|
||||||
CI_JOB_NUMBER: 1
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v1
|
|
||||||
- uses: andresz1/size-limit-action@v1
|
|
||||||
with:
|
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
"build": "parcel build --public-url /connect index.html"
|
"build": "parcel build --public-url /connect index.html"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nostr-connect/connect": "^0.1.0",
|
"@nostr-connect/connect": "^0.1.1",
|
||||||
"nostr-tools": "^1.1.1",
|
"nostr-tools": "^1.1.1",
|
||||||
"qrcode.react": "^3.1.0",
|
"qrcode.react": "^3.1.0",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
|
|||||||
@@ -159,10 +159,10 @@
|
|||||||
resolved "https://registry.yarnpkg.com/@noble/secp256k1/-/secp256k1-1.7.0.tgz#d15357f7c227e751d90aa06b05a0e5cf993ba8c1"
|
resolved "https://registry.yarnpkg.com/@noble/secp256k1/-/secp256k1-1.7.0.tgz#d15357f7c227e751d90aa06b05a0e5cf993ba8c1"
|
||||||
integrity sha512-kbacwGSsH/CTout0ZnZWxnW1B+jH/7r/WAAKLBtrRJ/+CUH7lgmQzl3GTrQua3SGKWNSDsS6lmjnDpIJ5Dxyaw==
|
integrity sha512-kbacwGSsH/CTout0ZnZWxnW1B+jH/7r/WAAKLBtrRJ/+CUH7lgmQzl3GTrQua3SGKWNSDsS6lmjnDpIJ5Dxyaw==
|
||||||
|
|
||||||
"@nostr-connect/connect@^0.1.0":
|
"@nostr-connect/connect@^0.1.1":
|
||||||
version "0.1.0"
|
version "0.1.1"
|
||||||
resolved "https://registry.yarnpkg.com/@nostr-connect/connect/-/connect-0.1.0.tgz#0f5537237d63e328922b9b13b97d98da53cc3bd4"
|
resolved "https://registry.yarnpkg.com/@nostr-connect/connect/-/connect-0.1.1.tgz#e289d6abd617fc537435321612df68a448df459d"
|
||||||
integrity sha512-YcQvkvMEdWBFy1tnPJhuS+wNK+W1EOz0vdOeIth6KezdSKS+yTHoR/jV58nQdRLvmiAIAIr+ZY/gYTztFddiUA==
|
integrity sha512-1lhogg58haTObD2KnnZZW4wEjYRrEIOOc8ll0N7s20WDVs4uoL+5bAetVXSzf1XzgyakDWJGTYawqbtbgCo45w==
|
||||||
dependencies:
|
dependencies:
|
||||||
events "^3.3.0"
|
events "^3.3.0"
|
||||||
nostr-tools "^1.0.1"
|
nostr-tools "^1.0.1"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"version": "0.1.0",
|
"version": "0.1.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
|
|||||||
@@ -17,10 +17,9 @@ export class ConnectURI {
|
|||||||
|
|
||||||
static fromURI(uri: string): ConnectURI {
|
static fromURI(uri: string): ConnectURI {
|
||||||
const url = new URL(uri);
|
const url = new URL(uri);
|
||||||
const target = url.searchParams.get('target');
|
const target = url.pathname.substring(2);
|
||||||
if (!target) {
|
if (!url.pathname.startsWith('//'))
|
||||||
throw new Error('Invalid connect URI: missing target');
|
throw new Error('Invalid connect URI: missing target');
|
||||||
}
|
|
||||||
const relay = url.searchParams.get('relay');
|
const relay = url.searchParams.get('relay');
|
||||||
if (!relay) {
|
if (!relay) {
|
||||||
throw new Error('Invalid connect URI: missing relay');
|
throw new Error('Invalid connect URI: missing relay');
|
||||||
@@ -33,7 +32,7 @@ export class ConnectURI {
|
|||||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||||
try {
|
try {
|
||||||
const md = JSON.parse(metadata);
|
const md = JSON.parse(metadata);
|
||||||
return new ConnectURI({ target, metadata: md, relay: relay });
|
return new ConnectURI({ target, metadata: md, relay });
|
||||||
} catch (ignore) {
|
} catch (ignore) {
|
||||||
throw new Error('Invalid connect URI: metadata is not valid JSON');
|
throw new Error('Invalid connect URI: metadata is not valid JSON');
|
||||||
}
|
}
|
||||||
@@ -54,7 +53,7 @@ export class ConnectURI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toString() {
|
toString() {
|
||||||
return `nostr://connect?${this.target}?metadata=${JSON.stringify(
|
return `nostrconnect://${this.target}?metadata=${JSON.stringify(
|
||||||
this.metadata
|
this.metadata
|
||||||
)}&relay=${this.relay}`;
|
)}&relay=${this.relay}`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,12 @@ class MobileHandler extends NostrSigner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe('Nostr Connect', () => {
|
describe('Nostr Connect', () => {
|
||||||
|
it.only('generates a connectURI', async () => {
|
||||||
|
const url = ConnectURI.fromURI(
|
||||||
|
`nostrconnect://b889ff5b1513b641e2a139f661a661364979c5beee91842f8f0ef42ab558e9d4?metadata={"name":"Example","description":"🔉🔉🔉","url":"https://example.com","icons":["https://example.com/icon.png"]}&relay=wss://nostr.vulpem.com`
|
||||||
|
);
|
||||||
|
console.log(url.target);
|
||||||
|
});
|
||||||
it('connect', async () => {
|
it('connect', async () => {
|
||||||
const testHandler = jest.fn();
|
const testHandler = jest.fn();
|
||||||
|
|
||||||
@@ -68,7 +74,7 @@ describe('Nostr Connect', () => {
|
|||||||
expect(testHandler).toBeCalledTimes(1);
|
expect(testHandler).toBeCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it.only('returns pubkey', async () => {
|
it('returns pubkey', async () => {
|
||||||
// start listening for connect messages on the mobile app
|
// start listening for connect messages on the mobile app
|
||||||
const remoteHandler = new MobileHandler({
|
const remoteHandler = new MobileHandler({
|
||||||
secretKey: mobileSK,
|
secretKey: mobileSK,
|
||||||
|
|||||||
Reference in New Issue
Block a user