]> zoso.dev Git - libnemo.git/commitdiff
Remove self reference in nacl since we're using it as a module. Replace imports of...
authorChris Duncan <chris@zoso.dev>
Sun, 24 Nov 2024 23:22:47 +0000 (15:22 -0800)
committerChris Duncan <chris@zoso.dev>
Sun, 24 Nov 2024 23:22:47 +0000 (15:22 -0800)
src/lib/account.ts
src/lib/block.ts
src/lib/tools.ts
src/lib/workers/nano25519.ts

index e9fb73ef4e21849f808722001c6bdefbe34585df..a98a5be9eb8c8f834d562b46cd3dd1670c3deee7 100644 (file)
@@ -4,9 +4,9 @@
 import blake2b from 'blake2b'\r
 import { ACCOUNT_KEY_LENGTH, ALPHABET, PREFIX, PREFIX_LEGACY } from './constants.js'\r
 import { base32, bytes, hex } from './convert.js'\r
-import { keyPair } from './workers/nano25519.js'\r
 import { Rpc } from './rpc.js'\r
 import { Safe } from './safe.js'\r
+import * as Ed25519 from './workers/nano25519.js'\r
 \r
 /**\r
 * Represents a single Nano address and the associated public key. To include the\r
@@ -87,7 +87,7 @@ export class Account {
        */\r
        static async fromPrivateKey (key: string, index?: number): Promise<Account> {\r
                Account.#validateKey(key)\r
-               const { publicKey } = keyPair.fromSeed(hex.toBytes(key))\r
+               const { publicKey } = Ed25519.sign.keyPair.fromSeed(hex.toBytes(key))\r
                const account = await Account.fromPublicKey(bytes.toHex(publicKey), index)\r
                account.#prv = key.toUpperCase()\r
                return account\r
index 577e6c9f03fa41f78f87e8175359fb63f2c7c586..cd4b5c2470065aec0ad8c88e3aebb957cdce3127 100644 (file)
@@ -4,9 +4,9 @@
 import { BURN_ADDRESS, PREAMBLE } from './constants.js'
 import { Account } from './account.js'
 import { bytes, dec, hex } from './convert.js'
-import Ed25519 from './ed25519.js'
 import { Rpc } from './rpc.js'
 import Tools from './tools.js'
+import * as Ed25519 from './workers/nano25519.js'
 
 /**
 * Represents a block as defined by the Nano cryptocurrency protocol. The Block
index 6763413a69b396e7132117ba1ad34a6665d8eb4b..c6bdbe27ab814e22597ba4a672b68c0814f0fa86 100644 (file)
@@ -5,10 +5,10 @@ import blake2b from 'blake2b'
 import { Account } from './account.js'
 import { UNITS } from './constants.js'
 import { bytes, hex } from './convert.js'
-import Ed25519 from './ed25519.js'
 import { Rpc } from './rpc.js'
 import { Bip44Wallet, Blake2bWallet, LedgerWallet } from './wallet.js'
 import { SendBlock } from './block.js'
+import * as Ed25519 from './workers/nano25519.js'
 
 /**
 * Converts a decimal amount of nano from one unit divider to another.
index 0a4351dfea5f84b390e4db6a926fd3400faff981..754b50e21c39725d8be17287396bf9a543c80480 100644 (file)
@@ -2110,7 +2110,7 @@ import blake2b from 'blake2b'
                        crypto_sign_SEEDBYTES = 32,\r
                        crypto_hash_BYTES = 64;\r
        \r
-       nacl.lowlevel = {\r
+       lowlevel = {\r
                crypto_core_hsalsa20: crypto_core_hsalsa20,\r
                crypto_stream_xor: crypto_stream_xor,\r
                crypto_stream: crypto_stream,\r
@@ -2192,13 +2192,13 @@ import blake2b from 'blake2b'
                for (var i = 0; i < arr.length; i++) arr[i] = 0;\r
        }\r
        \r
-       nacl.randomBytes = function(n) {\r
+       randomBytes = function(n) {\r
                var b = new Uint8Array(n);\r
                randombytes(b, n);\r
                return b;\r
        };\r
        \r
-       nacl.secretbox = function(msg, nonce, key) {\r
+       secretbox = function(msg, nonce, key) {\r
                checkArrayTypes(msg, nonce, key);\r
                checkLengths(key, nonce);\r
                var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length);\r
@@ -2208,7 +2208,7 @@ import blake2b from 'blake2b'
                return c.subarray(crypto_secretbox_BOXZEROBYTES);\r
        };\r
        \r
-       nacl.secretbox.open = function(box, nonce, key) {\r
+       secretbox.open = function(box, nonce, key) {\r
                checkArrayTypes(box, nonce, key);\r
                checkLengths(key, nonce);\r
                var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length);\r
@@ -2219,11 +2219,11 @@ import blake2b from 'blake2b'
                return m.subarray(crypto_secretbox_ZEROBYTES);\r
        };\r
        \r
-       nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES;\r
-       nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES;\r
-       nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES;\r
+       secretbox.keyLength = crypto_secretbox_KEYBYTES;\r
+       secretbox.nonceLength = crypto_secretbox_NONCEBYTES;\r
+       secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES;\r
        \r
-       nacl.scalarMult = function(n, p) {\r
+       scalarMult = function(n, p) {\r
                checkArrayTypes(n, p);\r
                if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');\r
                if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size');\r
@@ -2232,7 +2232,7 @@ import blake2b from 'blake2b'
                return q;\r
        };\r
        \r
-       nacl.scalarMult.base = function(n) {\r
+       scalarMult.base = function(n) {\r
                checkArrayTypes(n);\r
                if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');\r
                var q = new Uint8Array(crypto_scalarmult_BYTES);\r
@@ -2240,15 +2240,15 @@ import blake2b from 'blake2b'
                return q;\r
        };\r
        \r
-       nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES;\r
-       nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES;\r
+       scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES;\r
+       scalarMult.groupElementLength = crypto_scalarmult_BYTES;\r
 \r
-       nacl.box = function(msg, nonce, publicKey, secretKey) {\r
-               var k = nacl.box.before(publicKey, secretKey);\r
-               return nacl.secretbox(msg, nonce, k);\r
+       box = function(msg, nonce, publicKey, secretKey) {\r
+               var k = box.before(publicKey, secretKey);\r
+               return secretbox(msg, nonce, k);\r
        };\r
        \r
-       nacl.box.before = function(publicKey, secretKey) {\r
+       box.before = function(publicKey, secretKey) {\r
                        checkArrayTypes(publicKey, secretKey);\r
                        checkBoxLengths(publicKey, secretKey);\r
                        var k = new Uint8Array(crypto_box_BEFORENMBYTES);\r
@@ -2256,23 +2256,23 @@ import blake2b from 'blake2b'
                        return k;\r
        };\r
        \r
-       nacl.box.after = nacl.secretbox;\r
+       box.after = secretbox;\r
        \r
-       nacl.box.open = function(msg, nonce, publicKey, secretKey) {\r
-               var k = nacl.box.before(publicKey, secretKey);\r
-               return nacl.secretbox.open(msg, nonce, k);\r
+       box.open = function(msg, nonce, publicKey, secretKey) {\r
+               var k = box.before(publicKey, secretKey);\r
+               return secretbox.open(msg, nonce, k);\r
        };\r
        \r
-       nacl.box.open.after = nacl.secretbox.open;\r
+       box.open.after = secretbox.open;\r
        \r
-       nacl.box.keyPair = function() {\r
+       box.keyPair = function() {\r
                                var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);\r
                                var sk = new Uint8Array(crypto_box_SECRETKEYBYTES);\r
                                crypto_box_keypair(pk, sk);\r
                                return {publicKey: pk, secretKey: sk};\r
        };\r
        \r
-       nacl.box.keyPair.fromSecretKey = function(secretKey) {\r
+       box.keyPair.fromSecretKey = function(secretKey) {\r
                                checkArrayTypes(secretKey);\r
                                if (secretKey.length !== crypto_box_SECRETKEYBYTES)\r
                                        throw new Error('bad secret key size');\r
@@ -2281,13 +2281,13 @@ import blake2b from 'blake2b'
                                return {publicKey: pk, secretKey: new Uint8Array(secretKey)};\r
        };\r
        \r
-       nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES;\r
-       nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES;\r
-       nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES;\r
-       nacl.box.nonceLength = crypto_box_NONCEBYTES;\r
-       nacl.box.overheadLength = nacl.secretbox.overheadLength;\r
+       box.publicKeyLength = crypto_box_PUBLICKEYBYTES;\r
+       box.secretKeyLength = crypto_box_SECRETKEYBYTES;\r
+       box.sharedKeyLength = crypto_box_BEFORENMBYTES;\r
+       box.nonceLength = crypto_box_NONCEBYTES;\r
+       box.overheadLength = secretbox.overheadLength;\r
        \r
-       nacl.sign = function(msg, secretKey) {\r
+       sign = function(msg, secretKey) {\r
                        checkArrayTypes(msg, secretKey);\r
                        if (secretKey.length !== crypto_sign_SECRETKEYBYTES)\r
                                throw new Error('bad secret key size');\r
@@ -2296,7 +2296,7 @@ import blake2b from 'blake2b'
                        return signedMsg;\r
        };\r
        \r
-       nacl.sign.open = function(signedMsg, publicKey) {\r
+       sign.open = function(signedMsg, publicKey) {\r
                        checkArrayTypes(signedMsg, publicKey);\r
                        if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)\r
                                throw new Error('bad public key size');\r
@@ -2308,14 +2308,14 @@ import blake2b from 'blake2b'
                        return m;\r
        };\r
        \r
-       nacl.sign.detached = function(msg, secretKey) {\r
-                       var signedMsg = nacl.sign(msg, secretKey);\r
+       sign.detached = function(msg, secretKey) {\r
+                       var signedMsg = sign(msg, secretKey);\r
                        var sig = new Uint8Array(crypto_sign_BYTES);\r
                        for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i];\r
                        return sig;\r
        };\r
        \r
-       nacl.sign.detached.verify = function(msg, sig, publicKey) {\r
+       sign.detached.verify = function(msg, sig, publicKey) {\r
                        checkArrayTypes(msg, sig, publicKey);\r
                        if (sig.length !== crypto_sign_BYTES)\r
                                throw new Error('bad signature size');\r
@@ -2329,14 +2329,14 @@ import blake2b from 'blake2b'
                        return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0);\r
        };\r
        \r
-       nacl.sign.keyPair = function() {\r
+       sign.keyPair = function() {\r
                        var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);\r
                        var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);\r
                        crypto_sign_keypair(pk, sk);\r
                        return {publicKey: pk, secretKey: sk};\r
        };\r
        \r
-       nacl.sign.keyPair.fromSecretKey = function(secretKey) {\r
+       sign.keyPair.fromSecretKey = function(secretKey) {\r
                        checkArrayTypes(secretKey);\r
                        if (secretKey.length !== crypto_sign_SECRETKEYBYTES)\r
                        throw new Error('bad secret key size');\r
@@ -2345,7 +2345,7 @@ import blake2b from 'blake2b'
                        return {publicKey: pk, secretKey: new Uint8Array(secretKey)};\r
        };\r
        \r
-       nacl.sign.keyPair.fromSeed = function(seed) {\r
+       sign.keyPair.fromSeed = function(seed) {\r
                        checkArrayTypes(seed);\r
                        if (seed.length !== crypto_sign_SEEDBYTES)\r
                                throw new Error('bad seed size');\r
@@ -2356,21 +2356,21 @@ import blake2b from 'blake2b'
                        return {publicKey: pk, secretKey: sk};\r
        };\r
        \r
-       nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES;\r
-       nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES;\r
-       nacl.sign.seedLength = crypto_sign_SEEDBYTES;\r
-       nacl.sign.signatureLength = crypto_sign_BYTES;\r
+       sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES;\r
+       sign.secretKeyLength = crypto_sign_SECRETKEYBYTES;\r
+       sign.seedLength = crypto_sign_SEEDBYTES;\r
+       sign.signatureLength = crypto_sign_BYTES;\r
        \r
-       nacl.hash = function(msg) {\r
+       hash = function(msg) {\r
                checkArrayTypes(msg);\r
                var h = new Uint8Array(crypto_hash_BYTES);\r
                crypto_hash(h, msg, msg.length);\r
                return h;\r
        };\r
        \r
-       nacl.hash.hashLength = crypto_hash_BYTES;\r
+       hash.hashLength = crypto_hash_BYTES;\r
        \r
-       nacl.verify = function(x, y) {\r
+       verify = function(x, y) {\r
                checkArrayTypes(x, y);\r
                // Zero length arguments are considered not equal.\r
                if (x.length === 0 || y.length === 0) return false;\r
@@ -2378,7 +2378,7 @@ import blake2b from 'blake2b'
                return (vn(x, 0, y, 0, x.length) === 0) ? true : false;\r
        };\r
        \r
-       nacl.setPRNG = function(fn) {\r
+       setPRNG = function(fn) {\r
                randombytes = fn;\r
        };\r
        \r
@@ -2389,7 +2389,7 @@ import blake2b from 'blake2b'
                if (crypto && crypto.getRandomValues) {\r
                        // Browsers.\r
                        var QUOTA = 65536;\r
-                       nacl.setPRNG(function(x, n) {\r
+                       setPRNG(function(x, n) {\r
                                var i, v = new Uint8Array(n);\r
                                for (i = 0; i < n; i += QUOTA) {\r
                                        crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));\r
@@ -2401,7 +2401,7 @@ import blake2b from 'blake2b'
                        // Node.js.\r
                        crypto = require('crypto');\r
                        if (crypto && crypto.randomBytes) {\r
-                               nacl.setPRNG(function(x, n) {\r
+                               setPRNG(function(x, n) {\r
                                        var i, v = crypto.randomBytes(n);\r
                                        for (i = 0; i < n; i++) x[i] = v[i];\r
                                        cleanup(v);\r
@@ -2410,4 +2410,4 @@ import blake2b from 'blake2b'
                }\r
        })();\r
        \r
-       export { box, keyPair, getPublicKey, hash, message, randomBytes, scalarMult }\r
+       export { box, hash, randomBytes, scalarMult, secretbox, sign, verify }\r