nappup 2.0.0 → 2.0.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/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "url": "git+https://github.com/44billion/nappup.git"
7
7
  },
8
8
  "license": "MIT",
9
- "version": "2.0.0",
9
+ "version": "2.0.1",
10
10
  "description": "Nostr App Uploader",
11
11
  "type": "module",
12
12
  "scripts": {
@@ -21,7 +21,7 @@
21
21
  "@noble/hashes": "^2.0.0",
22
22
  "dotenv": "^17.2.0",
23
23
  "file-type": "^21.0.0",
24
- "libp2r2p": "^0.2.0",
24
+ "libp2r2p": "^0.3.0",
25
25
  "mime-types": "^3.0.1",
26
26
  "nmmr": "^2.0.0",
27
27
  "nostr-tools": "^2.23.3"
@@ -1,74 +0,0 @@
1
- import { base16ToBytes, bytesToBase16 } from '#helpers/base16.js'
2
- import { base62ToBytes, bytesToBase62 } from '#helpers/base62.js'
3
-
4
- export const BASE36_ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyz'
5
- const BASE = BigInt(BASE36_ALPHABET.length)
6
- const LEADER = BASE36_ALPHABET[0]
7
- const CHAR_MAP = new Map([...BASE36_ALPHABET].map((char, index) => [char, BigInt(index)]))
8
- const BASE36_REGEX = /^[0-9a-z]+$/
9
-
10
- export function isBase36 (str) {
11
- if (typeof str !== 'string') return false
12
- return BASE36_REGEX.test(str)
13
- }
14
-
15
- export function bytesToBase36 (bytes, padLength = 0) {
16
- return base16ToBase36(bytesToBase16(bytes), padLength)
17
- }
18
-
19
- export function base16ToBase36 (hex, padLength = 0) {
20
- return bigIntToBase36(base16ToBigInt(hex), padLength)
21
- }
22
-
23
- export function base62ToBase36 (base62str, padLength = 0) {
24
- return bytesToBase36(base62ToBytes(base62str), padLength)
25
- }
26
-
27
- export function base36ToBytes (base36str) {
28
- return base16ToBytes(base36ToBase16(base36str))
29
- }
30
-
31
- export function base36ToBase16 (base36str) {
32
- return bigIntToBase16(base36ToBigInt(base36str))
33
- }
34
-
35
- export function base36ToBase62 (base36str, padLength = 0) {
36
- return bytesToBase62(base36ToBytes(base36str), padLength)
37
- }
38
-
39
- function base36ToBigInt (base36str) {
40
- if (typeof base36str !== 'string') {
41
- throw new Error('Input must be a string.')
42
- }
43
-
44
- let result = 0n
45
- for (const char of base36str) {
46
- const value = CHAR_MAP.get(char)
47
- if (value === undefined) {
48
- throw new Error(`Invalid character in Base36 string: ${char}`)
49
- }
50
- result = result * BASE + value
51
- }
52
- return result
53
- }
54
-
55
- function bigIntToBase36 (num, padLength) {
56
- if (typeof num !== 'bigint') throw new Error('Input must be a BigInt.')
57
- if (num < 0n) throw new Error('Can\'t be signed BigInt')
58
-
59
- return num.toString(36).padStart(padLength, LEADER)
60
- }
61
-
62
- function bigIntToBase16 (num) {
63
- if (typeof num !== 'bigint') throw new Error('Input must be a BigInt.')
64
- if (num < 0n) throw new Error('Can\'t be signed BigInt')
65
-
66
- let hexString = num.toString(16)
67
- if (hexString.length % 2 !== 0) hexString = `0${hexString}`
68
- return hexString
69
- }
70
-
71
- function base16ToBigInt (hex) {
72
- if (typeof hex !== 'string') throw new Error('Input must be a string.')
73
- return BigInt(`0x${hex}`)
74
- }
@@ -1,59 +0,0 @@
1
- export const BASE62_ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
2
- const BASE = BigInt(BASE62_ALPHABET.length)
3
- const LEADER = BASE62_ALPHABET[0]
4
- const CHAR_MAP = new Map([...BASE62_ALPHABET].map((char, index) => [char, BigInt(index)]))
5
-
6
- export function bytesToBase62 (bytes, padLength = 0) {
7
- if (bytes.length === 0) return ''.padStart(padLength, LEADER)
8
-
9
- let num = 0n
10
- for (const byte of bytes) {
11
- num = (num << 8n) + BigInt(byte)
12
- }
13
-
14
- let result = ''
15
- if (num === 0n) return LEADER.padStart(padLength, LEADER)
16
-
17
- while (num > 0n) {
18
- const remainder = num % BASE
19
- result = BASE62_ALPHABET[Number(remainder)] + result
20
- num = num / BASE
21
- }
22
-
23
- for (const byte of bytes) {
24
- if (byte !== 0) break
25
-
26
- result = LEADER + result
27
- }
28
-
29
- return result.padStart(padLength, LEADER)
30
- }
31
-
32
- export function base62ToBytes (base62Str) {
33
- if (typeof base62Str !== 'string') { throw new Error('base62ToBytes requires a string argument') }
34
- if (base62Str.length === 0) return new Uint8Array()
35
-
36
- let leadingZeros = 0
37
- for (let i = 0; i < base62Str.length; i++) {
38
- if (base62Str[i] !== LEADER) break
39
-
40
- leadingZeros++
41
- }
42
-
43
- let num = 0n
44
- for (const char of base62Str) {
45
- const value = CHAR_MAP.get(char)
46
- if (value === undefined) { throw new Error(`Invalid character in Base62 string: ${char}`) }
47
- num = num * BASE + value
48
- }
49
-
50
- const bytes = []
51
- while (num > 0n) {
52
- bytes.unshift(Number(num & 0xffn))
53
- num = num >> 8n
54
- }
55
-
56
- const result = new Uint8Array(leadingZeros + bytes.length)
57
- result.set(bytes, leadingZeros)
58
- return result
59
- }