Merge branch 'upgrade-nostr-tools' into 'develop'
Upgrade nostr-tools, simplify powPolicy See merge request soapbox-pub/strfry-policies!8
This commit is contained in:
commit
fc690bd44c
78
deno.lock
78
deno.lock
@ -177,49 +177,39 @@
|
|||||||
"https://deno.land/x/sqlite@v2.3.2/src/row_objects.ts": "cf7ad165bb14c0fd346c46a7f3ea08043ace747d1abae3787bbe4b36be11b09c",
|
"https://deno.land/x/sqlite@v2.3.2/src/row_objects.ts": "cf7ad165bb14c0fd346c46a7f3ea08043ace747d1abae3787bbe4b36be11b09c",
|
||||||
"https://deno.land/x/sqlite@v2.3.2/src/rows.ts": "1b05730096f8df626bfc9d1597a776cc5ac7d989910a20711fa28c7a8daebb0e",
|
"https://deno.land/x/sqlite@v2.3.2/src/rows.ts": "1b05730096f8df626bfc9d1597a776cc5ac7d989910a20711fa28c7a8daebb0e",
|
||||||
"https://deno.land/x/sqlite@v2.3.2/src/wasm.ts": "9747b8c4de5542f2359a35461317f08a244fe8a0933c7e279caad27a0190e6bf",
|
"https://deno.land/x/sqlite@v2.3.2/src/wasm.ts": "9747b8c4de5542f2359a35461317f08a244fe8a0933c7e279caad27a0190e6bf",
|
||||||
"https://esm.sh/v113/@noble/curves@0.8.3/deno/abstract/modular.js": "d91c510811b267efedd3bdefd8b73413359aef5bce4448a6fc766feb5b90aa23",
|
"https://esm.sh/v114/@noble/hashes@1.2.0/deno/_assert.js": "4ae82ea34135ea09f5f727201f345d5c1c2999cee74a7169e1f7954409c22fc3",
|
||||||
"https://esm.sh/v113/@noble/curves@0.8.3/deno/secp256k1.js": "20f0e8991377f43483c2d20c0933444954db1c5608c48118282d9d0698f1c31d",
|
"https://esm.sh/v114/@noble/hashes@1.2.0/deno/crypto.js": "62e1119c9426fbf642bad03c7b934768c7c6de757c8a3d263f5c46f63b9c51c5",
|
||||||
"https://esm.sh/v113/@noble/hashes@1.3.0/deno/_assert.js": "72a2c390121ef64189358442e9c762a8254ad26a1067f094f19b993c2ee0410f",
|
"https://esm.sh/v114/@noble/hashes@1.2.0/deno/hmac.js": "5f10dadb16e809c7533f592b038b05cf2895bc471406a47e5088fccf13615e76",
|
||||||
"https://esm.sh/v113/@noble/hashes@1.3.0/deno/crypto.js": "5155cc032738707f4a4e27e2743be57bdddd21d2462837c328adba2cb190755c",
|
"https://esm.sh/v114/@noble/hashes@1.2.0/deno/pbkdf2.js": "8a47e018fe56ad64cd488ae20558f8a0fc32dbb34bb642365fc10a38d642f733",
|
||||||
"https://esm.sh/v113/@noble/hashes@1.3.0/deno/hmac.js": "5ee68684fd06b98bb07039b5a0b3d3f32c2a82638a2fe8b1dbdc0860ab77303e",
|
"https://esm.sh/v114/@noble/hashes@1.2.0/deno/ripemd160.js": "f64586d2f13dbe832fa0f814ca7e1c49e09e73e4cb71f074049bac546ae88eff",
|
||||||
"https://esm.sh/v113/@noble/hashes@1.3.0/deno/pbkdf2.js": "f15a067b29ae22bee69ad1e91aec374dc1b3d819132b519b3b5a49db263eac3a",
|
"https://esm.sh/v114/@noble/hashes@1.2.0/deno/sha256.js": "a9b2c46d0b81b6a45a27eeb72f15fce97493bcbbc0aef665b7ae7e130035d033",
|
||||||
"https://esm.sh/v113/@noble/hashes@1.3.0/deno/ripemd160.js": "0e25b8733bfb9adcee81e111efcc0169ff652f32f2f2550caaee9512a18e4302",
|
"https://esm.sh/v114/@noble/hashes@1.2.0/deno/sha512.js": "b6821abe4715bff7abfbe04c52f67285ee3ce49cdd463eaf7d87ad635e5ce12a",
|
||||||
"https://esm.sh/v113/@noble/hashes@1.3.0/deno/sha256.js": "a23d2b298cd8089ab1dee3f1d60641cb11ed551ed649c5d30555a34ca19f400b",
|
"https://esm.sh/v114/@noble/hashes@1.2.0/deno/utils.js": "38e315b8dec2c6a5907e34470fef47a459bb562d25821a169763ec43605e3bf1",
|
||||||
"https://esm.sh/v113/@noble/hashes@1.3.0/deno/sha512.js": "ee47ce36636a562bd6ef44d1f743ed62c74a8e6485382eb41e260139bf1acf45",
|
"https://esm.sh/v114/@noble/secp256k1@1.7.0/deno/secp256k1.mjs": "058a16e83628f6e0d048055f07ddd9400599ad21812a3db314406ef73c591d5e",
|
||||||
"https://esm.sh/v113/@noble/hashes@1.3.0/deno/utils.js": "d39d84af712da02d6789734c1e2084ae0f4f452be618861e1981ee10ab2c96ef",
|
"https://esm.sh/v114/@noble/secp256k1@1.7.1/deno/secp256k1.mjs": "9616385c64e9ad73da07cbe7342e22f28d16092f632681e5bc19b6f403f7a28d",
|
||||||
"https://esm.sh/v113/@noble/secp256k1@1.7.1/deno/secp256k1.mjs": "9616385c64e9ad73da07cbe7342e22f28d16092f632681e5bc19b6f403f7a28d",
|
"https://esm.sh/v114/@scure/base@1.1.1/deno/base.mjs": "c9be265179789182c8a9f719bfce436c09b512a42afa09c3c66d91a9f7d8659e",
|
||||||
"https://esm.sh/v113/@scure/base@1.1.1/deno/base.mjs": "c9be265179789182c8a9f719bfce436c09b512a42afa09c3c66d91a9f7d8659e",
|
"https://esm.sh/v114/@scure/bip32@1.1.4/deno/bip32.mjs": "cd928251a5fb5a78e9e65d73fe5ee34dfd00ea7228a5dcd5e4e143a168314fa2",
|
||||||
"https://esm.sh/v113/@scure/bip32@1.2.0/deno/bip32.mjs": "0fdfc6f8f21d710a4808506efd7d9ad3dcd50745ae9c47a164be9f9f17d9b831",
|
"https://esm.sh/v114/@scure/bip39@1.1.1/deno/bip39.mjs": "ee547a6c3207b6fac81c2cb5d8945994f24bca8bebe2125789e47a9a3846137d",
|
||||||
"https://esm.sh/v113/@scure/bip39@1.2.0/deno/bip39.mjs": "2f7c3a19892a67fea235337aa73160c57b5170a30db88f38df18ced956cb0c2d",
|
"https://esm.sh/v114/@scure/bip39@1.1.1/deno/wordlists/english.js.js": "d3994c41068f581e6fb3427f53a40dcd4a7309c570b651579339c2b5a33cba5d",
|
||||||
"https://esm.sh/v113/@scure/bip39@1.2.0/deno/wordlists/english.js.js": "d2f68b7928869a1b362d5e9cbb85f796fd7387f6129b0278a499db28ea7daac5",
|
"https://esm.sh/v114/nostr-tools@1.8.4": "382bc56bde0377c59da1ef58a2fa9d8bdcc92dbf10ef6a50d9253a30efdb9d96",
|
||||||
"https://esm.sh/v113/nostr-tools@1.8.1": "8fa03509e71eb78beff8ecb81a33c91581eb61b48f7d0437f59ddb2ff6875d4b",
|
"https://esm.sh/v114/nostr-tools@1.8.4/deno/nostr-tools.mjs": "5140a23c793227df205f4fe1a388c554530de0e90cf6d43842a28dad6744cd13",
|
||||||
"https://esm.sh/v113/nostr-tools@1.8.1/deno/nostr-tools.mjs": "745e9e2498ace50eca097fa5a8616c3edb39210f863190d201487298fcb78007",
|
"https://esm.sh/v114/nostr-tools@1.8.4/lib/event.d.ts": "4f9481476116fe98cf7667b2e1b8a8efecde076fb0e5e8c3890ad89c7e1db9d5",
|
||||||
"https://esm.sh/v113/nostr-tools@1.8.1/lib/event.d.ts": "5ff40da5677bcf4fd16309dec9b2dd271e6ed8dce43de6995066efc6c2f0727c",
|
"https://esm.sh/v114/nostr-tools@1.8.4/lib/fakejson.d.ts": "7f56a105c7db5ba6b525c278a4c2e2a4e9bd67fa954e9bc523705f266a39eb53",
|
||||||
"https://esm.sh/v113/nostr-tools@1.8.1/lib/fakejson.d.ts": "7f56a105c7db5ba6b525c278a4c2e2a4e9bd67fa954e9bc523705f266a39eb53",
|
"https://esm.sh/v114/nostr-tools@1.8.4/lib/filter.d.ts": "308d8b36f5405af5a34174500d95d30253f70308e21767e1eddbab912f58480f",
|
||||||
"https://esm.sh/v113/nostr-tools@1.8.1/lib/filter.d.ts": "41cc390b0e7ae40cbb423031c3cf9500adc8bc91d632c3b0324dddd53f73b21d",
|
"https://esm.sh/v114/nostr-tools@1.8.4/lib/index.d.ts": "4801be2f5314db4c9899dc04dbd0b91f1e02057f1fe624dfe22913111256dc46",
|
||||||
"https://esm.sh/v113/nostr-tools@1.8.1/lib/index.d.ts": "9fedd273dab24ff887f604095f1fc27fc5665fe3b953d1f8aa8d00890cbeba82",
|
"https://esm.sh/v114/nostr-tools@1.8.4/lib/keys.d.ts": "a95ae8881851ae3e38125606ea1710dc0c684232db18fbfab632d274b58ef04a",
|
||||||
"https://esm.sh/v113/nostr-tools@1.8.1/lib/keys.d.ts": "a95ae8881851ae3e38125606ea1710dc0c684232db18fbfab632d274b58ef04a",
|
"https://esm.sh/v114/nostr-tools@1.8.4/lib/nip04.d.ts": "1d7576fda27eba5279dd28cffe2be414335fd2dffb894efd77b61fd30fe89cbd",
|
||||||
"https://esm.sh/v113/nostr-tools@1.8.1/lib/nip04.d.ts": "1d7576fda27eba5279dd28cffe2be414335fd2dffb894efd77b61fd30fe89cbd",
|
"https://esm.sh/v114/nostr-tools@1.8.4/lib/nip05.d.ts": "f181522bd2d2247f8634a0175579bcc47eec67fdc3a0703328fff1bd1f164e39",
|
||||||
"https://esm.sh/v113/nostr-tools@1.8.1/lib/nip05.d.ts": "f181522bd2d2247f8634a0175579bcc47eec67fdc3a0703328fff1bd1f164e39",
|
"https://esm.sh/v114/nostr-tools@1.8.4/lib/nip06.d.ts": "e2cf12b2fa49e0fe1a8f251b5ff8b3bba8d98d26c0c591e3a0e39cf3120ead1e",
|
||||||
"https://esm.sh/v113/nostr-tools@1.8.1/lib/nip06.d.ts": "e2cf12b2fa49e0fe1a8f251b5ff8b3bba8d98d26c0c591e3a0e39cf3120ead1e",
|
"https://esm.sh/v114/nostr-tools@1.8.4/lib/nip10.d.ts": "2e98303abee5d02b0319c6abd01e3aa54d1337711155f0feb43752a465052e87",
|
||||||
"https://esm.sh/v113/nostr-tools@1.8.1/lib/nip19.d.ts": "8baed9c741f2935c7ae61af63cfc14ecf5e8228088dc8b51601a63a237f06a82",
|
"https://esm.sh/v114/nostr-tools@1.8.4/lib/nip13.d.ts": "b319fee85d1048d8ad3f19475bf45d300d474cc658075d191b1a0f419ba8a7da",
|
||||||
"https://esm.sh/v113/nostr-tools@1.8.1/lib/nip26.d.ts": "e3dd5da8f9afe76e87dd1aa67f976fd2c0fab09253d02d669d0969b9f434d048",
|
"https://esm.sh/v114/nostr-tools@1.8.4/lib/nip19.d.ts": "8baed9c741f2935c7ae61af63cfc14ecf5e8228088dc8b51601a63a237f06a82",
|
||||||
"https://esm.sh/v113/nostr-tools@1.8.1/lib/nip39.d.ts": "f508df907affd5310fdd509124e3092be35a039a04c8f06aa367d13782f23416",
|
"https://esm.sh/v114/nostr-tools@1.8.4/lib/nip26.d.ts": "e3dd5da8f9afe76e87dd1aa67f976fd2c0fab09253d02d669d0969b9f434d048",
|
||||||
"https://esm.sh/v113/nostr-tools@1.8.1/lib/nip57.d.ts": "a7434735da9b5073aa533f88241516d74f6a37da81b097277e8ad90233c50bfc",
|
"https://esm.sh/v114/nostr-tools@1.8.4/lib/nip39.d.ts": "f508df907affd5310fdd509124e3092be35a039a04c8f06aa367d13782f23416",
|
||||||
"https://esm.sh/v113/nostr-tools@1.8.1/lib/pool.d.ts": "ff40f2acad2252493c04a3a6bf200e44bfc71ad0c3e6eb368475c4ce9c3572b6",
|
"https://esm.sh/v114/nostr-tools@1.8.4/lib/nip57.d.ts": "a7434735da9b5073aa533f88241516d74f6a37da81b097277e8ad90233c50bfc",
|
||||||
"https://esm.sh/v113/nostr-tools@1.8.1/lib/references.d.ts": "b2e39f5c439380a1dc8e578b471ba3992f33e3936aa0eecf625734c7ba669098",
|
"https://esm.sh/v114/nostr-tools@1.8.4/lib/pool.d.ts": "ff40f2acad2252493c04a3a6bf200e44bfc71ad0c3e6eb368475c4ce9c3572b6",
|
||||||
"https://esm.sh/v113/nostr-tools@1.8.1/lib/relay.d.ts": "9bc6f2897a95ec12d128e94b2e7d6161d30a6bfe8d4350e217fbf4b710988db3",
|
"https://esm.sh/v114/nostr-tools@1.8.4/lib/references.d.ts": "b2e39f5c439380a1dc8e578b471ba3992f33e3936aa0eecf625734c7ba669098",
|
||||||
"https://esm.sh/v113/nostr-tools@1.8.1/lib/utils.d.ts": "6f37b09db0dce09f17ff7b70b921b9bb809bcb18c3bc058cb914afdf3c0e774e"
|
"https://esm.sh/v114/nostr-tools@1.8.4/lib/relay.d.ts": "9bc6f2897a95ec12d128e94b2e7d6161d30a6bfe8d4350e217fbf4b710988db3",
|
||||||
},
|
"https://esm.sh/v114/nostr-tools@1.8.4/lib/utils.d.ts": "6f37b09db0dce09f17ff7b70b921b9bb809bcb18c3bc058cb914afdf3c0e774e"
|
||||||
"npm": {
|
|
||||||
"specifiers": {
|
|
||||||
"@noble/secp256k1@^1.7.1": "@noble/secp256k1@1.7.1"
|
|
||||||
},
|
|
||||||
"packages": {
|
|
||||||
"@noble/secp256k1@1.7.1": {
|
|
||||||
"integrity": "sha512-hOUk6AyBFmqVrv7k5WAw/LpszxVbj9gGN4JRkIX52fdFAj1UA61KXmZDvqVEm+pOyec3+fIeZB02LYa/pWOArw==",
|
|
||||||
"dependencies": {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export { readLines } from 'https://deno.land/std@0.181.0/io/mod.ts';
|
export { readLines } from 'https://deno.land/std@0.181.0/io/mod.ts';
|
||||||
export { assert, assertEquals } from 'https://deno.land/std@0.181.0/testing/asserts.ts';
|
export { assert, assertEquals } from 'https://deno.land/std@0.181.0/testing/asserts.ts';
|
||||||
export { Keydb } from 'https://deno.land/x/keydb@1.0.0/sqlite.ts';
|
export { Keydb } from 'https://deno.land/x/keydb@1.0.0/sqlite.ts';
|
||||||
export * as secp from 'npm:@noble/secp256k1@^1.7.1';
|
export { type Filter, matchFilter, nip13 } from 'https://esm.sh/v114/nostr-tools@1.8.4';
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
|
import { type Filter, matchFilter } from '../deps.ts';
|
||||||
import { Policy } from '../types.ts';
|
import { Policy } from '../types.ts';
|
||||||
|
|
||||||
import { type Filter, matchFilter } from 'https://esm.sh/v113/nostr-tools@1.8.1';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reject all events which don't match the filter.
|
* Reject all events which don't match the filter.
|
||||||
*
|
*
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { secp } from '../deps.ts';
|
import { nip13 } from '../deps.ts';
|
||||||
|
|
||||||
import type { Policy } from '../types.ts';
|
import type { Policy } from '../types.ts';
|
||||||
|
|
||||||
@ -12,7 +12,7 @@ interface POW {
|
|||||||
const powPolicy: Policy<POW> = ({ event }, opts = {}) => {
|
const powPolicy: Policy<POW> = ({ event }, opts = {}) => {
|
||||||
const { difficulty = 1 } = opts;
|
const { difficulty = 1 } = opts;
|
||||||
|
|
||||||
const pow = getPow(event.id);
|
const pow = nip13.getPow(event.id);
|
||||||
const nonce = event.tags.find((t) => t[0] === 'nonce');
|
const nonce = event.tags.find((t) => t[0] === 'nonce');
|
||||||
|
|
||||||
if (pow >= difficulty && nonce && Number(nonce[2]) >= difficulty) {
|
if (pow >= difficulty && nonce && Number(nonce[2]) >= difficulty) {
|
||||||
@ -30,45 +30,4 @@ const powPolicy: Policy<POW> = ({ event }, opts = {}) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Get POW difficulty from a Nostr hex ID. */
|
|
||||||
function getPow(id: string): number {
|
|
||||||
return getLeadingZeroBits(secp.utils.hexToBytes(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get number of leading 0 bits. Adapted from nostream.
|
|
||||||
* https://github.com/Cameri/nostream/blob/fb6948fd83ca87ce552f39f9b5eb780ea07e272e/src/utils/proof-of-work.ts
|
|
||||||
*/
|
|
||||||
function getLeadingZeroBits(hash: Uint8Array): number {
|
|
||||||
let total: number, i: number, bits: number;
|
|
||||||
|
|
||||||
for (i = 0, total = 0; i < hash.length; i++) {
|
|
||||||
bits = msb(hash[i]);
|
|
||||||
total += bits;
|
|
||||||
if (bits !== 8) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adapted from nostream.
|
|
||||||
* https://github.com/Cameri/nostream/blob/fb6948fd83ca87ce552f39f9b5eb780ea07e272e/src/utils/proof-of-work.ts
|
|
||||||
*/
|
|
||||||
function msb(b: number) {
|
|
||||||
let n = 0;
|
|
||||||
|
|
||||||
if (b === 0) {
|
|
||||||
return 8;
|
|
||||||
}
|
|
||||||
|
|
||||||
// deno-lint-ignore no-cond-assign
|
|
||||||
while (b >>= 1) {
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 7 - n;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default powPolicy;
|
export default powPolicy;
|
||||||
|
Loading…
Reference in New Issue
Block a user