@pomade/core 0.0.4
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/LICENSE +21 -0
- package/README.md +45 -0
- package/dist/client.d.ts +94 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +292 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/message.d.ts +255 -0
- package/dist/message.d.ts.map +1 -0
- package/dist/message.js +128 -0
- package/dist/message.js.map +1 -0
- package/dist/rpc.d.ts +75 -0
- package/dist/rpc.d.ts.map +1 -0
- package/dist/rpc.js +184 -0
- package/dist/rpc.js.map +1 -0
- package/dist/schema.d.ts +245 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +194 -0
- package/dist/schema.js.map +1 -0
- package/dist/signer.d.ts +228 -0
- package/dist/signer.d.ts.map +1 -0
- package/dist/signer.js +510 -0
- package/dist/signer.js.map +1 -0
- package/dist/storage.d.ts +21 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +21 -0
- package/dist/storage.js.map +1 -0
- package/dist/util.d.ts +55 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +103 -0
- package/dist/util.js.map +1 -0
- package/package.json +49 -0
package/dist/util.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import * as b58 from "base58-js";
|
|
2
|
+
import * as nt44 from "nostr-tools/nip44";
|
|
3
|
+
import { argon2id } from "@noble/hashes/argon2.js";
|
|
4
|
+
import { bytesToHex } from "@noble/hashes/utils.js";
|
|
5
|
+
import { cached, uniq, textEncoder, hexToBytes } from "@welshman/lib";
|
|
6
|
+
import { prep, sign, getPubkey, RELAYS, getTagValues, normalizeRelayUrl, isRelayUrl, } from "@welshman/util";
|
|
7
|
+
import { publish, request, LOCAL_RELAY_URL } from "@welshman/net";
|
|
8
|
+
// Signing and encryption
|
|
9
|
+
export const bcryptOptions = {
|
|
10
|
+
rounds: 10,
|
|
11
|
+
};
|
|
12
|
+
export function prepAndSign(secret, event) {
|
|
13
|
+
return sign(prep(event, getPubkey(secret)), secret);
|
|
14
|
+
}
|
|
15
|
+
export const nip44 = {
|
|
16
|
+
getSharedSecret: cached({
|
|
17
|
+
maxSize: 10000,
|
|
18
|
+
getKey: ([secret, pubkey]) => `${secret}:${pubkey}`,
|
|
19
|
+
getValue: ([secret, pubkey]) => nt44.v2.utils.getConversationKey(hexToBytes(secret), pubkey),
|
|
20
|
+
}),
|
|
21
|
+
encrypt: (pubkey, secret, m) => nt44.v2.encrypt(m, nip44.getSharedSecret(secret, pubkey)),
|
|
22
|
+
decrypt: (pubkey, secret, m) => nt44.v2.decrypt(m, nip44.getSharedSecret(secret, pubkey)),
|
|
23
|
+
};
|
|
24
|
+
// Challenges
|
|
25
|
+
export function encodeChallenge(peer, otp) {
|
|
26
|
+
const otpBytes = hexToBytes(otp);
|
|
27
|
+
const peerBytes = hexToBytes(peer);
|
|
28
|
+
const combined = new Uint8Array(peerBytes.length + otpBytes.length);
|
|
29
|
+
combined.set(peerBytes, 0);
|
|
30
|
+
combined.set(otpBytes, peerBytes.length);
|
|
31
|
+
return b58.binary_to_base58(combined);
|
|
32
|
+
}
|
|
33
|
+
export function decodeChallenge(challenge) {
|
|
34
|
+
const challengeBytes = b58.base58_to_binary(challenge);
|
|
35
|
+
const peer = bytesToHex(challengeBytes.slice(0, 32));
|
|
36
|
+
const otp = bytesToHex(challengeBytes.slice(32));
|
|
37
|
+
return { peer, otp };
|
|
38
|
+
}
|
|
39
|
+
// Payload hashing
|
|
40
|
+
export const argonOptions = { t: 2, m: 32 * 1024, p: 1 };
|
|
41
|
+
export async function hashEmail(email, peer) {
|
|
42
|
+
return bytesToHex(argon2id(textEncoder.encode(email), hexToBytes(peer), argonOptions));
|
|
43
|
+
}
|
|
44
|
+
export async function hashPassword(email, password, peer) {
|
|
45
|
+
return bytesToHex(argon2id(textEncoder.encode(email + password), hexToBytes(peer), argonOptions));
|
|
46
|
+
}
|
|
47
|
+
export const context = {
|
|
48
|
+
debug: false,
|
|
49
|
+
signerPubkeys: [],
|
|
50
|
+
indexerRelays: [
|
|
51
|
+
"wss://indexer.coracle.social/",
|
|
52
|
+
"wss://relay.nostr.band/",
|
|
53
|
+
"wss://purplepag.es/",
|
|
54
|
+
],
|
|
55
|
+
setSignerPubkeys(pubkeys) {
|
|
56
|
+
context.signerPubkeys = pubkeys;
|
|
57
|
+
// Prime our relay cache
|
|
58
|
+
for (const pubkey of pubkeys) {
|
|
59
|
+
fetchRelays(pubkey, AbortSignal.timeout(5000));
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
setIndexerRelays(relays) {
|
|
63
|
+
context.indexerRelays = relays.filter(isRelay).map(normalizeRelay);
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
export function debug(...args) {
|
|
67
|
+
if (context.debug) {
|
|
68
|
+
console.log(...args);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// Relays
|
|
72
|
+
export const isRelay = (url) => (url === LOCAL_RELAY_URL ? true : isRelayUrl(url));
|
|
73
|
+
export const normalizeRelay = (url) => url === LOCAL_RELAY_URL ? url : normalizeRelayUrl(url);
|
|
74
|
+
export const relayCache = new Map();
|
|
75
|
+
export const fetchRelays = async (pubkey, signal) => {
|
|
76
|
+
let relays = relayCache.get(pubkey);
|
|
77
|
+
if (!relays || relays?.length === 0) {
|
|
78
|
+
const timeout = AbortSignal.timeout(5000);
|
|
79
|
+
const [relayList] = await request({
|
|
80
|
+
autoClose: true,
|
|
81
|
+
relays: context.indexerRelays,
|
|
82
|
+
filters: [{ kinds: [RELAYS], authors: [pubkey] }],
|
|
83
|
+
signal: signal ? AbortSignal.any([signal, timeout]) : timeout,
|
|
84
|
+
});
|
|
85
|
+
relays = getTagValues("r", relayList?.tags || [])
|
|
86
|
+
.filter(isRelay)
|
|
87
|
+
.map(normalizeRelay);
|
|
88
|
+
relayCache.set(pubkey, relays);
|
|
89
|
+
}
|
|
90
|
+
return relays;
|
|
91
|
+
};
|
|
92
|
+
export function publishRelays({ secret, signal, relays, }) {
|
|
93
|
+
return publish({
|
|
94
|
+
signal,
|
|
95
|
+
relays: uniq([...relays, ...context.indexerRelays]),
|
|
96
|
+
event: prepAndSign(secret, {
|
|
97
|
+
kind: RELAYS,
|
|
98
|
+
content: "",
|
|
99
|
+
tags: relays.map(url => ["r", url]),
|
|
100
|
+
}),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=util.js.map
|
package/dist/util.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,WAAW,CAAA;AAChC,OAAO,KAAK,IAAI,MAAM,mBAAmB,CAAA;AACzC,OAAO,EAAC,QAAQ,EAAC,MAAM,yBAAyB,CAAA;AAChD,OAAO,EAAC,UAAU,EAAC,MAAM,wBAAwB,CAAA;AACjD,OAAO,EAAC,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAC,MAAM,eAAe,CAAA;AAEnE,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,MAAM,EACN,YAAY,EACZ,iBAAiB,EACjB,UAAU,GACX,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAC,OAAO,EAAE,OAAO,EAAE,eAAe,EAAC,MAAM,eAAe,CAAA;AAE/D,yBAAyB;AAEzB,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,MAAM,EAAE,EAAE;CACX,CAAA;AAED,MAAM,UAAU,WAAW,CAAC,MAAc,EAAE,KAAoB;IAC9D,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;AACrD,CAAC;AAED,MAAM,CAAC,MAAM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CAAC,MAAM,CAAC,EAAC,CAAC;YAC/C,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO;SAC9D,CAAC,CAAA;QAEF,MAAM,GAAG,YAAY,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC;aAC9C,MAAM,CAAC,OAAO,CAAC;aACf,GAAG,CAAC,cAAc,CAAC,CAAA;QAEtB,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED,MAAM,UAAU,aAAa,CAAC,EAC5B,MAAM,EACN,MAAM,EACN,MAAM,GAKP;IACC,OAAO,OAAO,CAAC;QACb,MAAM;QACN,MAAM,EAAE,IAAI,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;QACnD,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE;YACzB,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,EAAE;YACX,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;SACpC,CAAC;KACH,CAAC,CAAA;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pomade/core",
|
|
3
|
+
"version": "0.0.4",
|
|
4
|
+
"author": "hodlbod",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"description": "Recovery protocol and implementation for nostr multisig signers.",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=12.0.0"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"main": "dist/index.js",
|
|
18
|
+
"types": "dist/index.d.ts",
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/bcrypt": "^6.0.0",
|
|
21
|
+
"@typescript-eslint/eslint-plugin": "^8.49.0",
|
|
22
|
+
"@typescript-eslint/parser": "^8.49.0",
|
|
23
|
+
"eslint": "^9.39.1",
|
|
24
|
+
"eslint-config-prettier": "^10.1.8",
|
|
25
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
26
|
+
"prettier": "^3.7.4",
|
|
27
|
+
"rimraf": "~6.0.0",
|
|
28
|
+
"typescript": "^5.9.3"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@frostr/bifrost": "^1.0.7",
|
|
32
|
+
"@noble/hashes": "^2.0.1",
|
|
33
|
+
"@welshman/lib": "^0.7.1",
|
|
34
|
+
"@welshman/net": "^0.7.1",
|
|
35
|
+
"@welshman/util": "^0.7.1",
|
|
36
|
+
"base58-js": "^3.0.3",
|
|
37
|
+
"bcrypt": "^6.0.0",
|
|
38
|
+
"nostr-tools": "^2.19.3",
|
|
39
|
+
"zod": "^4.1.13"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"test": "vitest -r __tests__ --bail=1 --run",
|
|
43
|
+
"test:watch": "vitest -r __tests__ --bail=1",
|
|
44
|
+
"build": "rimraf ./dist && tsc -b --force",
|
|
45
|
+
"lint": "eslint . --ext .ts,.tsx",
|
|
46
|
+
"lint:fix": "eslint . --ext .ts,.tsx --fix",
|
|
47
|
+
"format": "prettier --write \"**/*.{ts,tsx,json,md}\""
|
|
48
|
+
}
|
|
49
|
+
}
|