@welshman/app 0.12.6 → 0.13.1
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/dist/app/src/plugins/base.d.ts +17 -23
- package/dist/app/src/plugins/base.d.ts.map +1 -1
- package/dist/app/src/plugins/base.js +23 -34
- package/dist/app/src/plugins/base.js.map +1 -1
- package/dist/app/src/plugins/plaintext.d.ts +6 -2
- package/dist/app/src/plugins/plaintext.d.ts.map +1 -1
- package/dist/app/src/plugins/plaintext.js +34 -14
- package/dist/app/src/plugins/plaintext.js.map +1 -1
- package/dist/app/src/plugins/publisher.d.ts +11 -6
- package/dist/app/src/plugins/publisher.d.ts.map +1 -1
- package/dist/app/src/plugins/publisher.js +111 -76
- package/dist/app/src/plugins/publisher.js.map +1 -1
- package/dist/app/src/plugins/wraps.d.ts +5 -1
- package/dist/app/src/plugins/wraps.d.ts.map +1 -1
- package/dist/app/src/plugins/wraps.js +6 -10
- package/dist/app/src/plugins/wraps.js.map +1 -1
- package/dist/app/src/policy.d.ts.map +1 -1
- package/dist/app/src/policy.js +4 -1
- package/dist/app/src/policy.js.map +1 -1
- package/dist/app/src/user.d.ts +2 -2
- package/dist/app/src/user.d.ts.map +1 -1
- package/dist/app/src/user.js.map +1 -1
- package/dist/domain/src/core/ListWriter.d.ts +6 -6
- package/dist/domain/src/index.d.ts +1 -0
- package/dist/domain/src/index.d.ts.map +1 -1
- package/dist/domain/src/index.js +1 -0
- package/dist/domain/src/index.js.map +1 -1
- package/dist/domain/src/kinds/Bolt12Offer.d.ts.map +1 -1
- package/dist/domain/src/kinds/Bolt12Offer.js +10 -9
- package/dist/domain/src/kinds/Bolt12Offer.js.map +1 -1
- package/dist/domain/src/kinds/Bolt12Zap.d.ts +6 -11
- package/dist/domain/src/kinds/Bolt12Zap.d.ts.map +1 -1
- package/dist/domain/src/kinds/Bolt12Zap.js +77 -105
- package/dist/domain/src/kinds/Bolt12Zap.js.map +1 -1
- package/dist/domain/src/kinds/Bolt12ZapIntent.d.ts +2 -0
- package/dist/domain/src/kinds/Bolt12ZapIntent.d.ts.map +1 -1
- package/dist/domain/src/kinds/Bolt12ZapIntent.js +31 -20
- package/dist/domain/src/kinds/Bolt12ZapIntent.js.map +1 -1
- package/dist/domain/src/kinds/RoomCreateInvite.d.ts +17 -0
- package/dist/domain/src/kinds/RoomCreateInvite.d.ts.map +1 -0
- package/dist/domain/src/kinds/RoomCreateInvite.js +36 -0
- package/dist/domain/src/kinds/RoomCreateInvite.js.map +1 -0
- package/dist/feeds/src/request.d.ts.map +1 -1
- package/dist/feeds/src/request.js +14 -5
- package/dist/feeds/src/request.js.map +1 -1
- package/dist/lib/src/TaskQueue.d.ts.map +1 -1
- package/dist/lib/src/TaskQueue.js +8 -2
- package/dist/lib/src/TaskQueue.js.map +1 -1
- package/dist/net/src/policy.d.ts.map +1 -1
- package/dist/net/src/policy.js +11 -3
- package/dist/net/src/policy.js.map +1 -1
- package/dist/net/src/repository.d.ts +18 -15
- package/dist/net/src/repository.d.ts.map +1 -1
- package/dist/net/src/repository.js +69 -78
- package/dist/net/src/repository.js.map +1 -1
- package/dist/net/src/wrapManager.d.ts +0 -2
- package/dist/net/src/wrapManager.d.ts.map +1 -1
- package/dist/net/src/wrapManager.js +8 -23
- package/dist/net/src/wrapManager.js.map +1 -1
- package/dist/signer/src/index.d.ts +1 -0
- package/dist/signer/src/index.d.ts.map +1 -1
- package/dist/signer/src/index.js +1 -0
- package/dist/signer/src/index.js.map +1 -1
- package/dist/signer/src/nip59.d.ts +13 -6
- package/dist/signer/src/nip59.d.ts.map +1 -1
- package/dist/signer/src/nip59.js +38 -19
- package/dist/signer/src/nip59.js.map +1 -1
- package/dist/signer/src/queue.d.ts +21 -0
- package/dist/signer/src/queue.d.ts.map +1 -0
- package/dist/signer/src/queue.js +40 -0
- package/dist/signer/src/queue.js.map +1 -0
- package/dist/signer/src/signers/nip01.d.ts +14 -2
- package/dist/signer/src/signers/nip01.d.ts.map +1 -1
- package/dist/signer/src/signers/nip01.js +6 -2
- package/dist/signer/src/signers/nip01.js.map +1 -1
- package/dist/signer/src/signers/nip07.d.ts +9 -9
- package/dist/signer/src/signers/nip07.d.ts.map +1 -1
- package/dist/signer/src/signers/nip07.js +15 -27
- package/dist/signer/src/signers/nip07.js.map +1 -1
- package/dist/signer/src/signers/nip46.d.ts +7 -3
- package/dist/signer/src/signers/nip46.d.ts.map +1 -1
- package/dist/signer/src/signers/nip46.js +12 -8
- package/dist/signer/src/signers/nip46.js.map +1 -1
- package/dist/signer/src/signers/nip55.d.ts +7 -7
- package/dist/signer/src/signers/nip55.d.ts.map +1 -1
- package/dist/signer/src/signers/nip55.js +33 -40
- package/dist/signer/src/signers/nip55.js.map +1 -1
- package/dist/signer/src/util.d.ts +27 -15
- package/dist/signer/src/util.d.ts.map +1 -1
- package/dist/signer/src/util.js +47 -14
- package/dist/signer/src/util.js.map +1 -1
- package/dist/store/src/repository.d.ts +5 -0
- package/dist/store/src/repository.d.ts.map +1 -1
- package/dist/store/src/repository.js +115 -96
- package/dist/store/src/repository.js.map +1 -1
- package/dist/util/src/Bolt12.d.ts.map +1 -1
- package/dist/util/src/Bolt12.js +11 -8
- package/dist/util/src/Bolt12.js.map +1 -1
- package/dist/util/src/Events.d.ts +1 -0
- package/dist/util/src/Events.d.ts.map +1 -1
- package/dist/util/src/Events.js +10 -1
- package/dist/util/src/Events.js.map +1 -1
- package/dist/util/src/Kinds.d.ts +1 -0
- package/dist/util/src/Kinds.d.ts.map +1 -1
- package/dist/util/src/Kinds.js +1 -0
- package/dist/util/src/Kinds.js.map +1 -1
- package/dist/util/src/Lightning.d.ts +1 -0
- package/dist/util/src/Lightning.d.ts.map +1 -1
- package/dist/util/src/Lightning.js +1 -0
- package/dist/util/src/Lightning.js.map +1 -1
- package/package.json +15 -15
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Emitter, remove, omit } from "@welshman/lib";
|
|
1
|
+
import { Emitter, remove, omit, pushToMapKey } from "@welshman/lib";
|
|
2
2
|
export class WrapManager extends Emitter {
|
|
3
3
|
options;
|
|
4
4
|
_wrapIndex = new Map();
|
|
@@ -63,31 +63,16 @@ export class WrapManager extends Emitter {
|
|
|
63
63
|
// Utils
|
|
64
64
|
_add = (wrapItem) => {
|
|
65
65
|
this._wrapIndex.set(wrapItem.id, wrapItem);
|
|
66
|
-
|
|
67
|
-
};
|
|
68
|
-
_addReference = (index, key, wrapId) => {
|
|
69
|
-
const reference = index.get(key);
|
|
70
|
-
if (reference) {
|
|
71
|
-
reference.push(wrapId);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
index.set(key, [wrapId]);
|
|
75
|
-
}
|
|
66
|
+
pushToMapKey(this._rumorIndex, wrapItem.rumorId, wrapItem.id);
|
|
76
67
|
};
|
|
77
68
|
_remove = (wrapItem) => {
|
|
69
|
+
const wrapIds = remove(wrapItem.id, this._rumorIndex.get(wrapItem.rumorId) || []);
|
|
78
70
|
this._wrapIndex.delete(wrapItem.id);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const wraps = remove(wrapId, reference);
|
|
85
|
-
if (wraps.length > 0) {
|
|
86
|
-
index.set(key, wraps);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
index.delete(key);
|
|
90
|
-
}
|
|
71
|
+
if (wrapIds.length > 0) {
|
|
72
|
+
this._rumorIndex.set(wrapItem.rumorId, wrapIds);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
this._rumorIndex.delete(wrapItem.rumorId);
|
|
91
76
|
}
|
|
92
77
|
};
|
|
93
78
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrapManager.js","sourceRoot":"","sources":["../../../../net/src/wrapManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAC,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"wr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ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../signer/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA"}
|
package/dist/signer/src/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../signer/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../signer/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA"}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { SignedEvent, HashedEvent, StampedEvent } from "@welshman/util";
|
|
2
|
-
import { ISigner } from "./util.js";
|
|
2
|
+
import { ISigner, SignerOptions } from "./util.js";
|
|
3
3
|
export declare const now: (drift?: number) => number;
|
|
4
|
-
export declare const getSeal: (signer: ISigner, pubkey: string, rumor: HashedEvent) => Promise<SignedEvent>;
|
|
4
|
+
export declare const getSeal: (signer: ISigner, pubkey: string, rumor: HashedEvent, options?: SignerOptions) => Promise<SignedEvent>;
|
|
5
5
|
export declare const getWrap: (wrapper: ISigner, pubkey: string, seal: SignedEvent, tags: string[][]) => Promise<SignedEvent>;
|
|
6
|
-
export declare const wrap: (signer: ISigner, wrapper: ISigner, pubkey: string, template: StampedEvent, tags?: string[][]) => Promise<SignedEvent>;
|
|
7
|
-
|
|
6
|
+
export declare const wrap: (signer: ISigner, wrapper: ISigner, pubkey: string, template: StampedEvent, tags?: string[][], options?: SignerOptions) => Promise<SignedEvent>;
|
|
7
|
+
/**
|
|
8
|
+
* A decision about the wrap itself rather than a failure to reach the signer. The wrap will
|
|
9
|
+
* read the same way every time it is tried, so a caller is free to remember the verdict;
|
|
10
|
+
* anything the signer throws is about the signer and may answer next time.
|
|
11
|
+
*/
|
|
12
|
+
export declare class InvalidWrapError extends Error {
|
|
13
|
+
}
|
|
14
|
+
export declare const unwrap: (signer: ISigner, wrap: SignedEvent, options?: SignerOptions) => Promise<HashedEvent>;
|
|
8
15
|
export declare class Nip59 {
|
|
9
16
|
private signer;
|
|
10
17
|
private wrapper?;
|
|
@@ -13,7 +20,7 @@ export declare class Nip59 {
|
|
|
13
20
|
static fromSigner: (signer: ISigner) => Nip59;
|
|
14
21
|
static fromSecret: (secret: string) => Nip59;
|
|
15
22
|
withWrapper: (wrapper: ISigner) => Nip59;
|
|
16
|
-
wrap: (pubkey: string, template: StampedEvent, tags?: string[][]) => Promise<SignedEvent>;
|
|
17
|
-
unwrap: (event: SignedEvent) => Promise<HashedEvent>;
|
|
23
|
+
wrap: (pubkey: string, template: StampedEvent, tags?: string[][], options?: SignerOptions) => Promise<SignedEvent>;
|
|
24
|
+
unwrap: (event: SignedEvent, options?: SignerOptions) => Promise<HashedEvent>;
|
|
18
25
|
}
|
|
19
26
|
//# sourceMappingURL=nip59.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nip59.d.ts","sourceRoot":"","sources":["../../../../signer/src/nip59.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"nip59.d.ts","sourceRoot":"","sources":["../../../../signer/src/nip59.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,WAAW,EACX,WAAW,EACX,YAAY,EAKb,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAU,OAAO,EAAE,aAAa,EAAC,MAAM,WAAW,CAAA;AAGzD,eAAO,MAAM,GAAG,GAAI,cAAS,WACwC,CAAA;AAErE,eAAO,MAAM,OAAO,GAClB,QAAQ,OAAO,EACf,QAAQ,MAAM,EACd,OAAO,WAAW,EAClB,UAAU,aAAa,yBAWtB,CAAA;AAEH,eAAO,MAAM,OAAO,GAClB,SAAS,OAAO,EAChB,QAAQ,MAAM,EACd,MAAM,WAAW,EACjB,MAAM,MAAM,EAAE,EAAE,yBAUf,CAAA;AAEH,eAAO,MAAM,IAAI,GACf,QAAQ,OAAO,EACf,SAAS,OAAO,EAChB,QAAQ,MAAM,EACd,UAAU,YAAY,EACtB,OAAM,MAAM,EAAE,EAAO,EACrB,UAAU,aAAa,yBAQxB,CAAA;AAED;;;;GAIG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;CAAG;AAa9C,eAAO,MAAM,MAAM,GACjB,QAAQ,OAAO,EACf,MAAM,WAAW,EACjB,UAAU,aAAa,KACtB,OAAO,CAAC,WAAW,CAWrB,CAAA;AAED,qBAAa,KAAK;IAId,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,OAAO,CAAC;IAJlB,OAAO,CAAC,KAAK,CAAoD;gBAGvD,MAAM,EAAE,OAAO,EACf,OAAO,CAAC,EAAE,OAAO,YAAA;IAG3B,MAAM,CAAC,UAAU,GAAI,QAAQ,OAAO,WAAsB;IAE1D,MAAM,CAAC,UAAU,GAAI,QAAQ,MAAM,WAAuC;IAE1E,WAAW,GAAI,SAAS,OAAO,WAAoC;IAEnE,IAAI,GAAI,QAAQ,MAAM,EAAE,UAAU,YAAY,EAAE,OAAM,MAAM,EAAE,EAAO,EAAE,UAAU,aAAa,0BACD;IAE7F,MAAM,GAAU,OAAO,WAAW,EAAE,UAAU,aAAa,KAAG,OAAO,CAAC,WAAW,CAAC,CAwBjF;CACF"}
|
package/dist/signer/src/nip59.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { isHashedEvent, WRAP, SEAL, prep, hash, } from "@welshman/util";
|
|
1
|
+
import { isHashedEvent, isSignedEvent, WRAP, SEAL, prep, hash, } from "@welshman/util";
|
|
2
|
+
import { isPojo, tryCatch } from "@welshman/lib";
|
|
2
3
|
import { decrypt } from "./util.js";
|
|
3
4
|
import { Nip01Signer } from "./signers/nip01.js";
|
|
4
5
|
export const now = (drift = 0) => Math.round(Date.now() / 1000 - Math.random() * Math.pow(10, drift));
|
|
5
|
-
export const getSeal = async (signer, pubkey, rumor) => signer.sign(hash({
|
|
6
|
+
export const getSeal = async (signer, pubkey, rumor, options) => signer.sign(hash({
|
|
6
7
|
kind: SEAL,
|
|
7
|
-
pubkey: await signer.getPubkey(),
|
|
8
|
-
content: await signer.nip44.encrypt(pubkey, JSON.stringify(rumor)),
|
|
8
|
+
pubkey: await signer.getPubkey(options),
|
|
9
|
+
content: await signer.nip44.encrypt(pubkey, JSON.stringify(rumor), options),
|
|
9
10
|
created_at: now(5),
|
|
10
11
|
tags: [],
|
|
11
|
-
}));
|
|
12
|
+
}), options);
|
|
12
13
|
export const getWrap = async (wrapper, pubkey, seal, tags) => wrapper.sign(hash({
|
|
13
14
|
kind: WRAP,
|
|
14
15
|
pubkey: await wrapper.getPubkey(),
|
|
@@ -16,20 +17,36 @@ export const getWrap = async (wrapper, pubkey, seal, tags) => wrapper.sign(hash(
|
|
|
16
17
|
created_at: now(5),
|
|
17
18
|
tags: [...tags, ["p", pubkey]],
|
|
18
19
|
}));
|
|
19
|
-
export const wrap = async (signer, wrapper, pubkey, template, tags = []) => {
|
|
20
|
-
const author = await signer.getPubkey();
|
|
20
|
+
export const wrap = async (signer, wrapper, pubkey, template, tags = [], options) => {
|
|
21
|
+
const author = await signer.getPubkey(options);
|
|
21
22
|
const rumor = await prep(template, author);
|
|
22
|
-
const seal = await getSeal(signer, pubkey, rumor);
|
|
23
|
+
const seal = await getSeal(signer, pubkey, rumor, options);
|
|
23
24
|
const wrap = await getWrap(wrapper, pubkey, seal, tags);
|
|
24
25
|
return wrap;
|
|
25
26
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
/**
|
|
28
|
+
* A decision about the wrap itself rather than a failure to reach the signer. The wrap will
|
|
29
|
+
* read the same way every time it is tried, so a caller is free to remember the verdict;
|
|
30
|
+
* anything the signer throws is about the signer and may answer next time.
|
|
31
|
+
*/
|
|
32
|
+
export class InvalidWrapError extends Error {
|
|
33
|
+
}
|
|
34
|
+
// Each layer must decrypt to the event that layer carries, or the wrap is malformed
|
|
35
|
+
const parseLayer = (json, isLayer, layer) => {
|
|
36
|
+
const value = tryCatch(() => JSON.parse(json));
|
|
37
|
+
if (!isPojo(value) || !isLayer(value)) {
|
|
38
|
+
throw new InvalidWrapError(`Decrypted ${layer} was not a valid event`);
|
|
39
|
+
}
|
|
40
|
+
return value;
|
|
41
|
+
};
|
|
42
|
+
export const unwrap = async (signer, wrap, options) => {
|
|
43
|
+
const sealJson = await decrypt(signer, wrap.pubkey, wrap.content, options);
|
|
44
|
+
const seal = parseLayer(sealJson, isSignedEvent, "seal");
|
|
45
|
+
const rumorJson = await decrypt(signer, seal.pubkey, seal.content, options);
|
|
46
|
+
const rumor = parseLayer(rumorJson, isHashedEvent, "rumor");
|
|
47
|
+
if (seal.pubkey !== rumor.pubkey) {
|
|
48
|
+
throw new InvalidWrapError("Seal pubkey does not match rumor pubkey");
|
|
49
|
+
}
|
|
33
50
|
return rumor;
|
|
34
51
|
};
|
|
35
52
|
export class Nip59 {
|
|
@@ -43,8 +60,8 @@ export class Nip59 {
|
|
|
43
60
|
static fromSigner = (signer) => new Nip59(signer);
|
|
44
61
|
static fromSecret = (secret) => new Nip59(new Nip01Signer(secret));
|
|
45
62
|
withWrapper = (wrapper) => new Nip59(this.signer, wrapper);
|
|
46
|
-
wrap = (pubkey, template, tags = []) => wrap(this.signer, this.wrapper || Nip01Signer.ephemeral(), pubkey, template, tags);
|
|
47
|
-
unwrap = async (event) => {
|
|
63
|
+
wrap = (pubkey, template, tags = [], options) => wrap(this.signer, this.wrapper || Nip01Signer.ephemeral(), pubkey, template, tags, options);
|
|
64
|
+
unwrap = async (event, options) => {
|
|
48
65
|
const cached = this.cache.get(event.id);
|
|
49
66
|
if (cached) {
|
|
50
67
|
if (cached instanceof Error) {
|
|
@@ -53,12 +70,14 @@ export class Nip59 {
|
|
|
53
70
|
return cached;
|
|
54
71
|
}
|
|
55
72
|
try {
|
|
56
|
-
const rumor = await unwrap(this.signer, event);
|
|
73
|
+
const rumor = await unwrap(this.signer, event, options);
|
|
57
74
|
this.cache.set(event.id, rumor);
|
|
58
75
|
return rumor;
|
|
59
76
|
}
|
|
60
77
|
catch (error) {
|
|
61
|
-
|
|
78
|
+
if (error instanceof InvalidWrapError) {
|
|
79
|
+
this.cache.set(event.id, error);
|
|
80
|
+
}
|
|
62
81
|
throw error;
|
|
63
82
|
}
|
|
64
83
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nip59.js","sourceRoot":"","sources":["../../../../signer/src/nip59.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAIb,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,IAAI,GACL,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"nip59.js","sourceRoot":"","sources":["../../../../signer/src/nip59.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,aAAa,EAIb,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,IAAI,GACL,M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Q,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;IAE7F,MAAM,GAAG,KAAK,EAAE,KAAkB,EAAE,OAAuB,EAAwB,EAAE;QACnF,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAEvC,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,MAAM,YAAY,KAAK,EAAE,CAAC;gBAC5B,MAAM,MAAM,CAAA;YACd,CAAC;YAED,OAAO,MAAM,CAAA;QACf,CAAC;QAED,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,CAAA;YAEvD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,CAAA;YAE/B,OAAO,KAAK,CAAA;QACd,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,gBAAgB,EAAE,CAAC;gBACtC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,CAAA;YACjC,CAAC;YAED,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TaskQueue } from "@welshman/lib";
|
|
2
|
+
import type { SignerOptions } from "./util.js";
|
|
3
|
+
export type SignerRequest = {
|
|
4
|
+
priority: number;
|
|
5
|
+
run: () => Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* The lane every request to one signer goes down. A browser extension and a native signer
|
|
9
|
+
* app each answer one request at a time, so a caller is already queueing; making the queue
|
|
10
|
+
* explicit is what lets a signature the user is waiting on overtake a backlog of
|
|
11
|
+
* decryptions, and what keeps one request that never answers from blocking the rest.
|
|
12
|
+
*
|
|
13
|
+
* `batchSize` is 1, since a batch is fixed once it starts and a request arriving mid-batch
|
|
14
|
+
* would otherwise wait out the whole of it however urgent it is. A `batchDelay` of 0 then
|
|
15
|
+
* costs no timer per request, since `TaskQueue` drains a zero delay in a microtask.
|
|
16
|
+
*/
|
|
17
|
+
export declare class SignerQueue {
|
|
18
|
+
queue: TaskQueue<SignerRequest>;
|
|
19
|
+
push: <T>(thunk: () => Promise<T>, options?: SignerOptions) => Promise<T>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../../../../signer/src/queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAc,MAAM,eAAe,CAAA;AAEpD,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,WAAW,CAAA;AAE5C,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CACzB,CAAA;AAED;;;;;;;;;GASG;AACH,qBAAa,WAAW;IACtB,KAAK,2BAKH;IAEF,IAAI,GAAI,CAAC,EAAE,OAAO,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,UAAS,aAAkB,KAAG,OAAO,CAAC,CAAC,CAAC,CAsB3E;CACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { TaskQueue, defer, noop } from "@welshman/lib";
|
|
2
|
+
import { signerCall } from "./util.js";
|
|
3
|
+
/**
|
|
4
|
+
* The lane every request to one signer goes down. A browser extension and a native signer
|
|
5
|
+
* app each answer one request at a time, so a caller is already queueing; making the queue
|
|
6
|
+
* explicit is what lets a signature the user is waiting on overtake a backlog of
|
|
7
|
+
* decryptions, and what keeps one request that never answers from blocking the rest.
|
|
8
|
+
*
|
|
9
|
+
* `batchSize` is 1, since a batch is fixed once it starts and a request arriving mid-batch
|
|
10
|
+
* would otherwise wait out the whole of it however urgent it is. A `batchDelay` of 0 then
|
|
11
|
+
* costs no timer per request, since `TaskQueue` drains a zero delay in a microtask.
|
|
12
|
+
*/
|
|
13
|
+
export class SignerQueue {
|
|
14
|
+
queue = new TaskQueue({
|
|
15
|
+
batchSize: 1,
|
|
16
|
+
batchDelay: 0,
|
|
17
|
+
getPriority: (request) => request.priority,
|
|
18
|
+
processItem: (request) => request.run(),
|
|
19
|
+
});
|
|
20
|
+
push = (thunk, options = {}) => {
|
|
21
|
+
const result = defer();
|
|
22
|
+
const settled = result.then(noop, noop);
|
|
23
|
+
const abort = () => result.reject(new Error("Signer request was aborted"));
|
|
24
|
+
// A signal that is already aborted never fires "abort", so refuse the request here.
|
|
25
|
+
if (options.signal?.aborted)
|
|
26
|
+
abort();
|
|
27
|
+
options.signal?.addEventListener("abort", abort);
|
|
28
|
+
settled.then(() => options.signal?.removeEventListener("abort", abort));
|
|
29
|
+
this.queue.push({
|
|
30
|
+
priority: options.priority ?? 0,
|
|
31
|
+
run: () => {
|
|
32
|
+
signerCall(thunk, options).then(result.resolve, result.reject);
|
|
33
|
+
// The lane is given back when welshman stops waiting, not always when the signer answered
|
|
34
|
+
return settled;
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../../../../signer/src/queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,KAAK,EAAE,IAAI,EAAC,MAAM,eAAe,CAAA;AACpD,OAAO,EAAC,UAAU,EAAC,MAAM,WAAW,CAAA;AAQpC;;;;;;;;;GASG;AACH,MAAM,OAAO,WAAW;IACtB,KAAK,GAAG,IAAI,SAAS,CAAgB;QACnC,SAAS,EAAE,CAAC;QACZ,UAAU,EAAE,CAAC;QACb,WAAW,EAAE,CAAC,OAAsB,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ;QACzD,WAAW,EAAE,CAAC,OAAsB,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE;KACvD,CAAC,CAAA;IAEF,IAAI,GAAG,CAAI,KAAuB,EAAE,UAAyB,EAAE,EAAc,EAAE;QAC7E,MAAM,MAAM,GAAG,KAAK,EAAY,CAAA;QAChC,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QACvC,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC,CAAA;QAE1E,oFAAoF;QACpF,IAAI,OAAO,CAAC,MAAM,EAAE,OAAO;YAAE,KAAK,EAAE,CAAA;QAEpC,OAAO,CAAC,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;QAChD,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAA;QAEvE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;YACd,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,CAAC;YAC/B,GAAG,EAAE,GAAG,EAAE;gBACR,UAAU,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;gBAE9D,0FAA0F;gBAC1F,OAAO,OAAO,CAAA;YAChB,CAAC;SACF,CAAC,CAAA;QAEF,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;CACF"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { StampedEvent } from "@welshman/util";
|
|
2
|
-
import { ISigner
|
|
2
|
+
import { ISigner } from "../util.js";
|
|
3
|
+
/**
|
|
4
|
+
* A local key, so every request is answered synchronously. Nothing here can hang or be
|
|
5
|
+
* worth reordering, which is why it takes no `SignerOptions`.
|
|
6
|
+
*/
|
|
3
7
|
export declare class Nip01Signer implements ISigner {
|
|
4
8
|
#private;
|
|
5
9
|
private secret;
|
|
@@ -7,7 +11,15 @@ export declare class Nip01Signer implements ISigner {
|
|
|
7
11
|
static fromSecret: (secret: string) => Nip01Signer;
|
|
8
12
|
static ephemeral: () => Nip01Signer;
|
|
9
13
|
getPubkey: () => Promise<string>;
|
|
10
|
-
sign: (event: StampedEvent
|
|
14
|
+
sign: (event: StampedEvent) => Promise<{
|
|
15
|
+
sig: string;
|
|
16
|
+
tags: string[][];
|
|
17
|
+
content: string;
|
|
18
|
+
kind: number;
|
|
19
|
+
created_at: number;
|
|
20
|
+
pubkey: string;
|
|
21
|
+
id: string;
|
|
22
|
+
}>;
|
|
11
23
|
nip04: {
|
|
12
24
|
encrypt: (pubkey: string, message: string) => Promise<string>;
|
|
13
25
|
decrypt: (pubkey: string, message: string) => Promise<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nip01.d.ts","sourceRoot":"","sources":["../../../../../signer/src/signers/nip01.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAyC,MAAM,gBAAgB,CAAA;AACnF,OAAO,EAAe,OAAO,
|
|
1
|
+
{"version":3,"file":"nip01.d.ts","sourceRoot":"","sources":["../../../../../signer/src/signers/nip01.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAyC,MAAM,gBAAgB,CAAA;AACnF,OAAO,EAAe,OAAO,EAAC,MAAM,YAAY,CAAA;AAEhD;;;GAGG;AACH,qBAAa,WAAY,YAAW,OAAO;;IAG7B,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAIlC,MAAM,CAAC,UAAU,GAAI,QAAQ,MAAM,iBAA4B;IAE/D,MAAM,CAAC,SAAS,oBAAsC;IAEtD,SAAS,wBAA2B;IAEpC,IAAI,GAAU,OAAO,YAAY;;;;;;;;OAAsD;IAEvF,KAAK;0BACqB,MAAM,WAAW,MAAM;0BACvB,MAAM,WAAW,MAAM;MAChD;IAED,KAAK;0BACqB,MAAM,WAAW,MAAM;0BACvB,MAAM,WAAW,MAAM;MAChD;CACF"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { own, hash, sign, getPubkey, makeSecret } from "@welshman/util";
|
|
2
|
-
import { nip04, nip44
|
|
2
|
+
import { nip04, nip44 } from "../util.js";
|
|
3
|
+
/**
|
|
4
|
+
* A local key, so every request is answered synchronously. Nothing here can hang or be
|
|
5
|
+
* worth reordering, which is why it takes no `SignerOptions`.
|
|
6
|
+
*/
|
|
3
7
|
export class Nip01Signer {
|
|
4
8
|
secret;
|
|
5
9
|
#pubkey;
|
|
@@ -10,7 +14,7 @@ export class Nip01Signer {
|
|
|
10
14
|
static fromSecret = (secret) => new Nip01Signer(secret);
|
|
11
15
|
static ephemeral = () => new Nip01Signer(makeSecret());
|
|
12
16
|
getPubkey = async () => this.#pubkey;
|
|
13
|
-
sign = (event
|
|
17
|
+
sign = async (event) => sign(hash(own(event, this.#pubkey)), this.secret);
|
|
14
18
|
nip04 = {
|
|
15
19
|
encrypt: async (pubkey, message) => nip04.encrypt(pubkey, this.secret, message),
|
|
16
20
|
decrypt: async (pubkey, message) => nip04.decrypt(pubkey, this.secret, message),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nip01.js","sourceRoot":"","sources":["../../../../../signer/src/signers/nip01.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAC,MAAM,gBAAgB,CAAA;AACnF,OAAO,EAAC,KAAK,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"nip01.js","sourceRoot":"","sources":["../../../../../signer/src/signers/nip01.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAC,MAAM,gBAAgB,CAAA;AACnF,OAAO,EAAC,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IAAI,CAAC,MAAM,EAAE,OAAO,CAAC;KAChG,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { StampedEvent } from "@welshman/util";
|
|
2
|
-
import {
|
|
1
|
+
import { SignedEvent, StampedEvent } from "@welshman/util";
|
|
2
|
+
import { SignerOptions, ISigner, EncryptionImplementation } from "../util.js";
|
|
3
3
|
export type Nip07 = {
|
|
4
|
-
signEvent:
|
|
4
|
+
signEvent: (event: StampedEvent) => Promise<SignedEvent>;
|
|
5
5
|
nip04: EncryptionImplementation;
|
|
6
6
|
nip44: EncryptionImplementation;
|
|
7
7
|
getPublicKey: () => string | undefined;
|
|
@@ -9,15 +9,15 @@ export type Nip07 = {
|
|
|
9
9
|
export declare const getNip07: () => Nip07 | undefined;
|
|
10
10
|
export declare class Nip07Signer implements ISigner {
|
|
11
11
|
#private;
|
|
12
|
-
getPubkey: () => Promise<string>;
|
|
13
|
-
sign: (template: StampedEvent, options?:
|
|
12
|
+
getPubkey: (options?: SignerOptions) => Promise<string>;
|
|
13
|
+
sign: (template: StampedEvent, options?: SignerOptions) => Promise<SignedEvent>;
|
|
14
14
|
nip04: {
|
|
15
|
-
encrypt: (pubkey: string, message: string) => Promise<string>;
|
|
16
|
-
decrypt: (pubkey: string, message: string) => Promise<string>;
|
|
15
|
+
encrypt: (pubkey: string, message: string, options?: SignerOptions) => Promise<string>;
|
|
16
|
+
decrypt: (pubkey: string, message: string, options?: SignerOptions) => Promise<string>;
|
|
17
17
|
};
|
|
18
18
|
nip44: {
|
|
19
|
-
encrypt: (pubkey: string, message: string) => Promise<string>;
|
|
20
|
-
decrypt: (pubkey: string, message: string) => Promise<string>;
|
|
19
|
+
encrypt: (pubkey: string, message: string, options?: SignerOptions) => Promise<string>;
|
|
20
|
+
decrypt: (pubkey: string, message: string, options?: SignerOptions) => Promise<string>;
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
//# sourceMappingURL=nip07.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nip07.d.ts","sourceRoot":"","sources":["../../../../../signer/src/signers/nip07.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"nip07.d.ts","sourceRoot":"","sources":["../../../../../signer/src/signers/nip07.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,YAAY,EAAC,MAAM,gBAAgB,CAAA;AAExD,OAAO,EAAC,aAAa,EAAE,OAAO,EAAE,wBAAwB,EAAC,MAAM,YAAY,CAAA;AAE3E,MAAM,MAAM,KAAK,GAAG;IAClB,SAAS,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,WAAW,CAAC,CAAA;IACxD,KAAK,EAAE,wBAAwB,CAAA;IAC/B,KAAK,EAAE,wBAAwB,CAAA;IAC/B,YAAY,EAAE,MAAM,MAAM,GAAG,SAAS,CAAA;CACvC,CAAA;AAED,eAAO,MAAM,QAAQ,yBAA0C,CAAA;AAE/D,qBAAa,WAAY,YAAW,OAAO;;IAazC,SAAS,GAAI,UAAS,aAAkB,qBASvC;IAED,IAAI,GAAI,UAAU,YAAY,EAAE,UAAS,aAAkB,0BACN;IAErD,KAAK;0BACe,MAAM,WAAW,MAAM,YAAW,aAAa;0BAE/C,MAAM,WAAW,MAAM,YAAW,aAAa;MAElE;IAED,KAAK;0BACe,MAAM,WAAW,MAAM,YAAW,aAAa;0BAE/C,MAAM,WAAW,MAAM,YAAW,aAAa;MAElE;CACF"}
|
|
@@ -1,43 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { signWithOptions } from "../util.js";
|
|
1
|
+
import { SignerQueue } from "../queue.js";
|
|
3
2
|
export const getNip07 = () => window.nostr;
|
|
4
|
-
const release = (promise) => new Promise(resolve => {
|
|
5
|
-
const timeout = setTimeout(resolve, 30_000);
|
|
6
|
-
promise.catch(noop).then(() => {
|
|
7
|
-
clearTimeout(timeout);
|
|
8
|
-
resolve();
|
|
9
|
-
});
|
|
10
|
-
});
|
|
11
3
|
export class Nip07Signer {
|
|
12
|
-
#
|
|
4
|
+
#queue = new SignerQueue();
|
|
13
5
|
#pubkey;
|
|
14
|
-
#then = async (
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
this.#lock = release(promise);
|
|
22
|
-
return promise;
|
|
23
|
-
};
|
|
24
|
-
getPubkey = () => {
|
|
6
|
+
#then = (f, options) => this.#queue.push(async () => {
|
|
7
|
+
const ext = getNip07();
|
|
8
|
+
if (!ext)
|
|
9
|
+
throw new Error("Nip07 is not enabled");
|
|
10
|
+
return f(ext);
|
|
11
|
+
}, options);
|
|
12
|
+
getPubkey = (options = {}) => {
|
|
25
13
|
if (!this.#pubkey) {
|
|
26
|
-
this.#pubkey = this.#then(ext => ext.getPublicKey());
|
|
14
|
+
this.#pubkey = this.#then(ext => ext.getPublicKey(), options);
|
|
27
15
|
this.#pubkey.catch(() => {
|
|
28
16
|
this.#pubkey = undefined;
|
|
29
17
|
});
|
|
30
18
|
}
|
|
31
19
|
return this.#pubkey;
|
|
32
20
|
};
|
|
33
|
-
sign = (template, options = {}) =>
|
|
21
|
+
sign = (template, options = {}) => this.#then(ext => ext.signEvent(template), options);
|
|
34
22
|
nip04 = {
|
|
35
|
-
encrypt: (pubkey, message) => this.#then(ext => ext.nip04.encrypt(pubkey, message)),
|
|
36
|
-
decrypt: (pubkey, message) => this.#then(ext => ext.nip04.decrypt(pubkey, message)),
|
|
23
|
+
encrypt: (pubkey, message, options = {}) => this.#then(ext => ext.nip04.encrypt(pubkey, message), options),
|
|
24
|
+
decrypt: (pubkey, message, options = {}) => this.#then(ext => ext.nip04.decrypt(pubkey, message), options),
|
|
37
25
|
};
|
|
38
26
|
nip44 = {
|
|
39
|
-
encrypt: (pubkey, message) => this.#then(ext => ext.nip44.encrypt(pubkey, message)),
|
|
40
|
-
decrypt: (pubkey, message) => this.#then(ext => ext.nip44.decrypt(pubkey, message)),
|
|
27
|
+
encrypt: (pubkey, message, options = {}) => this.#then(ext => ext.nip44.encrypt(pubkey, message), options),
|
|
28
|
+
decrypt: (pubkey, message, options = {}) => this.#then(ext => ext.nip44.decrypt(pubkey, message), options),
|
|
41
29
|
};
|
|
42
30
|
}
|
|
43
31
|
//# sourceMappingURL=nip07.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nip07.js","sourceRoot":"","sources":["../../../../../signer/src/signers/nip07.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"nip07.js","sourceRoot":"","sources":["../../../../../signer/src/signers/nip07.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,WAAW,EAAC,MAAM,aAAa,CAAA;AAUvC,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG,EAAE,CAAE,MAA0B,CAAC,KAAK,CAAA;AAE/D,MAAM,OAAO,WAAW;IACtB,MAAM,GAAG,IAAI,WAAW,EAAE,CAAA;IAC1B,OAAO,CAAkB;IAEzB,KAAK,GAAG,CAAI,CAAiC,EAAE,OAAsB,EAAE,EAAE,CACvE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE;QAC1B,MAAM,GAAG,GAAG,QAAQ,EAAE,CAAA;QAEtB,IAAI,CAAC,GAAG;YAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;QAEjD,OAAO,CAAC,CAAC,GAAG,CAAC,CAAA;IACf,CAAC,EAAE,OAAO,CAAC,CAAA;IAEb,SAAS,GAAG,CAAC,UAAyB,EAAE,EAAE,EAAE;QAC1C,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,CAAS,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,YAAY,EAAY,EAAE,OAAO,CAAC,CAAA;YAC/E,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE;gBACtB,IAAI,CAAC,OAAO,GAA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man/lib";
|
|
2
2
|
import { HashedEvent, StampedEvent, TrustedEvent } from "@welshman/util";
|
|
3
3
|
import { AdapterContext } from "@welshman/net";
|
|
4
|
-
import { ISigner, EncryptionImplementation,
|
|
4
|
+
import { ISigner, EncryptionImplementation, SignerOptions } from "../util.js";
|
|
5
5
|
import { Nip01Signer } from "./nip01.js";
|
|
6
6
|
export type Nip46Context = {
|
|
7
7
|
debug: boolean;
|
|
@@ -116,14 +116,18 @@ export declare class Nip46Broker extends Emitter {
|
|
|
116
116
|
nip44Decrypt: (pk: string, message: string) => Promise<string>;
|
|
117
117
|
switchRelays: () => Promise<string[]>;
|
|
118
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* A bunker answers over relays rather than one at a time, so requests here are not queued
|
|
121
|
+
* and a priority would order nothing. Each one still carries its own deadline.
|
|
122
|
+
*/
|
|
119
123
|
export declare class Nip46Signer implements ISigner {
|
|
120
124
|
broker: Nip46Broker;
|
|
121
125
|
pubkey?: string;
|
|
122
126
|
nip04: EncryptionImplementation;
|
|
123
127
|
nip44: EncryptionImplementation;
|
|
124
128
|
constructor(broker: Nip46Broker);
|
|
125
|
-
getPubkey: () => Promise<string>;
|
|
126
|
-
sign: (template: StampedEvent, options?:
|
|
129
|
+
getPubkey: (options?: SignerOptions) => Promise<string>;
|
|
130
|
+
sign: (template: StampedEvent, options?: SignerOptions) => Promise<any>;
|
|
127
131
|
cleanup: () => Promise<void>;
|
|
128
132
|
}
|
|
129
133
|
//# sourceMappingURL=nip46.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nip46.d.ts","sourceRoot":"","sources":["../../../../../signer/src/signers/nip46.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAQP,UAAU,EAGX,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,WAAW,EAMX,YAAY,EACZ,YAAY,EACb,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAGL,cAAc,EAIf,MAAM,eAAe,CAAA;AACt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,qBACD;IAE5D,OAAO,GAAU,sBAAkB,EAAE,cAAU,qBAU9C;IAED,SAAS,GAAU,OAAO,YAAY,kBAC8B;IAEpE,YAAY,GAAI,IAAI,MAAM,EAAE,SAAS,MAAM,qBAA8C;IAEzF,YAAY,GAAI,IAAI,MAAM,EAAE,SAAS,MAAM,qBAA8C;IAEzF,YAAY,GAAI,IAAI,MAAM,EAAE,SAAS,MAAM,qBAA8C;IAEzF,YAAY,GAAI,IAAI,MAAM,EAAE,SAAS,MAAM,qBAA8C;IAGzF,YAAY,0BAsBX;CACF;AAED;;;GAGG;AACH,qBAAa,WAAY,YAAW,OAAO;IAKtB,MAAM,EAAE,WAAW;IAJtC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,wBAAwB,CAAA;IAC/B,KAAK,EAAE,wBAAwB,CAAA;gBAEZ,MAAM,EAAE,WAAW;IAgBtC,SAAS,GAAU,UAAU,aAAa,qBAMzC;IAED,IAAI,GAAI,UAAU,YAAY,EAAE,UAAS,aAAkB,kBAIxD;IAEH,OAAO,sBAAoC;CAC5C"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Emitter, throttle, makePromise, defer, memoize, sleep, tryCatch, randomId, parseJson, isHex32, } from "@welshman/lib";
|
|
2
2
|
import { makeEvent, makeSecret, normalizeRelayUrl, NOSTR_CONNECT, prep, } from "@welshman/util";
|
|
3
3
|
import { publish, request, Pool, socketPolicyConnectOnSend, socketPolicyLifecycle, } from "@welshman/net";
|
|
4
|
-
import {
|
|
4
|
+
import { signerCall, decrypt } from "../util.js";
|
|
5
5
|
import { Nip01Signer } from "./nip01.js";
|
|
6
6
|
export const nip46Context = {
|
|
7
7
|
debug: false,
|
|
@@ -370,6 +370,10 @@ export class Nip46Broker extends Emitter {
|
|
|
370
370
|
return this.params.relays;
|
|
371
371
|
};
|
|
372
372
|
}
|
|
373
|
+
/**
|
|
374
|
+
* A bunker answers over relays rather than one at a time, so requests here are not queued
|
|
375
|
+
* and a priority would order nothing. Each one still carries its own deadline.
|
|
376
|
+
*/
|
|
373
377
|
export class Nip46Signer {
|
|
374
378
|
broker;
|
|
375
379
|
pubkey;
|
|
@@ -378,21 +382,21 @@ export class Nip46Signer {
|
|
|
378
382
|
constructor(broker) {
|
|
379
383
|
this.broker = broker;
|
|
380
384
|
this.nip04 = {
|
|
381
|
-
encrypt: this.broker.nip04Encrypt,
|
|
382
|
-
decrypt: this.broker.nip04Decrypt,
|
|
385
|
+
encrypt: (pubkey, message, options) => signerCall(() => this.broker.nip04Encrypt(pubkey, message), options),
|
|
386
|
+
decrypt: (pubkey, message, options) => signerCall(() => this.broker.nip04Decrypt(pubkey, message), options),
|
|
383
387
|
};
|
|
384
388
|
this.nip44 = {
|
|
385
|
-
encrypt: this.broker.nip44Encrypt,
|
|
386
|
-
decrypt: this.broker.nip44Decrypt,
|
|
389
|
+
encrypt: (pubkey, message, options) => signerCall(() => this.broker.nip44Encrypt(pubkey, message), options),
|
|
390
|
+
decrypt: (pubkey, message, options) => signerCall(() => this.broker.nip44Decrypt(pubkey, message), options),
|
|
387
391
|
};
|
|
388
392
|
}
|
|
389
|
-
getPubkey = async () => {
|
|
393
|
+
getPubkey = async (options) => {
|
|
390
394
|
if (!this.pubkey) {
|
|
391
|
-
this.pubkey = await this.broker.getPublicKey();
|
|
395
|
+
this.pubkey = await signerCall(() => this.broker.getPublicKey(), options);
|
|
392
396
|
}
|
|
393
397
|
return this.pubkey;
|
|
394
398
|
};
|
|
395
|
-
sign = (template, options = {}) =>
|
|
399
|
+
sign = (template, options = {}) => signerCall(() => this.getPubkey(options).then(pubkey => this.broker.signEvent(prep(template, pubkey))), options);
|
|
396
400
|
cleanup = async () => this.broker.cleanup();
|
|
397
401
|
}
|
|
398
402
|
//# sourceMappingURL=nip46.js.map
|