@welshman/signer 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/index.cjs +22 -0
- package/build/src/index.cjs.map +1 -0
- package/build/src/index.d.ts +4 -4
- package/build/src/index.mjs +4 -4
- package/build/src/nip59.cjs +76 -0
- package/build/src/nip59.cjs.map +1 -0
- package/build/src/nip59.d.ts +19 -0
- package/build/src/nip59.mjs +66 -0
- package/build/src/nip59.mjs.map +1 -0
- package/build/src/signers/nip01.cjs +24 -0
- package/build/src/signers/nip01.cjs.map +1 -0
- package/build/src/signers/{secret.d.ts → nip01.d.ts} +3 -2
- package/build/src/signers/{secret.mjs → nip01.mjs} +5 -4
- package/build/src/signers/nip01.mjs.map +1 -0
- package/build/src/signers/nip07.cjs +50 -0
- package/build/src/signers/nip07.cjs.map +1 -0
- package/build/src/signers/{extension.d.ts → nip07.d.ts} +5 -5
- package/build/src/signers/nip07.mjs +45 -0
- package/build/src/signers/nip07.mjs.map +1 -0
- package/build/src/signers/nip46.cjs +156 -0
- package/build/src/signers/nip46.cjs.map +1 -0
- package/build/src/signers/{connect.d.ts → nip46.d.ts} +9 -10
- package/build/src/signers/{connect.mjs → nip46.mjs} +23 -24
- package/build/src/signers/nip46.mjs.map +1 -0
- package/build/src/util.cjs +40 -0
- package/build/src/util.cjs.map +1 -0
- package/build/src/util.d.ts +2 -3
- package/build/src/util.mjs +1 -1
- package/build/src/util.mjs.map +1 -1
- package/package.json +1 -1
- package/build/src/signers/connect.mjs.map +0 -1
- package/build/src/signers/extension.mjs +0 -48
- package/build/src/signers/extension.mjs.map +0 -1
- package/build/src/signers/secret.mjs.map +0 -1
- package/build/src/wrapper.d.ts +0 -21
- package/build/src/wrapper.mjs +0 -56
- package/build/src/wrapper.mjs.map +0 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./util.cjs"), exports);
|
|
18
|
+
__exportStar(require("./nip59.cjs"), exports);
|
|
19
|
+
__exportStar(require("./signers/nip01.cjs"), exports);
|
|
20
|
+
__exportStar(require("./signers/nip07.cjs"), exports);
|
|
21
|
+
__exportStar(require("./signers/nip46.cjs"), exports);
|
|
22
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAAsB;AACtB,8CAAuB;AACvB,sDAA+B;AAC/B,sDAA+B;AAC/B,sDAA+B"}
|
package/build/src/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './util';
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './signers/
|
|
4
|
-
export * from './signers/
|
|
5
|
-
export * from './signers/
|
|
2
|
+
export * from './nip59';
|
|
3
|
+
export * from './signers/nip01';
|
|
4
|
+
export * from './signers/nip07';
|
|
5
|
+
export * from './signers/nip46';
|
package/build/src/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from "./util.mjs";
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./signers/
|
|
4
|
-
export * from "./signers/
|
|
5
|
-
export * from "./signers/
|
|
2
|
+
export * from "./nip59.mjs";
|
|
3
|
+
export * from "./signers/nip01.mjs";
|
|
4
|
+
export * from "./signers/nip07.mjs";
|
|
5
|
+
export * from "./signers/nip46.mjs";
|
|
6
6
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Nip59 = exports.unwrap = exports.wrap = exports.getWrap = exports.getSeal = exports.getRumor = exports.now = exports.seen = void 0;
|
|
4
|
+
const util_1 = require("@welshman/util");
|
|
5
|
+
const util_2 = require("./util.cjs");
|
|
6
|
+
const nip01_1 = require("./signers/nip01.cjs");
|
|
7
|
+
exports.seen = new Map();
|
|
8
|
+
const now = (drift = 0) => Math.round(Date.now() / 1000 - Math.random() * Math.pow(10, drift));
|
|
9
|
+
exports.now = now;
|
|
10
|
+
const getRumor = async (signer, template) => (0, util_2.hash)((0, util_2.own)(await signer.getPubkey(), template));
|
|
11
|
+
exports.getRumor = getRumor;
|
|
12
|
+
const getSeal = async (signer, pubkey, rumor) => signer.sign((0, util_2.hash)({
|
|
13
|
+
kind: util_1.SEAL,
|
|
14
|
+
pubkey: await signer.getPubkey(),
|
|
15
|
+
content: await signer.nip44.encrypt(pubkey, JSON.stringify(rumor)),
|
|
16
|
+
created_at: (0, exports.now)(5),
|
|
17
|
+
tags: [],
|
|
18
|
+
}));
|
|
19
|
+
exports.getSeal = getSeal;
|
|
20
|
+
const getWrap = async (wrapper, pubkey, seal, tags) => wrapper.sign((0, util_2.hash)({
|
|
21
|
+
kind: util_1.WRAP,
|
|
22
|
+
pubkey: await wrapper.getPubkey(),
|
|
23
|
+
content: await wrapper.nip44.encrypt(pubkey, JSON.stringify(seal)),
|
|
24
|
+
created_at: (0, exports.now)(5),
|
|
25
|
+
tags: [...tags, ["p", pubkey]],
|
|
26
|
+
}));
|
|
27
|
+
exports.getWrap = getWrap;
|
|
28
|
+
const wrap = async (signer, wrapper, pubkey, template, tags = []) => {
|
|
29
|
+
const rumor = await (0, exports.getRumor)(signer, template);
|
|
30
|
+
const seal = await (0, exports.getSeal)(signer, pubkey, rumor);
|
|
31
|
+
const wrap = await (0, exports.getWrap)(wrapper, pubkey, seal, tags);
|
|
32
|
+
return Object.assign(rumor, { wrap });
|
|
33
|
+
};
|
|
34
|
+
exports.wrap = wrap;
|
|
35
|
+
const unwrap = async (signer, wrap) => {
|
|
36
|
+
// Avoid decrypting the same event multiple times
|
|
37
|
+
if (exports.seen.has(wrap.id)) {
|
|
38
|
+
const rumorOrError = exports.seen.get(wrap.id);
|
|
39
|
+
if (rumorOrError instanceof Error) {
|
|
40
|
+
throw rumorOrError;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return rumorOrError;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
const seal = JSON.parse(await (0, util_2.decrypt)(signer, wrap.pubkey, wrap.content));
|
|
48
|
+
const rumor = JSON.parse(await (0, util_2.decrypt)(signer, seal.pubkey, seal.content));
|
|
49
|
+
if (seal.pubkey !== rumor.pubkey)
|
|
50
|
+
throw new Error("Seal pubkey does not match rumor pubkey");
|
|
51
|
+
exports.seen.set(wrap.id, rumor);
|
|
52
|
+
return Object.assign(rumor, { wrap });
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
exports.seen.set(wrap.id, error);
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
exports.unwrap = unwrap;
|
|
60
|
+
// This is a utility that makes it harder to re-use wrapper signers, since that can result in
|
|
61
|
+
// leaked metadata. It simultaneously makes it easier to wrap stuff, because it allows for
|
|
62
|
+
// wrapping a single user signer and omit the wrapper signer argument to wrap, while still
|
|
63
|
+
// making it possible to pass a wrapper signer if desired.
|
|
64
|
+
class Nip59 {
|
|
65
|
+
constructor(signer, wrapper) {
|
|
66
|
+
this.signer = signer;
|
|
67
|
+
this.wrapper = wrapper;
|
|
68
|
+
this.withWrapper = (wrapper) => new Nip59(this.signer, wrapper);
|
|
69
|
+
this.wrap = (pubkey, template, tags = []) => (0, exports.wrap)(this.signer, this.wrapper || nip01_1.Nip01Signer.ephemeral(), pubkey, template, tags);
|
|
70
|
+
this.unwrap = (event) => (0, exports.unwrap)(this.signer, event);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.Nip59 = Nip59;
|
|
74
|
+
Nip59.fromSigner = (signer) => new Nip59(signer);
|
|
75
|
+
Nip59.fromSecret = (secret) => new Nip59(new nip01_1.Nip01Signer(secret));
|
|
76
|
+
//# sourceMappingURL=nip59.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nip59.cjs","sourceRoot":"","sources":["../../src/nip59.ts"],"names":[],"mappings":";;;AAAA,yCAAkG;AAClG,qCAAkD;AAClD,+CAA2C;AAE9B,QAAA,IAAI,GAAG,IAAI,GAAG,EAAkC,CAAA;AAEtD,MAAM,GAAG,GAAG,CAAC,KAAK,GAAG,CAAC,EAAE,EAAE,CAC/B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAA;AADxD,QAAA,GAAG,OACqD;AAE9D,MAAM,QAAQ,GAAG,KAAK,EAAE,MAAe,EAAE,QAAuB,EAAE,EAAE,CACzE,IAAA,WAAI,EAAC,IAAA,UAAG,EAAC,MAAM,MAAM,CAAC,SAAS,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAA;AADlC,QAAA,QAAQ,YAC0B;AAExC,MAAM,OAAO,GAAG,KAAK,EAAE,MAAe,E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A0BlB;AAED,6FAA6F;AAC7F,0FAA0F;AAC1F,0FAA0F;AAC1F,0DAA0D;AAC1D,MAAa,KAAK;IAChB,YAAoB,MAAe,EAAU,OAAiB;QAA1C,WAAM,GAAN,MAAM,CAAS;QAAU,YAAO,GAAP,OAAO,CAAU;QAM9D,gBAAW,GAAG,CAAC,OAAgB,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAEnE,SAAI,GAAG,CAAC,MAAc,EAAE,QAAuB,EAAE,OAAmB,EAAE,EAAE,EAAE,CACxE,IAAA,YAAI,EAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,IAAI,mBAAW,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAA;QAEpF,WAAM,GAAG,CAAC,KAAkB,EAAE,EAAE,CAC9B,IAAA,cAAM,EAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;IAZqC,CAAC;;AADpE,sBAcC;AAXQ,gBAAU,GAAG,CAAC,MAAe,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,AAAzC,CAAyC;AAEnD,gBAAU,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,IAAI,mBAAW,CAAC,MAAM,CAAC,CAAC,AAAzD,CAAyD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { UnwrappedEvent, SignedEvent, HashedEvent, EventTemplate } from '@welshman/util';
|
|
2
|
+
import { ISigner } from './util';
|
|
3
|
+
export declare const seen: Map<string, UnwrappedEvent | Error>;
|
|
4
|
+
export declare const now: (drift?: number) => number;
|
|
5
|
+
export declare const getRumor: (signer: ISigner, template: EventTemplate) => Promise<HashedEvent>;
|
|
6
|
+
export declare const getSeal: (signer: ISigner, pubkey: string, rumor: HashedEvent) => Promise<SignedEvent>;
|
|
7
|
+
export declare const getWrap: (wrapper: ISigner, pubkey: string, seal: SignedEvent, tags: string[][]) => Promise<SignedEvent>;
|
|
8
|
+
export declare const wrap: (signer: ISigner, wrapper: ISigner, pubkey: string, template: EventTemplate, tags?: string[][]) => Promise<UnwrappedEvent>;
|
|
9
|
+
export declare const unwrap: (signer: ISigner, wrap: SignedEvent) => Promise<UnwrappedEvent | undefined>;
|
|
10
|
+
export declare class Nip59 {
|
|
11
|
+
private signer;
|
|
12
|
+
private wrapper?;
|
|
13
|
+
constructor(signer: ISigner, wrapper?: ISigner | undefined);
|
|
14
|
+
static fromSigner: (signer: ISigner) => Nip59;
|
|
15
|
+
static fromSecret: (secret: string) => Nip59;
|
|
16
|
+
withWrapper: (wrapper: ISigner) => Nip59;
|
|
17
|
+
wrap: (pubkey: string, template: EventTemplate, tags?: string[][]) => Promise<UnwrappedEvent>;
|
|
18
|
+
unwrap: (event: SignedEvent) => Promise<UnwrappedEvent | undefined>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { WRAP, SEAL } from '@welshman/util';
|
|
2
|
+
import { own, hash, decrypt } from "./util.mjs";
|
|
3
|
+
import { Nip01Signer } from "./signers/nip01.mjs";
|
|
4
|
+
export const seen = new Map();
|
|
5
|
+
export const now = (drift = 0) => Math.round(Date.now() / 1000 - Math.random() * Math.pow(10, drift));
|
|
6
|
+
export const getRumor = async (signer, template) => hash(own(await signer.getPubkey(), template));
|
|
7
|
+
export const getSeal = async (signer, pubkey, rumor) => signer.sign(hash({
|
|
8
|
+
kind: SEAL,
|
|
9
|
+
pubkey: await signer.getPubkey(),
|
|
10
|
+
content: await signer.nip44.encrypt(pubkey, JSON.stringify(rumor)),
|
|
11
|
+
created_at: now(5),
|
|
12
|
+
tags: [],
|
|
13
|
+
}));
|
|
14
|
+
export const getWrap = async (wrapper, pubkey, seal, tags) => wrapper.sign(hash({
|
|
15
|
+
kind: WRAP,
|
|
16
|
+
pubkey: await wrapper.getPubkey(),
|
|
17
|
+
content: await wrapper.nip44.encrypt(pubkey, JSON.stringify(seal)),
|
|
18
|
+
created_at: now(5),
|
|
19
|
+
tags: [...tags, ["p", pubkey]],
|
|
20
|
+
}));
|
|
21
|
+
export const wrap = async (signer, wrapper, pubkey, template, tags = []) => {
|
|
22
|
+
const rumor = await getRumor(signer, template);
|
|
23
|
+
const seal = await getSeal(signer, pubkey, rumor);
|
|
24
|
+
const wrap = await getWrap(wrapper, pubkey, seal, tags);
|
|
25
|
+
return Object.assign(rumor, { wrap });
|
|
26
|
+
};
|
|
27
|
+
export const unwrap = async (signer, wrap) => {
|
|
28
|
+
// Avoid decrypting the same event multiple times
|
|
29
|
+
if (seen.has(wrap.id)) {
|
|
30
|
+
const rumorOrError = seen.get(wrap.id);
|
|
31
|
+
if (rumorOrError instanceof Error) {
|
|
32
|
+
throw rumorOrError;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return rumorOrError;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const seal = JSON.parse(await decrypt(signer, wrap.pubkey, wrap.content));
|
|
40
|
+
const rumor = JSON.parse(await decrypt(signer, seal.pubkey, seal.content));
|
|
41
|
+
if (seal.pubkey !== rumor.pubkey)
|
|
42
|
+
throw new Error("Seal pubkey does not match rumor pubkey");
|
|
43
|
+
seen.set(wrap.id, rumor);
|
|
44
|
+
return Object.assign(rumor, { wrap });
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
seen.set(wrap.id, error);
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
// This is a utility that makes it harder to re-use wrapper signers, since that can result in
|
|
52
|
+
// leaked metadata. It simultaneously makes it easier to wrap stuff, because it allows for
|
|
53
|
+
// wrapping a single user signer and omit the wrapper signer argument to wrap, while still
|
|
54
|
+
// making it possible to pass a wrapper signer if desired.
|
|
55
|
+
export class Nip59 {
|
|
56
|
+
constructor(signer, wrapper) {
|
|
57
|
+
this.signer = signer;
|
|
58
|
+
this.wrapper = wrapper;
|
|
59
|
+
this.withWrapper = (wrapper) => new Nip59(this.signer, wrapper);
|
|
60
|
+
this.wrap = (pubkey, template, tags = []) => wrap(this.signer, this.wrapper || Nip01Signer.ephemeral(), pubkey, template, tags);
|
|
61
|
+
this.unwrap = (event) => unwrap(this.signer, event);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
Nip59.fromSigner = (signer) => new Nip59(signer);
|
|
65
|
+
Nip59.fromSecret = (secret) => new Nip59(new Nip01Signer(secret));
|
|
66
|
+
//# sourceMappingURL=nip59.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nip59.mjs","sourceRoot":"","sources":["../../src/nip59.ts"],"names":[],"mappings":"OAAO,EAA0D,IAAI,EAAE,IAAI,EAAC,MAAM,gBAAgB;OAC3F,EAAC,GAAG,EAAE,IAAI,EAAE,OAAO,EAAU;OAC7B,EAAC,WAAW,EAAC;AAEpB,MAAM,CAAC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAkC,CAAA;AAE7D,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,KAAK,GAAG,CAAC,EAAE,EAAE,CAC/B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAA;AAErE,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAAE,MAAe,EAAE,QAAuB,EAAE,EAAE,CACzE,IAAI,CAAC,GAAG,CAAC,MAAM,MAAM,CAAC,SAAS,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAA;AAE/C,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,EAAE,MAAe,EAAE,MAAc,EAAE,KAAkB,EAAE,EAAE,CACnF,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;IACf,IAAI,EAAE,IAAI;IACV,MAAM,EA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,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAEnE,SAAI,GAAG,CAAC,MAAc,EAAE,QAAuB,EAAE,OAAmB,EAAE,EAAE,EAAE,CACxE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,IAAI,WAAW,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAA;QAEpF,WAAM,GAAG,CAAC,KAAkB,EAAE,EAAE,CAC9B,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;IAZqC,CAAC;;AAE3D,gBAAU,GAAG,CAAC,MAAe,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,AAAzC,CAAyC;AAEnD,gBAAU,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC,AAAzD,CAAyD"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Nip01Signer = void 0;
|
|
4
|
+
const util_1 = require("../util.cjs");
|
|
5
|
+
class Nip01Signer {
|
|
6
|
+
constructor(secret) {
|
|
7
|
+
this.secret = secret;
|
|
8
|
+
this.getPubkey = async () => this.pubkey;
|
|
9
|
+
this.sign = async (event) => (0, util_1.sign)((0, util_1.hash)((0, util_1.own)(this.pubkey, event)), this.secret);
|
|
10
|
+
this.nip04 = {
|
|
11
|
+
encrypt: async (pubkey, message) => util_1.nip04.encrypt(pubkey, this.secret, message),
|
|
12
|
+
decrypt: async (pubkey, message) => util_1.nip04.decrypt(pubkey, this.secret, message),
|
|
13
|
+
};
|
|
14
|
+
this.nip44 = {
|
|
15
|
+
encrypt: async (pubkey, message) => util_1.nip44.encrypt(pubkey, this.secret, message),
|
|
16
|
+
decrypt: async (pubkey, message) => util_1.nip44.decrypt(pubkey, this.secret, message),
|
|
17
|
+
};
|
|
18
|
+
this.pubkey = (0, util_1.getPubkey)(this.secret);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.Nip01Signer = Nip01Signer;
|
|
22
|
+
Nip01Signer.fromSecret = (secret) => new Nip01Signer(secret);
|
|
23
|
+
Nip01Signer.ephemeral = () => new Nip01Signer((0, util_1.makeSecret)());
|
|
24
|
+
//# sourceMappingURL=nip01.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nip01.cjs","sourceRoot":"","sources":["../../../src/signers/nip01.ts"],"names":[],"mappings":";;;AACA,sCAAqF;AAErF,MAAa,WAAW;IAGtB,YAAoB,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;QAQlC,cAAS,GAAG,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,MAAM,CAAA;QAEnC,SAAI,GAAG,KAAK,EAAE,KAAoB,EAAE,EAAE,CAAC,IAAA,WAAI,EAAC,IAAA,WAAI,EAAC,IAAA,UAAG,EAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;QAEvF,UAAK,GAAG;YACN,OAAO,EAAE,KAAK,EAAE,MAAc,EAAE,OAAe,EAAE,EAAE,CACjD,YAAK,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC;YAC7C,OAAO,EAAE,KAAK,EAAE,MAAc,EAAE,OAAe,EAAE,EAAE,CACjD,YAAK,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC;SAC9C,CAAA;QAED,UAAK,GAAG;YACN,OAAO,EAAE,KAAK,EAAE,MAAc,EAAE,OAAe,EAAE,EAAE,CACjD,YAAK,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC;YAC7C,OAAO,EAAE,KAAK,EAAE,MAAc,EAAE,OAAe,EAAE,EAAE,CACjD,YAAK,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC;SAC9C,CAAA;QAvBC,IAAI,CAAC,MAAM,GAAG,IAAA,gBAAS,EAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACtC,CAAC;;AALH,kCA4BC;AArBQ,sBAAU,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,IAAI,WAAW,CAAC,MAAM,CAAC,AAA9C,CAA8C;AAExD,qBAAS,GAAG,GAAG,EAAE,CAAC,IAAI,WAAW,CAAC,IAAA,iBAAU,GAAE,CAAC,AAAtC,CAAsC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { EventTemplate } from '@welshman/util';
|
|
2
2
|
import { ISigner } from "../util";
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class Nip01Signer implements ISigner {
|
|
4
4
|
private secret;
|
|
5
5
|
private pubkey;
|
|
6
6
|
constructor(secret: string);
|
|
7
|
-
|
|
7
|
+
static fromSecret: (secret: string) => Nip01Signer;
|
|
8
|
+
static ephemeral: () => Nip01Signer;
|
|
8
9
|
getPubkey: () => Promise<string>;
|
|
9
10
|
sign: (event: EventTemplate) => Promise<{
|
|
10
11
|
sig: string;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { nip04, nip44, own, hash, sign, getPubkey } from "../util.mjs";
|
|
2
|
-
export class
|
|
1
|
+
import { nip04, nip44, own, hash, sign, getPubkey, makeSecret } from "../util.mjs";
|
|
2
|
+
export class Nip01Signer {
|
|
3
3
|
constructor(secret) {
|
|
4
4
|
this.secret = secret;
|
|
5
|
-
this.isEnabled = () => true;
|
|
6
5
|
this.getPubkey = async () => this.pubkey;
|
|
7
6
|
this.sign = async (event) => sign(hash(own(this.pubkey, event)), this.secret);
|
|
8
7
|
this.nip04 = {
|
|
@@ -16,4 +15,6 @@ export class SecretSigner {
|
|
|
16
15
|
this.pubkey = getPubkey(this.secret);
|
|
17
16
|
}
|
|
18
17
|
}
|
|
19
|
-
|
|
18
|
+
Nip01Signer.fromSecret = (secret) => new Nip01Signer(secret);
|
|
19
|
+
Nip01Signer.ephemeral = () => new Nip01Signer(makeSecret());
|
|
20
|
+
//# sourceMappingURL=nip01.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nip01.mjs","sourceRoot":"","sources":["../../../src/signers/nip01.ts"],"names":[],"mappings":"OACO,EAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAW,UAAU,EAAC;AAEtE,MAAM,OAAO,WAAW;IAGtB,YAAoB,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;QAQlC,cAAS,GAAG,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,MAAM,CAAA;QAEnC,SAAI,GAAG,KAAK,EAAE,KAAoB,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;QAEvF,UAAK,GAAG;YACN,OAAO,EAAE,KAAK,EAAE,MAAc,EAAE,OAAe,EAAE,EAAE,CACjD,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC;YAC7C,OAAO,EAAE,KAAK,EAAE,MAAc,EAAE,OAAe,EAAE,EAAE,CACjD,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC;SAC9C,CAAA;QAED,UAAK,GAAG;YACN,OAAO,EAAE,KAAK,EAAE,MAAc,EAAE,OAAe,EAAE,EAAE,CACjD,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC;YAC7C,OAAO,EAAE,KAAK,EAAE,MAAc,EAAE,OAAe,EAAE,EAAE,CACjD,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC;SAC9C,CAAA;QAvBC,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACtC,CAAC;;AAEM,sBAAU,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,IAAI,WAAW,CAAC,MAAM,CAAC,AAA9C,CAA8C;AAExD,qBAAS,GAAG,GAAG,EAAE,CAAC,IAAI,WAAW,CAAC,UAAU,EAAE,CAAC,AAAtC,CAAsC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
8
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
11
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
12
|
+
};
|
|
13
|
+
var _Nip07Signer_lock, _Nip07Signer_then;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.Nip07Signer = exports.getNip07 = void 0;
|
|
16
|
+
const util_1 = require("../util.cjs");
|
|
17
|
+
const getNip07 = () => window.nostr;
|
|
18
|
+
exports.getNip07 = getNip07;
|
|
19
|
+
class Nip07Signer {
|
|
20
|
+
constructor() {
|
|
21
|
+
_Nip07Signer_lock.set(this, Promise.resolve());
|
|
22
|
+
_Nip07Signer_then.set(this, async (f) => {
|
|
23
|
+
const promise = __classPrivateFieldGet(this, _Nip07Signer_lock, "f").then(() => {
|
|
24
|
+
const ext = (0, exports.getNip07)();
|
|
25
|
+
if (!ext)
|
|
26
|
+
throw new Error("Nip07 is not enabled");
|
|
27
|
+
return f(ext);
|
|
28
|
+
});
|
|
29
|
+
// Recover from errors
|
|
30
|
+
__classPrivateFieldSet(this, _Nip07Signer_lock, promise.then(() => undefined, () => undefined), "f");
|
|
31
|
+
return promise;
|
|
32
|
+
});
|
|
33
|
+
this.getPubkey = async () => (0, exports.getNip07)().getPublicKey();
|
|
34
|
+
this.sign = async (template) => {
|
|
35
|
+
const event = (0, util_1.hash)((0, util_1.own)(await this.getPubkey(), template));
|
|
36
|
+
return __classPrivateFieldGet(this, _Nip07Signer_then, "f").call(this, ext => ext.signEvent(event));
|
|
37
|
+
};
|
|
38
|
+
this.nip04 = {
|
|
39
|
+
encrypt: (pubkey, message) => __classPrivateFieldGet(this, _Nip07Signer_then, "f").call(this, ext => ext.nip04.encrypt(pubkey, message)),
|
|
40
|
+
decrypt: (pubkey, message) => __classPrivateFieldGet(this, _Nip07Signer_then, "f").call(this, ext => ext.nip04.decrypt(pubkey, message)),
|
|
41
|
+
};
|
|
42
|
+
this.nip44 = {
|
|
43
|
+
encrypt: (pubkey, message) => __classPrivateFieldGet(this, _Nip07Signer_then, "f").call(this, ext => ext.nip44.encrypt(pubkey, message)),
|
|
44
|
+
decrypt: (pubkey, message) => __classPrivateFieldGet(this, _Nip07Signer_then, "f").call(this, ext => ext.nip44.decrypt(pubkey, message)),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.Nip07Signer = Nip07Signer;
|
|
49
|
+
_Nip07Signer_lock = new WeakMap(), _Nip07Signer_then = new WeakMap();
|
|
50
|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ED,UAAK,GAAG;YACN,OAAO,EAAE,CAAC,MAAc,EAAE,OAAe,EAAE,EAAE,CAC3C,uBAAA,IAAI,yBAAM,MAAV,IAAI,EAAO,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACvD,OAAO,EAAE,CAAC,MAAc,EAAE,OAAe,EAAE,EAAE,CAC3C,uBAAA,IAAI,yBAAM,MAAV,IAAI,EAAO,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;SACxD,CAAA;QAED,UAAK,GAAG;YACN,OAAO,EAAE,CAAC,MAAc,EAAE,OAAe,EAAE,EAAE,CAC3C,uBAAA,IAAI,yBAAM,MAAV,IAAI,EAAO,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACvD,OAAO,EAAE,CAAC,MAAc,EAAE,OAAe,EAAE,EAAE,CAC3C,uBAAA,IAAI,yBAAM,MAAV,IAAI,EAAO,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;SACxD,CAAA;IACH,CAAC;CAAA;AAvCD,kCAuCC"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { EventTemplate } from '@welshman/util';
|
|
2
2
|
import { Sign, ISigner, EncryptionImplementation } from '../util';
|
|
3
|
-
export type
|
|
4
|
-
|
|
3
|
+
export type Nip07 = {
|
|
4
|
+
signEvent: Sign;
|
|
5
5
|
nip04: EncryptionImplementation;
|
|
6
6
|
nip44: EncryptionImplementation;
|
|
7
7
|
getPublicKey: () => string | undefined;
|
|
8
8
|
};
|
|
9
|
-
export declare
|
|
9
|
+
export declare const getNip07: () => Nip07 | undefined;
|
|
10
|
+
export declare class Nip07Signer implements ISigner {
|
|
10
11
|
#private;
|
|
11
|
-
isEnabled: () => boolean;
|
|
12
12
|
getPubkey: () => Promise<string>;
|
|
13
|
-
sign: (
|
|
13
|
+
sign: (template: EventTemplate) => Promise<import("@welshman/util").SignedEvent>;
|
|
14
14
|
nip04: {
|
|
15
15
|
encrypt: (pubkey: string, message: string) => Promise<string>;
|
|
16
16
|
decrypt: (pubkey: string, message: string) => Promise<string>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
|
+
};
|
|
12
|
+
var _Nip07Signer_lock, _Nip07Signer_then;
|
|
13
|
+
import { hash, own } from "../util.mjs";
|
|
14
|
+
export const getNip07 = () => window.nostr;
|
|
15
|
+
export class Nip07Signer {
|
|
16
|
+
constructor() {
|
|
17
|
+
_Nip07Signer_lock.set(this, Promise.resolve());
|
|
18
|
+
_Nip07Signer_then.set(this, async (f) => {
|
|
19
|
+
const promise = __classPrivateFieldGet(this, _Nip07Signer_lock, "f").then(() => {
|
|
20
|
+
const ext = getNip07();
|
|
21
|
+
if (!ext)
|
|
22
|
+
throw new Error("Nip07 is not enabled");
|
|
23
|
+
return f(ext);
|
|
24
|
+
});
|
|
25
|
+
// Recover from errors
|
|
26
|
+
__classPrivateFieldSet(this, _Nip07Signer_lock, promise.then(() => undefined, () => undefined), "f");
|
|
27
|
+
return promise;
|
|
28
|
+
});
|
|
29
|
+
this.getPubkey = async () => getNip07().getPublicKey();
|
|
30
|
+
this.sign = async (template) => {
|
|
31
|
+
const event = hash(own(await this.getPubkey(), template));
|
|
32
|
+
return __classPrivateFieldGet(this, _Nip07Signer_then, "f").call(this, ext => ext.signEvent(event));
|
|
33
|
+
};
|
|
34
|
+
this.nip04 = {
|
|
35
|
+
encrypt: (pubkey, message) => __classPrivateFieldGet(this, _Nip07Signer_then, "f").call(this, ext => ext.nip04.encrypt(pubkey, message)),
|
|
36
|
+
decrypt: (pubkey, message) => __classPrivateFieldGet(this, _Nip07Signer_then, "f").call(this, ext => ext.nip04.decrypt(pubkey, message)),
|
|
37
|
+
};
|
|
38
|
+
this.nip44 = {
|
|
39
|
+
encrypt: (pubkey, message) => __classPrivateFieldGet(this, _Nip07Signer_then, "f").call(this, ext => ext.nip44.encrypt(pubkey, message)),
|
|
40
|
+
decrypt: (pubkey, message) => __classPrivateFieldGet(this, _Nip07Signer_then, "f").call(this, ext => ext.nip44.decrypt(pubkey, message)),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
_Nip07Signer_lock = new WeakMap(), _Nip07Signer_then = new WeakMap();
|
|
45
|
+
//# sourceMappingURL=nip07.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nip07.mjs","sourceRoot":"","sources":["../../../src/signers/nip07.ts"],"names":[],"mappings":";;;;;;;;;;;;OACO,EAAC,IAAI,EAAE,GAAG,EAA0C;AAS3D,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG,EAAE,CAAE,MAA0B,CAAC,KAAK,CAAA;AAE/D,MAAM,OAAO,WAAW;IAAxB;QACE,4B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CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;SACxD,CAAA;QAED,UAAK,GAAG;YACN,OAAO,EAAE,CAAC,MAAc,EAAE,OAAe,EAAE,EAAE,CAC3C,uBAAA,IAAI,yBAAM,MAAV,IAAI,EAAO,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACvD,OAAO,EAAE,CAAC,MAAc,EAAE,OAAe,EAAE,EAAE,CAC3C,uBAAA,IAAI,yBAAM,MAAV,IAAI,EAAO,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;SACxD,CAAA;IACH,CAAC;CAAA"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _Nip46Broker_sub, _Nip46Broker_signer, _Nip46Broker_ready, _Nip46Broker_closed, _Nip46Broker_connectResult;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.Nip46Signer = exports.Nip46Broker = void 0;
|
|
16
|
+
const nostr_tools_1 = require("nostr-tools");
|
|
17
|
+
const utils_1 = require("@noble/hashes/utils");
|
|
18
|
+
const lib_1 = require("@welshman/lib");
|
|
19
|
+
const util_1 = require("@welshman/util");
|
|
20
|
+
const net_1 = require("@welshman/net");
|
|
21
|
+
const util_2 = require("../util.cjs");
|
|
22
|
+
const nip01_1 = require("./nip01.cjs");
|
|
23
|
+
let singleton;
|
|
24
|
+
// FIXME set the full list of requested perms
|
|
25
|
+
const Perms = "nip04_encrypt,nip04_decrypt,sign_event:0,sign_event:1,sign_event:4,sign_event:6,sign_event:7";
|
|
26
|
+
class Nip46Broker extends lib_1.Emitter {
|
|
27
|
+
static get(pubkey, secret, handler) {
|
|
28
|
+
if ((singleton === null || singleton === void 0 ? void 0 : singleton.pubkey) !== pubkey ||
|
|
29
|
+
(singleton === null || singleton === void 0 ? void 0 : singleton.secret) !== secret ||
|
|
30
|
+
!(0, lib_1.equals)(singleton === null || singleton === void 0 ? void 0 : singleton.handler, handler)) {
|
|
31
|
+
singleton === null || singleton === void 0 ? void 0 : singleton.teardown();
|
|
32
|
+
singleton = new Nip46Broker(pubkey, secret, handler);
|
|
33
|
+
}
|
|
34
|
+
return singleton;
|
|
35
|
+
}
|
|
36
|
+
constructor(pubkey, secret, handler) {
|
|
37
|
+
super();
|
|
38
|
+
this.pubkey = pubkey;
|
|
39
|
+
this.secret = secret;
|
|
40
|
+
this.handler = handler;
|
|
41
|
+
_Nip46Broker_sub.set(this, void 0);
|
|
42
|
+
_Nip46Broker_signer.set(this, void 0);
|
|
43
|
+
_Nip46Broker_ready.set(this, (0, lib_1.sleep)(500));
|
|
44
|
+
_Nip46Broker_closed.set(this, false);
|
|
45
|
+
_Nip46Broker_connectResult.set(this, void 0);
|
|
46
|
+
__classPrivateFieldSet(this, _Nip46Broker_signer, new nip01_1.Nip01Signer(secret), "f");
|
|
47
|
+
__classPrivateFieldSet(this, _Nip46Broker_sub, this.subscribe(), "f");
|
|
48
|
+
}
|
|
49
|
+
subscribe() {
|
|
50
|
+
const sub = (0, net_1.subscribe)({
|
|
51
|
+
relays: this.handler.relays,
|
|
52
|
+
filters: [
|
|
53
|
+
{
|
|
54
|
+
since: (0, lib_1.now)() - 30,
|
|
55
|
+
kinds: [util_1.NOSTR_CONNECT],
|
|
56
|
+
"#p": [(0, nostr_tools_1.getPublicKey)((0, utils_1.hexToBytes)(this.secret))],
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
});
|
|
60
|
+
sub.emitter.on("event", async (url, e) => {
|
|
61
|
+
const json = await (0, util_2.decrypt)(__classPrivateFieldGet(this, _Nip46Broker_signer, "f"), e.pubkey, e.content);
|
|
62
|
+
const res = await (0, lib_1.tryCatch)(() => JSON.parse(json));
|
|
63
|
+
if (!res.id) {
|
|
64
|
+
console.error(`Invalid nostr-connect response: ${json}`);
|
|
65
|
+
}
|
|
66
|
+
if (res.result === "auth_url") {
|
|
67
|
+
this.emit(`auth-${res.id}`, res);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
this.emit(`res-${res.id}`, res);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
sub.emitter.on("complete", () => {
|
|
74
|
+
if (!__classPrivateFieldGet(this, _Nip46Broker_closed, "f")) {
|
|
75
|
+
__classPrivateFieldSet(this, _Nip46Broker_sub, this.subscribe(), "f");
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
return sub;
|
|
79
|
+
}
|
|
80
|
+
async request(method, params, admin = false) {
|
|
81
|
+
// nsecbunker has a race condition
|
|
82
|
+
await __classPrivateFieldGet(this, _Nip46Broker_ready, "f");
|
|
83
|
+
const id = (0, lib_1.randomId)();
|
|
84
|
+
const pubkey = admin ? this.handler.pubkey : this.pubkey;
|
|
85
|
+
const payload = JSON.stringify({ id, method, params });
|
|
86
|
+
const content = await nostr_tools_1.nip04.encrypt(this.secret, pubkey, payload);
|
|
87
|
+
const template = (0, util_1.createEvent)(util_1.NOSTR_CONNECT, { content, tags: [["p", pubkey]] });
|
|
88
|
+
const event = (0, nostr_tools_1.finalizeEvent)(template, this.secret);
|
|
89
|
+
(0, net_1.publish)({ event, relays: this.handler.relays });
|
|
90
|
+
this.once(`auth-${id}`, res => {
|
|
91
|
+
window.open(res.result, "Coracle", "width=600,height=800,popup=yes");
|
|
92
|
+
});
|
|
93
|
+
return new Promise((resolve, reject) => {
|
|
94
|
+
this.once(`res-${id}`, ({ result, error }) => {
|
|
95
|
+
if (error) {
|
|
96
|
+
reject(error);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
resolve(result);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
createAccount(username) {
|
|
105
|
+
if (!this.handler.domain) {
|
|
106
|
+
throw new Error("Unable to create an account without a handler domain");
|
|
107
|
+
}
|
|
108
|
+
return this.request("create_account", [username, this.handler.domain, "", Perms], true);
|
|
109
|
+
}
|
|
110
|
+
async connect(token = "") {
|
|
111
|
+
if (!__classPrivateFieldGet(this, _Nip46Broker_connectResult, "f")) {
|
|
112
|
+
const params = [this.pubkey, token, Perms];
|
|
113
|
+
__classPrivateFieldSet(this, _Nip46Broker_connectResult, await this.request("connect", params), "f");
|
|
114
|
+
}
|
|
115
|
+
return __classPrivateFieldGet(this, _Nip46Broker_connectResult, "f") === "ack";
|
|
116
|
+
}
|
|
117
|
+
async signEvent(event) {
|
|
118
|
+
return JSON.parse(await this.request("sign_event", [JSON.stringify(event)]));
|
|
119
|
+
}
|
|
120
|
+
nip04Encrypt(pk, message) {
|
|
121
|
+
return this.request("nip04_encrypt", [pk, message]);
|
|
122
|
+
}
|
|
123
|
+
nip04Decrypt(pk, message) {
|
|
124
|
+
return this.request("nip04_decrypt", [pk, message]);
|
|
125
|
+
}
|
|
126
|
+
nip44Encrypt(pk, message) {
|
|
127
|
+
return this.request("nip44_encrypt", [pk, message]);
|
|
128
|
+
}
|
|
129
|
+
nip44Decrypt(pk, message) {
|
|
130
|
+
return this.request("nip44_decrypt", [pk, message]);
|
|
131
|
+
}
|
|
132
|
+
teardown() {
|
|
133
|
+
var _a;
|
|
134
|
+
__classPrivateFieldSet(this, _Nip46Broker_closed, true, "f");
|
|
135
|
+
(_a = __classPrivateFieldGet(this, _Nip46Broker_sub, "f")) === null || _a === void 0 ? void 0 : _a.close();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.Nip46Broker = Nip46Broker;
|
|
139
|
+
_Nip46Broker_sub = new WeakMap(), _Nip46Broker_signer = new WeakMap(), _Nip46Broker_ready = new WeakMap(), _Nip46Broker_closed = new WeakMap(), _Nip46Broker_connectResult = new WeakMap();
|
|
140
|
+
class Nip46Signer {
|
|
141
|
+
constructor(broker) {
|
|
142
|
+
this.broker = broker;
|
|
143
|
+
this.getPubkey = async () => this.broker.pubkey;
|
|
144
|
+
this.sign = (event) => this.broker.signEvent(event);
|
|
145
|
+
this.nip04 = {
|
|
146
|
+
encrypt: this.broker.nip04Encrypt,
|
|
147
|
+
decrypt: this.broker.nip04Decrypt,
|
|
148
|
+
};
|
|
149
|
+
this.nip44 = {
|
|
150
|
+
encrypt: this.broker.nip44Encrypt,
|
|
151
|
+
decrypt: this.broker.nip44Decrypt,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
exports.Nip46Signer = Nip46Signer;
|
|
156
|
+
//# sourceMappingURL=nip46.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nip46.cjs","sourceRoot":"","sources":["../../../src/signers/nip46.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6CAA8D;AAC9D,+CAA8C;AAC9C,uCAA6E;AAC7E,yCAAsF;AACtF,uCAA8D;AAC9D,sCAAwC;AACxC,uCAAmC;AAcnC,IAA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IACrD,CAAC;IAED,YAAY,CAAC,EAAU,EAAE,OAAe;QACtC,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC,CAAA;IACrD,CAAC;IAED,QAAQ;;QACN,uBAAA,IAAI,uBAAW,IAAI,MAAA,CAAA;QACnB,MAAA,uBAAA,IAAI,wBAAK,0CAAE,KAAK,EAAE,CAAA;IACpB,CAAC;CACF;AAzID,kCAyIC;;AAED,MAAa,WAAW;IACtB,YAAoB,MAAmB;QAAnB,WAAM,GAAN,MAAM,CAAa;QAEvC,cAAS,GAAG,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAA;QAE1C,SAAI,GAAG,CAAC,KAAoB,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;QAE7D,UAAK,GAAG;YACN,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY;YACjC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY;SAClC,CAAA;QAED,UAAK,GAAG;YACN,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY;YACjC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY;SAClC,CAAA;IAdyC,CAAC;CAe5C;AAhBD,kCAgBC"}
|
|
@@ -2,23 +2,23 @@ import { Emitter } from "@welshman/lib";
|
|
|
2
2
|
import { EventTemplate } from "@welshman/util";
|
|
3
3
|
import { Subscription } from "@welshman/net";
|
|
4
4
|
import { ISigner } from '../util';
|
|
5
|
-
export type
|
|
6
|
-
pubkey: string;
|
|
5
|
+
export type Nip46Handler = {
|
|
7
6
|
relays: string[];
|
|
7
|
+
pubkey?: string;
|
|
8
8
|
domain?: string;
|
|
9
9
|
};
|
|
10
|
-
export type
|
|
10
|
+
export type Nip46Response = {
|
|
11
11
|
id: string;
|
|
12
12
|
error?: string;
|
|
13
13
|
result?: string;
|
|
14
14
|
};
|
|
15
|
-
export declare class
|
|
15
|
+
export declare class Nip46Broker extends Emitter {
|
|
16
16
|
#private;
|
|
17
17
|
readonly pubkey: string;
|
|
18
18
|
readonly secret: string;
|
|
19
|
-
readonly handler:
|
|
20
|
-
static get(pubkey: string, secret: string, handler:
|
|
21
|
-
constructor(pubkey: string, secret: string, handler:
|
|
19
|
+
readonly handler: Nip46Handler;
|
|
20
|
+
static get(pubkey: string, secret: string, handler: Nip46Handler): Nip46Broker;
|
|
21
|
+
constructor(pubkey: string, secret: string, handler: Nip46Handler);
|
|
22
22
|
subscribe(): Subscription;
|
|
23
23
|
request(method: string, params: string[], admin?: boolean): Promise<string>;
|
|
24
24
|
createAccount(username: string): Promise<string>;
|
|
@@ -30,10 +30,9 @@ export declare class NostrConnectBroker extends Emitter {
|
|
|
30
30
|
nip44Decrypt(pk: string, message: string): Promise<string>;
|
|
31
31
|
teardown(): void;
|
|
32
32
|
}
|
|
33
|
-
export declare class
|
|
33
|
+
export declare class Nip46Signer implements ISigner {
|
|
34
34
|
private broker;
|
|
35
|
-
constructor(broker:
|
|
36
|
-
isEnabled: () => boolean;
|
|
35
|
+
constructor(broker: Nip46Broker);
|
|
37
36
|
getPubkey: () => Promise<string>;
|
|
38
37
|
sign: (event: EventTemplate) => Promise<any>;
|
|
39
38
|
nip04: {
|
|
@@ -9,24 +9,24 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var
|
|
12
|
+
var _Nip46Broker_sub, _Nip46Broker_signer, _Nip46Broker_ready, _Nip46Broker_closed, _Nip46Broker_connectResult;
|
|
13
13
|
import { nip04, finalizeEvent, getPublicKey } from "nostr-tools";
|
|
14
14
|
import { hexToBytes } from '@noble/hashes/utils';
|
|
15
15
|
import { Emitter, tryCatch, randomId, sleep, equals, now } from "@welshman/lib";
|
|
16
16
|
import { createEvent, NOSTR_CONNECT } from "@welshman/util";
|
|
17
17
|
import { subscribe, publish } from "@welshman/net";
|
|
18
18
|
import { decrypt } from "../util.mjs";
|
|
19
|
-
import {
|
|
19
|
+
import { Nip01Signer } from "./nip01.mjs";
|
|
20
20
|
let singleton;
|
|
21
21
|
// FIXME set the full list of requested perms
|
|
22
22
|
const Perms = "nip04_encrypt,nip04_decrypt,sign_event:0,sign_event:1,sign_event:4,sign_event:6,sign_event:7";
|
|
23
|
-
export class
|
|
23
|
+
export class Nip46Broker extends Emitter {
|
|
24
24
|
static get(pubkey, secret, handler) {
|
|
25
25
|
if ((singleton === null || singleton === void 0 ? void 0 : singleton.pubkey) !== pubkey ||
|
|
26
26
|
(singleton === null || singleton === void 0 ? void 0 : singleton.secret) !== secret ||
|
|
27
27
|
!equals(singleton === null || singleton === void 0 ? void 0 : singleton.handler, handler)) {
|
|
28
28
|
singleton === null || singleton === void 0 ? void 0 : singleton.teardown();
|
|
29
|
-
singleton = new
|
|
29
|
+
singleton = new Nip46Broker(pubkey, secret, handler);
|
|
30
30
|
}
|
|
31
31
|
return singleton;
|
|
32
32
|
}
|
|
@@ -35,13 +35,13 @@ export class NostrConnectBroker extends Emitter {
|
|
|
35
35
|
this.pubkey = pubkey;
|
|
36
36
|
this.secret = secret;
|
|
37
37
|
this.handler = handler;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
__classPrivateFieldSet(this,
|
|
44
|
-
__classPrivateFieldSet(this,
|
|
38
|
+
_Nip46Broker_sub.set(this, void 0);
|
|
39
|
+
_Nip46Broker_signer.set(this, void 0);
|
|
40
|
+
_Nip46Broker_ready.set(this, sleep(500));
|
|
41
|
+
_Nip46Broker_closed.set(this, false);
|
|
42
|
+
_Nip46Broker_connectResult.set(this, void 0);
|
|
43
|
+
__classPrivateFieldSet(this, _Nip46Broker_signer, new Nip01Signer(secret), "f");
|
|
44
|
+
__classPrivateFieldSet(this, _Nip46Broker_sub, this.subscribe(), "f");
|
|
45
45
|
}
|
|
46
46
|
subscribe() {
|
|
47
47
|
const sub = subscribe({
|
|
@@ -55,7 +55,7 @@ export class NostrConnectBroker extends Emitter {
|
|
|
55
55
|
],
|
|
56
56
|
});
|
|
57
57
|
sub.emitter.on("event", async (url, e) => {
|
|
58
|
-
const json = await decrypt(__classPrivateFieldGet(this,
|
|
58
|
+
const json = await decrypt(__classPrivateFieldGet(this, _Nip46Broker_signer, "f"), e.pubkey, e.content);
|
|
59
59
|
const res = await tryCatch(() => JSON.parse(json));
|
|
60
60
|
if (!res.id) {
|
|
61
61
|
console.error(`Invalid nostr-connect response: ${json}`);
|
|
@@ -68,15 +68,15 @@ export class NostrConnectBroker extends Emitter {
|
|
|
68
68
|
}
|
|
69
69
|
});
|
|
70
70
|
sub.emitter.on("complete", () => {
|
|
71
|
-
if (!__classPrivateFieldGet(this,
|
|
72
|
-
__classPrivateFieldSet(this,
|
|
71
|
+
if (!__classPrivateFieldGet(this, _Nip46Broker_closed, "f")) {
|
|
72
|
+
__classPrivateFieldSet(this, _Nip46Broker_sub, this.subscribe(), "f");
|
|
73
73
|
}
|
|
74
74
|
});
|
|
75
75
|
return sub;
|
|
76
76
|
}
|
|
77
77
|
async request(method, params, admin = false) {
|
|
78
78
|
// nsecbunker has a race condition
|
|
79
|
-
await __classPrivateFieldGet(this,
|
|
79
|
+
await __classPrivateFieldGet(this, _Nip46Broker_ready, "f");
|
|
80
80
|
const id = randomId();
|
|
81
81
|
const pubkey = admin ? this.handler.pubkey : this.pubkey;
|
|
82
82
|
const payload = JSON.stringify({ id, method, params });
|
|
@@ -105,11 +105,11 @@ export class NostrConnectBroker extends Emitter {
|
|
|
105
105
|
return this.request("create_account", [username, this.handler.domain, "", Perms], true);
|
|
106
106
|
}
|
|
107
107
|
async connect(token = "") {
|
|
108
|
-
if (!__classPrivateFieldGet(this,
|
|
108
|
+
if (!__classPrivateFieldGet(this, _Nip46Broker_connectResult, "f")) {
|
|
109
109
|
const params = [this.pubkey, token, Perms];
|
|
110
|
-
__classPrivateFieldSet(this,
|
|
110
|
+
__classPrivateFieldSet(this, _Nip46Broker_connectResult, await this.request("connect", params), "f");
|
|
111
111
|
}
|
|
112
|
-
return __classPrivateFieldGet(this,
|
|
112
|
+
return __classPrivateFieldGet(this, _Nip46Broker_connectResult, "f") === "ack";
|
|
113
113
|
}
|
|
114
114
|
async signEvent(event) {
|
|
115
115
|
return JSON.parse(await this.request("sign_event", [JSON.stringify(event)]));
|
|
@@ -128,15 +128,14 @@ export class NostrConnectBroker extends Emitter {
|
|
|
128
128
|
}
|
|
129
129
|
teardown() {
|
|
130
130
|
var _a;
|
|
131
|
-
__classPrivateFieldSet(this,
|
|
132
|
-
(_a = __classPrivateFieldGet(this,
|
|
131
|
+
__classPrivateFieldSet(this, _Nip46Broker_closed, true, "f");
|
|
132
|
+
(_a = __classPrivateFieldGet(this, _Nip46Broker_sub, "f")) === null || _a === void 0 ? void 0 : _a.close();
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
|
-
|
|
136
|
-
export class
|
|
135
|
+
_Nip46Broker_sub = new WeakMap(), _Nip46Broker_signer = new WeakMap(), _Nip46Broker_ready = new WeakMap(), _Nip46Broker_closed = new WeakMap(), _Nip46Broker_connectResult = new WeakMap();
|
|
136
|
+
export class Nip46Signer {
|
|
137
137
|
constructor(broker) {
|
|
138
138
|
this.broker = broker;
|
|
139
|
-
this.isEnabled = () => true;
|
|
140
139
|
this.getPubkey = async () => this.broker.pubkey;
|
|
141
140
|
this.sign = (event) => this.broker.signEvent(event);
|
|
142
141
|
this.nip04 = {
|
|
@@ -149,4 +148,4 @@ export class ConnectSigner {
|
|
|
149
148
|
};
|
|
150
149
|
}
|
|
151
150
|
}
|
|
152
|
-
//# sourceMappingURL=
|
|
151
|
+
//# sourceMappingURL=nip46.mjs.map
|
|
@@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|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decrypt = exports.nip44 = exports.nip04 = exports.sign = exports.hash = exports.own = exports.getSig = exports.getHash = exports.getPubkey = exports.makeSecret = void 0;
|
|
4
|
+
const secp256k1_1 = require("@noble/curves/secp256k1");
|
|
5
|
+
const utils_1 = require("@noble/hashes/utils");
|
|
6
|
+
const nostr_tools_1 = require("nostr-tools");
|
|
7
|
+
const lib_1 = require("@welshman/lib");
|
|
8
|
+
const makeSecret = () => (0, utils_1.bytesToHex)((0, nostr_tools_1.generateSecretKey)());
|
|
9
|
+
exports.makeSecret = makeSecret;
|
|
10
|
+
const getPubkey = (secret) => (0, nostr_tools_1.getPublicKey)((0, utils_1.hexToBytes)(secret));
|
|
11
|
+
exports.getPubkey = getPubkey;
|
|
12
|
+
const getHash = (event) => (0, nostr_tools_1.getEventHash)(event);
|
|
13
|
+
exports.getHash = getHash;
|
|
14
|
+
const getSig = (event, secret) => (0, utils_1.bytesToHex)(secp256k1_1.schnorr.sign(event.id, secret));
|
|
15
|
+
exports.getSig = getSig;
|
|
16
|
+
const own = (pubkey, event) => ({ ...event, pubkey });
|
|
17
|
+
exports.own = own;
|
|
18
|
+
const hash = (event) => ({ ...event, id: (0, exports.getHash)(event) });
|
|
19
|
+
exports.hash = hash;
|
|
20
|
+
const sign = (event, secret) => ({ ...event, sig: (0, exports.getSig)(event, secret) });
|
|
21
|
+
exports.sign = sign;
|
|
22
|
+
exports.nip04 = {
|
|
23
|
+
detect: (m) => m.includes("?iv="),
|
|
24
|
+
encrypt: (pubkey, secret, m) => nostr_tools_1.nip04.encrypt(secret, pubkey, m),
|
|
25
|
+
decrypt: (pubkey, secret, m) => nostr_tools_1.nip04.decrypt(secret, pubkey, m),
|
|
26
|
+
};
|
|
27
|
+
exports.nip44 = {
|
|
28
|
+
getSharedSecret: (0, lib_1.cached)({
|
|
29
|
+
maxSize: 10000,
|
|
30
|
+
getKey: ([secret, pubkey]) => [secret, pubkey].join(":"),
|
|
31
|
+
getValue: ([secret, pubkey]) => nostr_tools_1.nip44.v2.utils.getConversationKey((0, utils_1.hexToBytes)(secret), pubkey),
|
|
32
|
+
}),
|
|
33
|
+
encrypt: (pubkey, secret, m) => nostr_tools_1.nip44.v2.encrypt(m, exports.nip44.getSharedSecret(secret, pubkey)),
|
|
34
|
+
decrypt: (pubkey, secret, m) => nostr_tools_1.nip44.v2.decrypt(m, exports.nip44.getSharedSecret(secret, pubkey)),
|
|
35
|
+
};
|
|
36
|
+
const decrypt = async (signer, pubkey, message) => exports.nip04.detect(message)
|
|
37
|
+
? signer.nip04.decrypt(pubkey, message)
|
|
38
|
+
: signer.nip44.decrypt(pubkey, message);
|
|
39
|
+
exports.decrypt = decrypt;
|
|
40
|
+
//# sourceMappingURL=util.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.cjs","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":";;;AAAA,uDAA+C;AAC/C,+CAA0D;AAC1D,6CAAuG;AACvG,uCAAoC;AAG7B,MAAM,UAAU,GAAG,GAAG,EAAE,CAAC,IAAA,kBAAU,EAAC,IAAA,+BAAiB,GAAE,CAAC,CAAA;AAAlD,QAAA,UAAU,cAAwC;AAExD,MAAM,SAAS,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,IAAA,0BAAY,EAAC,IAAA,kBAAU,EAAC,MAAM,CAAC,CAAC,CAAA;AAAhE,QAAA,SAAS,aAAuD;AAEtE,MAAM,OAAO,GAAG,CAAC,KAAiB,EAAE,EAAE,CAAC,IAAA,0BAAY,EAAC,KAAK,CAAC,CAAA;AAApD,QAAA,OAAO,WAA6C;AAE1D,MAAM,MAAM,GAAG,CAAC,KAAkB,EAAE,MAAc,EAAE,EAAE,CAC3D,IAAA,kBAAU,EAAC,mBAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAA;AAD/B,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,CAAC,KAAK,CAAC,kBAAkB,CAAC,IAAA,kBAAU,EAAC,MAAM,CAAC,EAAE,MAAM,CAAC;KACvG,CAAC;IACF,OAAO,EAAE,CAAC,MAAc,EAAE,MAAc,EAAE,CAAS,EAAE,EAAE,CAAC,mBAAI,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE,aAAK,CAAC,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjH,OAAO,EAAE,CAAC,MAAc,EAAE,MAAc,EAAE,CAAS,EAAE,EAAE,CAAC,mBAAI,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE,aAAK,CAAC,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClH,CAAA;AAoBM,MAAM,OAAO,GAAG,KAAK,EAAE,MAAe,EAAE,MAAc,EAAE,OAAe,EAAE,EAAE,CAChF,aAAK,CAAC,MAAM,CAAC,OAAO,CAAC;IACnB,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC;IACvC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAH9B,QAAA,OAAO,WAGuB"}
|
package/build/src/util.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SignedEvent, HashedEvent, EventTemplate, OwnedEvent } from '@welshman/util';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const makeSecret: () => string;
|
|
3
3
|
export declare const getPubkey: (secret: string) => string;
|
|
4
4
|
export declare const getHash: (event: OwnedEvent) => string;
|
|
5
5
|
export declare const getSig: (event: HashedEvent, secret: string) => string;
|
|
@@ -43,10 +43,9 @@ export type EncryptionImplementation = {
|
|
|
43
43
|
decrypt: Decrypt;
|
|
44
44
|
};
|
|
45
45
|
export interface ISigner {
|
|
46
|
-
isEnabled: () => boolean;
|
|
47
|
-
getPubkey: () => Promise<string>;
|
|
48
46
|
sign: Sign;
|
|
49
47
|
nip04: EncryptionImplementation;
|
|
50
48
|
nip44: EncryptionImplementation;
|
|
49
|
+
getPubkey: () => Promise<string>;
|
|
51
50
|
}
|
|
52
51
|
export declare const decrypt: (signer: ISigner, pubkey: string, message: string) => Promise<string>;
|
package/build/src/util.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { schnorr } from '@noble/curves/secp256k1';
|
|
|
2
2
|
import { bytesToHex, hexToBytes } from '@noble/hashes/utils';
|
|
3
3
|
import { nip04 as nt04, nip44 as nt44, generateSecretKey, getPublicKey, getEventHash } from "nostr-tools";
|
|
4
4
|
import { cached } from '@welshman/lib';
|
|
5
|
-
export const
|
|
5
|
+
export const makeSecret = () => bytesToHex(generateSecretKey());
|
|
6
6
|
export const getPubkey = (secret) => getPublicKey(hexToBytes(secret));
|
|
7
7
|
export const getHash = (event) => getEventHash(event);
|
|
8
8
|
export const getSig = (event, secret) => bytesToHex(schnorr.sign(event.id, secret));
|
package/build/src/util.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.mjs","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"OAAO,EAAC,OAAO,EAAC,MAAM,yBAAyB;OACxC,EAAC,UAAU,EAAE,UAAU,EAAC,MAAM,qBAAqB;OACnD,EAAC,KAAK,IAAI,IAAI,EAAE,KAAK,IAAI,IAAI,EAAE,iBAAiB,EAAE,YAAY,EAAE,YAAY,EAAC,MAAM,aAAa;OAChG,EAAC,MAAM,EAAC,MAAM,eAAe;AAGpC,MAAM,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"util.mjs","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"OAAO,EAAC,OAAO,EAAC,MAAM,yBAAyB;OACxC,EAAC,UAAU,EAAE,UAAU,EAAC,MAAM,qBAAqB;OACnD,EAAC,KAAK,IAAI,IAAI,EAAE,KAAK,IAAI,IAAI,EAAE,iBAAiB,EAAE,YAAY,EAAE,YAAY,EA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C,CAAA;IAhBgD,CAAC;CAiBnD"}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
-
};
|
|
6
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
|
-
};
|
|
12
|
-
var _ExtensionSigner_lock, _ExtensionSigner_ext, _ExtensionSigner_then;
|
|
13
|
-
import { hash, own } from "../util.mjs";
|
|
14
|
-
export class ExtensionSigner {
|
|
15
|
-
constructor() {
|
|
16
|
-
_ExtensionSigner_lock.set(this, Promise.resolve());
|
|
17
|
-
_ExtensionSigner_ext.set(this, () => window.nostr);
|
|
18
|
-
_ExtensionSigner_then.set(this, async (f) => {
|
|
19
|
-
const promise = __classPrivateFieldGet(this, _ExtensionSigner_lock, "f").then(() => {
|
|
20
|
-
const ext = __classPrivateFieldGet(this, _ExtensionSigner_ext, "f").call(this);
|
|
21
|
-
if (!ext)
|
|
22
|
-
throw new Error("Extension is not enabled");
|
|
23
|
-
return f(ext);
|
|
24
|
-
});
|
|
25
|
-
// Recover from errors
|
|
26
|
-
__classPrivateFieldSet(this, _ExtensionSigner_lock, promise.then(() => undefined, () => undefined), "f");
|
|
27
|
-
return promise;
|
|
28
|
-
});
|
|
29
|
-
this.isEnabled = () => Boolean(__classPrivateFieldGet(this, _ExtensionSigner_ext, "f").call(this));
|
|
30
|
-
this.getPubkey = () => __classPrivateFieldGet(this, _ExtensionSigner_then, "f").call(this, ext => {
|
|
31
|
-
const pubkey = ext.getPublicKey();
|
|
32
|
-
if (!pubkey)
|
|
33
|
-
throw new Error("Failed to retrieve pubkey");
|
|
34
|
-
return pubkey;
|
|
35
|
-
});
|
|
36
|
-
this.sign = (event) => __classPrivateFieldGet(this, _ExtensionSigner_then, "f").call(this, ext => ext.sign(hash(own(ext.getPublicKey(), event))));
|
|
37
|
-
this.nip04 = {
|
|
38
|
-
encrypt: (pubkey, message) => __classPrivateFieldGet(this, _ExtensionSigner_then, "f").call(this, ext => ext.nip04.encrypt(pubkey, message)),
|
|
39
|
-
decrypt: (pubkey, message) => __classPrivateFieldGet(this, _ExtensionSigner_then, "f").call(this, ext => ext.nip04.decrypt(pubkey, message)),
|
|
40
|
-
};
|
|
41
|
-
this.nip44 = {
|
|
42
|
-
encrypt: (pubkey, message) => __classPrivateFieldGet(this, _ExtensionSigner_then, "f").call(this, ext => ext.nip44.encrypt(pubkey, message)),
|
|
43
|
-
decrypt: (pubkey, message) => __classPrivateFieldGet(this, _ExtensionSigner_then, "f").call(this, ext => ext.nip44.decrypt(pubkey, message)),
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
_ExtensionSigner_lock = new WeakMap(), _ExtensionSigner_ext = new WeakMap(), _ExtensionSigner_then = new WeakMap();
|
|
48
|
-
//# sourceMappingURL=extension.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extension.mjs","sourceRoot":"","sources":["../../../src/signers/extension.ts"],"names":[],"mappings":";;;;;;;;;;;;OACO,EAAC,IAAI,EAAE,GAAG,EAA0C;AAS3D,MAAM,OAAO,eAAe;IAA5B;QACE,gCAAQ,OAAO,CAAC,OAAO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,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;QAEvF,UAAK,GAAG;YACN,OAAO,EAAE,KAAK,EAAE,MAAc,EAAE,OAAe,EAAE,EAAE,CACjD,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC;YAC7C,OAAO,EAAE,KAAK,EAAE,MAAc,EAAE,OAAe,EAAE,EAAE,CACjD,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC;SAC9C,CAAA;QAED,UAAK,GAAG;YACN,OAAO,EAAE,KAAK,EAAE,MAAc,EAAE,OAAe,EAAE,EAAE,CACjD,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC;YAC7C,OAAO,EAAE,KAAK,EAAE,MAAc,EAAE,OAAe,EAAE,EAAE,CACjD,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC;SAC9C,CAAA;QArBC,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACtC,CAAC;CAqBF"}
|
package/build/src/wrapper.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { UnwrappedEvent, SignedEvent, HashedEvent, EventTemplate } from '@welshman/util';
|
|
2
|
-
import { ISigner } from './util';
|
|
3
|
-
export type WrapperParams = {
|
|
4
|
-
author?: string;
|
|
5
|
-
wrap?: {
|
|
6
|
-
author: string;
|
|
7
|
-
recipient: string;
|
|
8
|
-
tags?: string[][];
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
export declare class Wrapper {
|
|
12
|
-
readonly userSigner: ISigner;
|
|
13
|
-
readonly wrapSigner: ISigner;
|
|
14
|
-
seen: Map<string, UnwrappedEvent | Error>;
|
|
15
|
-
constructor(userSigner: ISigner, wrapSigner: ISigner);
|
|
16
|
-
now: (drift?: number) => number;
|
|
17
|
-
getSeal: (pk: string, rumor: HashedEvent) => Promise<SignedEvent>;
|
|
18
|
-
getWrap: (pk: string, seal: SignedEvent) => Promise<SignedEvent>;
|
|
19
|
-
wrap: (pk: string, template: EventTemplate) => Promise<SignedEvent>;
|
|
20
|
-
unwrap: (wrap: SignedEvent) => Promise<any>;
|
|
21
|
-
}
|
package/build/src/wrapper.mjs
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { WRAP, SEAL } from '@welshman/util';
|
|
2
|
-
import { own, hash, decrypt } from "./util.mjs";
|
|
3
|
-
export class Wrapper {
|
|
4
|
-
constructor(userSigner, wrapSigner) {
|
|
5
|
-
this.userSigner = userSigner;
|
|
6
|
-
this.wrapSigner = wrapSigner;
|
|
7
|
-
this.seen = new Map();
|
|
8
|
-
this.now = (drift = 0) => Math.round(Date.now() / 1000 - Math.random() * Math.pow(10, drift));
|
|
9
|
-
this.getSeal = async (pk, rumor) => this.userSigner.sign(hash({
|
|
10
|
-
kind: SEAL,
|
|
11
|
-
pubkey: await this.userSigner.getPubkey(),
|
|
12
|
-
content: await this.userSigner.nip44.encrypt(pk, JSON.stringify(rumor)),
|
|
13
|
-
created_at: this.now(5),
|
|
14
|
-
tags: [],
|
|
15
|
-
}));
|
|
16
|
-
this.getWrap = async (pk, seal) => this.wrapSigner.sign(hash({
|
|
17
|
-
kind: WRAP,
|
|
18
|
-
pubkey: await this.wrapSigner.getPubkey(),
|
|
19
|
-
content: await this.wrapSigner.nip44.encrypt(pk, JSON.stringify(seal)),
|
|
20
|
-
created_at: this.now(5),
|
|
21
|
-
tags: [["p", pk]],
|
|
22
|
-
}));
|
|
23
|
-
this.wrap = async (pk, template) => {
|
|
24
|
-
const pubkey = await this.userSigner.getPubkey();
|
|
25
|
-
const rumor = hash(own(pubkey, template));
|
|
26
|
-
const seal = await this.getSeal(pk, rumor);
|
|
27
|
-
const wrap = await this.getWrap(pk, seal);
|
|
28
|
-
return wrap;
|
|
29
|
-
};
|
|
30
|
-
this.unwrap = async (wrap) => {
|
|
31
|
-
// Avoid decrypting the same event multiple times
|
|
32
|
-
if (this.seen.has(wrap.id)) {
|
|
33
|
-
const rumorOrError = this.seen.get(wrap.id);
|
|
34
|
-
if (rumorOrError instanceof Error) {
|
|
35
|
-
throw rumorOrError;
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
return rumorOrError;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
try {
|
|
42
|
-
const seal = JSON.parse(await decrypt(this.wrapSigner, wrap.pubkey, wrap.content));
|
|
43
|
-
const rumor = JSON.parse(await decrypt(this.wrapSigner, seal.pubkey, seal.content));
|
|
44
|
-
if (seal.pubkey !== rumor.pubkey)
|
|
45
|
-
throw new Error("Seal pubkey does not match rumor pubkey");
|
|
46
|
-
this.seen.set(wrap.id, rumor);
|
|
47
|
-
return rumor;
|
|
48
|
-
}
|
|
49
|
-
catch (error) {
|
|
50
|
-
this.seen.set(wrap.id, error);
|
|
51
|
-
throw error;
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
//# sourceMappingURL=wrapper.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wrapper.mjs","sourceRoot":"","sources":["../../src/wrapper.ts"],"names":[],"mappings":"OAAO,EAA0D,IAAI,EAAE,IAAI,EAAC,MAAM,gBAAgB;OAC3F,EAAC,GAAG,EAAE,IAAI,EAAE,OAAO,EAAU;AAapC,MAAM,OAAO,OAAO;IAGlB,YAAqB,UAAmB,EAAW,UAAmB;QAAjD,eAAU,GAAV,UAAU,CAAS;QAAW,eAAU,GAAV,UAAU,CAAS;QAFtE,SAAI,GAAG,IAAI,GAAG,EAAkC,CAAA;QAIhD,QAAG,GAAG,CAAC,KAAK,GAAG,CAAC,EAAE,EAAE,CAClB,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