shogun-core 6.2.3 → 6.3.0
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/browser/defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js +93 -341
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js.map +1 -1
- package/dist/browser/shogun-core.js +138850 -146638
- package/dist/browser/shogun-core.js.map +1 -1
- package/dist/{core.js → src/core.js} +167 -107
- package/dist/src/crypto/asymmetric.js +168 -0
- package/dist/src/crypto/double-ratchet.js +908 -0
- package/dist/src/crypto/file-encryption.js +352 -0
- package/dist/src/crypto/hashing.js +160 -0
- package/dist/src/crypto/index.js +18 -0
- package/dist/{crypto → src/crypto}/mls-codec.js +24 -34
- package/dist/src/crypto/mls.js +734 -0
- package/dist/src/crypto/pgp.js +619 -0
- package/dist/{crypto → src/crypto}/random-generation.js +125 -103
- package/dist/src/crypto/sframe.js +466 -0
- package/dist/src/crypto/signal-protocol.js +943 -0
- package/dist/src/crypto/symmetric.js +165 -0
- package/dist/src/crypto/utils.js +220 -0
- package/dist/src/examples/auth-test.js +535 -0
- package/dist/src/examples/crypto-identity-example.js +294 -0
- package/dist/src/examples/crypto-working-test.js +149 -0
- package/dist/src/examples/double-ratchet-test.js +240 -0
- package/dist/src/examples/mls-3-member-test.js +183 -0
- package/dist/src/examples/mls-multi-member.js +439 -0
- package/dist/src/examples/mls-sframe-test.js +491 -0
- package/dist/src/examples/mls-simple-test.js +122 -0
- package/dist/src/examples/pgp-example.js +354 -0
- package/dist/src/examples/random-generation-test.js +191 -0
- package/dist/src/examples/shogun-core-example.js +204 -0
- package/dist/src/examples/signal-protocol-test.js +82 -0
- package/dist/src/examples/zkproof-credentials-example.js +357 -0
- package/dist/src/examples/zkproof-example.js +357 -0
- package/dist/src/gundb/crypto.js +420 -0
- package/dist/src/gundb/db.js +728 -0
- package/dist/src/gundb/derive.js +327 -0
- package/dist/src/gundb/errors.js +115 -0
- package/dist/src/gundb/gun-es.js +8 -0
- package/dist/src/gundb/index.js +5 -0
- package/dist/{gundb → src/gundb}/rxjs.js +147 -111
- package/dist/{gundb → src/gundb}/types.js +1 -2
- package/dist/src/index.js +19 -0
- package/dist/src/interfaces/events.js +57 -0
- package/dist/{interfaces → src/interfaces}/shogun.js +4 -7
- package/dist/src/managers/AuthManager.js +301 -0
- package/dist/src/managers/CoreInitializer.js +304 -0
- package/dist/src/managers/CryptoIdentityManager.js +230 -0
- package/dist/{managers → src/managers}/EventManager.js +19 -21
- package/dist/{managers → src/managers}/PluginManager.js +123 -89
- package/dist/src/plugins/base.js +90 -0
- package/dist/src/plugins/index.js +17 -0
- package/dist/src/plugins/nostr/index.js +4 -0
- package/dist/src/plugins/nostr/nostrConnector.js +539 -0
- package/dist/src/plugins/nostr/nostrConnectorPlugin.js +663 -0
- package/dist/src/plugins/nostr/nostrSigner.js +414 -0
- package/dist/src/plugins/smartwallet/index.js +2 -0
- package/dist/src/plugins/smartwallet/smartWalletPlugin.js +824 -0
- package/dist/src/plugins/web3/index.js +4 -0
- package/dist/src/plugins/web3/types.js +1 -0
- package/dist/src/plugins/web3/web3Connector.js +738 -0
- package/dist/src/plugins/web3/web3ConnectorPlugin.js +639 -0
- package/dist/src/plugins/web3/web3Signer.js +432 -0
- package/dist/src/plugins/webauthn/index.js +3 -0
- package/dist/{plugins → src/plugins}/webauthn/types.js +2 -5
- package/dist/src/plugins/webauthn/webauthn.js +647 -0
- package/dist/src/plugins/webauthn/webauthnPlugin.js +689 -0
- package/dist/src/plugins/webauthn/webauthnSigner.js +419 -0
- package/dist/{plugins → src/plugins}/zkproof/index.js +3 -10
- package/dist/src/plugins/zkproof/types.js +1 -0
- package/dist/src/plugins/zkproof/zkCredentials.js +287 -0
- package/dist/src/plugins/zkproof/zkProofConnector.js +267 -0
- package/dist/src/plugins/zkproof/zkProofPlugin.js +405 -0
- package/dist/src/storage/storage.js +189 -0
- package/dist/src/utils/errorHandler.js +339 -0
- package/dist/{utils → src/utils}/eventEmitter.js +26 -26
- package/dist/{utils → src/utils}/seedPhrase.js +23 -32
- package/dist/{utils → src/utils}/validation.js +14 -21
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/{crypto → src/crypto}/double-ratchet.d.ts +1 -1
- package/dist/types/{crypto → src/crypto}/signal-protocol.d.ts +25 -0
- package/dist/types/{crypto → src/crypto}/types.d.ts +3 -1
- package/dist/types/src/examples/crypto-working-test.d.ts +1 -0
- package/dist/types/src/examples/double-ratchet-test.d.ts +1 -0
- package/dist/types/src/examples/mls-sframe-test.d.ts +1 -0
- package/dist/types/src/examples/random-generation-test.d.ts +1 -0
- package/dist/types/src/examples/signal-protocol-test.d.ts +1 -0
- package/dist/types/{gundb → src/gundb}/db.d.ts +14 -1
- package/dist/types/src/gundb/gun-es.d.ts +8 -0
- package/dist/types/src/gundb/min.d.ts +3 -0
- package/dist/types/{index.d.ts → src/index.d.ts} +1 -0
- package/package.json +14 -11
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_curve_js-node_modules_noble_curves_esm_-1ce4ed.shogun-core.js +0 -1651
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_curve_js-node_modules_noble_curves_esm_-1ce4ed.shogun-core.js.map +0 -1
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_nist_js.shogun-core.js +0 -1608
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_nist_js.shogun-core.js.map +0 -1
- package/dist/crypto/asymmetric.js +0 -99
- package/dist/crypto/double-ratchet.js +0 -370
- package/dist/crypto/file-encryption.js +0 -213
- package/dist/crypto/hashing.js +0 -87
- package/dist/crypto/index.js +0 -34
- package/dist/crypto/mls.js +0 -569
- package/dist/crypto/pgp.js +0 -390
- package/dist/crypto/sframe.js +0 -352
- package/dist/crypto/signal-protocol.js +0 -456
- package/dist/crypto/symmetric.js +0 -91
- package/dist/crypto/types.js +0 -2
- package/dist/crypto/utils.js +0 -140
- package/dist/examples/auth-test.js +0 -453
- package/dist/examples/crypto-identity-example.js +0 -196
- package/dist/examples/crypto-working-test.js +0 -83
- package/dist/examples/double-ratchet-test.js +0 -155
- package/dist/examples/mls-3-member-test.js +0 -97
- package/dist/examples/mls-multi-member.js +0 -153
- package/dist/examples/mls-sframe-test.js +0 -307
- package/dist/examples/mls-simple-test.js +0 -58
- package/dist/examples/pgp-example.js +0 -200
- package/dist/examples/random-generation-test.js +0 -151
- package/dist/examples/shogun-core-example.js +0 -150
- package/dist/examples/signal-protocol-test.js +0 -38
- package/dist/examples/zkproof-credentials-example.js +0 -217
- package/dist/examples/zkproof-example.js +0 -242
- package/dist/gundb/crypto.js +0 -306
- package/dist/gundb/db.js +0 -485
- package/dist/gundb/derive.js +0 -232
- package/dist/gundb/errors.js +0 -76
- package/dist/gundb/gun-es.js +0 -12
- package/dist/gundb/index.js +0 -21
- package/dist/gundb/min.js +0 -10
- package/dist/index.esm.js +0 -22
- package/dist/index.js +0 -47
- package/dist/interfaces/common.js +0 -2
- package/dist/interfaces/events.js +0 -40
- package/dist/interfaces/plugin.js +0 -2
- package/dist/managers/AuthManager.js +0 -226
- package/dist/managers/CoreInitializer.js +0 -250
- package/dist/managers/CryptoIdentityManager.js +0 -138
- package/dist/plugins/base.js +0 -50
- package/dist/plugins/index.js +0 -32
- package/dist/plugins/nostr/index.js +0 -20
- package/dist/plugins/nostr/nostrConnector.js +0 -419
- package/dist/plugins/nostr/nostrConnectorPlugin.js +0 -453
- package/dist/plugins/nostr/nostrSigner.js +0 -319
- package/dist/plugins/nostr/types.js +0 -2
- package/dist/plugins/smartwallet/index.js +0 -18
- package/dist/plugins/smartwallet/smartWalletPlugin.js +0 -511
- package/dist/plugins/smartwallet/types.js +0 -2
- package/dist/plugins/web3/index.js +0 -20
- package/dist/plugins/web3/types.js +0 -2
- package/dist/plugins/web3/web3Connector.js +0 -533
- package/dist/plugins/web3/web3ConnectorPlugin.js +0 -455
- package/dist/plugins/web3/web3Signer.js +0 -314
- package/dist/plugins/webauthn/index.js +0 -19
- package/dist/plugins/webauthn/webauthn.js +0 -496
- package/dist/plugins/webauthn/webauthnPlugin.js +0 -490
- package/dist/plugins/webauthn/webauthnSigner.js +0 -310
- package/dist/plugins/zkproof/types.js +0 -2
- package/dist/plugins/zkproof/zkCredentials.js +0 -216
- package/dist/plugins/zkproof/zkProofConnector.js +0 -198
- package/dist/plugins/zkproof/zkProofPlugin.js +0 -272
- package/dist/storage/storage.js +0 -145
- package/dist/types/gundb/gun-es.d.ts +0 -8
- package/dist/utils/errorHandler.js +0 -246
- /package/dist/{types/examples/crypto-working-test.d.ts → src/crypto/types.js} +0 -0
- /package/dist/{types/gundb/min.d.ts → src/gundb/min.js} +0 -0
- /package/dist/{types/examples/double-ratchet-test.d.ts → src/interfaces/common.js} +0 -0
- /package/dist/{types/examples/mls-sframe-test.d.ts → src/interfaces/plugin.js} +0 -0
- /package/dist/{types/examples/random-generation-test.d.ts → src/plugins/nostr/types.js} +0 -0
- /package/dist/{types/examples/signal-protocol-test.d.ts → src/plugins/smartwallet/types.js} +0 -0
- /package/dist/types/{core.d.ts → src/core.d.ts} +0 -0
- /package/dist/types/{crypto → src/crypto}/asymmetric.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/file-encryption.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/hashing.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/index.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/mls-codec.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/mls.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/pgp.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/random-generation.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/sframe.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/symmetric.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/utils.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/auth-test.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/crypto-identity-example.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/mls-3-member-test.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/mls-multi-member.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/mls-simple-test.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/pgp-example.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/shogun-core-example.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/zkproof-credentials-example.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/zkproof-example.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/crypto.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/derive.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/errors.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/index.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/rxjs.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/types.d.ts +0 -0
- /package/dist/types/{interfaces → src/interfaces}/common.d.ts +0 -0
- /package/dist/types/{interfaces → src/interfaces}/events.d.ts +0 -0
- /package/dist/types/{interfaces → src/interfaces}/plugin.d.ts +0 -0
- /package/dist/types/{interfaces → src/interfaces}/shogun.d.ts +0 -0
- /package/dist/types/{managers → src/managers}/AuthManager.d.ts +0 -0
- /package/dist/types/{managers → src/managers}/CoreInitializer.d.ts +0 -0
- /package/dist/types/{managers → src/managers}/CryptoIdentityManager.d.ts +0 -0
- /package/dist/types/{managers → src/managers}/EventManager.d.ts +0 -0
- /package/dist/types/{managers → src/managers}/PluginManager.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/base.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/nostr/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/nostr/nostrConnector.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/nostr/nostrConnectorPlugin.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/nostr/nostrSigner.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/nostr/types.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/smartwallet/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/smartwallet/smartWalletPlugin.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/smartwallet/types.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/web3/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/web3/types.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/web3/web3Connector.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/web3/web3ConnectorPlugin.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/web3/web3Signer.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/webauthn/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/webauthn/types.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/webauthn/webauthn.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/webauthn/webauthnPlugin.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/webauthn/webauthnSigner.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/zkproof/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/zkproof/types.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/zkproof/zkCredentials.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/zkproof/zkProofConnector.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/zkproof/zkProofPlugin.d.ts +0 -0
- /package/dist/types/{storage → src/storage}/storage.d.ts +0 -0
- /package/dist/types/{utils → src/utils}/errorHandler.d.ts +0 -0
- /package/dist/types/{utils → src/utils}/eventEmitter.d.ts +0 -0
- /package/dist/types/{utils → src/utils}/seedPhrase.d.ts +0 -0
- /package/dist/types/{utils → src/utils}/validation.d.ts +0 -0
package/dist/gundb/derive.js
DELETED
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = default_1;
|
|
4
|
-
const p256_1 = require("@noble/curves/p256");
|
|
5
|
-
const secp256k1_1 = require("@noble/curves/secp256k1");
|
|
6
|
-
const sha256_1 = require("@noble/hashes/sha256");
|
|
7
|
-
const sha3_1 = require("@noble/hashes/sha3");
|
|
8
|
-
const ripemd160_1 = require("@noble/hashes/ripemd160");
|
|
9
|
-
async function default_1(pwd, extra, options = {}) {
|
|
10
|
-
const TEXT_ENCODER = new TextEncoder();
|
|
11
|
-
const pwdBytes = pwd
|
|
12
|
-
? typeof pwd === "string"
|
|
13
|
-
? TEXT_ENCODER.encode(normalizeString(pwd))
|
|
14
|
-
: pwd
|
|
15
|
-
: crypto.getRandomValues(new Uint8Array(32));
|
|
16
|
-
// Mix extra into password bytes to ensure different results for different inputs
|
|
17
|
-
const extras = extra
|
|
18
|
-
? (Array.isArray(extra) ? extra : [extra]).map((e) => normalizeString(e.toString()))
|
|
19
|
-
: [];
|
|
20
|
-
const extraBuf = TEXT_ENCODER.encode(extras.join("|"));
|
|
21
|
-
const combinedInput = new Uint8Array(pwdBytes.length + extraBuf.length);
|
|
22
|
-
combinedInput.set(pwdBytes);
|
|
23
|
-
combinedInput.set(extraBuf, pwdBytes.length);
|
|
24
|
-
if (combinedInput.length < 16) {
|
|
25
|
-
throw new Error(`Insufficient input entropy (${combinedInput.length})`);
|
|
26
|
-
}
|
|
27
|
-
const version = "v1";
|
|
28
|
-
const result = {};
|
|
29
|
-
// Mantieni comportamento esistente (P-256) come default
|
|
30
|
-
const { includeP256 = true, includeSecp256k1Bitcoin = true, includeSecp256k1Ethereum = true, } = options;
|
|
31
|
-
if (includeP256) {
|
|
32
|
-
const salts = [
|
|
33
|
-
{ label: "signing", type: "pub/priv" },
|
|
34
|
-
{ label: "encryption", type: "epub/epriv" },
|
|
35
|
-
];
|
|
36
|
-
const [signingKeys, encryptionKeys] = await Promise.all(salts.map(async ({ label }) => {
|
|
37
|
-
const salt = TEXT_ENCODER.encode(`${label}-${version}`);
|
|
38
|
-
const privateKey = await stretchKey(combinedInput, salt);
|
|
39
|
-
if (!p256_1.p256.utils.isValidPrivateKey(privateKey)) {
|
|
40
|
-
throw new Error(`Invalid private key for ${label}`);
|
|
41
|
-
}
|
|
42
|
-
const publicKey = p256_1.p256.getPublicKey(privateKey, false);
|
|
43
|
-
return {
|
|
44
|
-
pub: keyBufferToJwk(publicKey),
|
|
45
|
-
priv: arrayBufToBase64UrlEncode(privateKey),
|
|
46
|
-
};
|
|
47
|
-
}));
|
|
48
|
-
// Chiavi P-256 esistenti
|
|
49
|
-
result.pub = signingKeys.pub;
|
|
50
|
-
result.priv = signingKeys.priv;
|
|
51
|
-
result.epub = encryptionKeys.pub;
|
|
52
|
-
result.epriv = encryptionKeys.priv;
|
|
53
|
-
}
|
|
54
|
-
// Derivazione Bitcoin P2PKH (secp256k1 + SHA256 + RIPEMD160 + Base58)
|
|
55
|
-
if (includeSecp256k1Bitcoin) {
|
|
56
|
-
const bitcoinSalt = TEXT_ENCODER.encode(`secp256k1-bitcoin-${version}`);
|
|
57
|
-
const bitcoinPrivateKey = await stretchKey(combinedInput, bitcoinSalt);
|
|
58
|
-
if (!secp256k1_1.secp256k1.utils.isValidPrivateKey(bitcoinPrivateKey)) {
|
|
59
|
-
throw new Error("Invalid secp256k1 private key for Bitcoin");
|
|
60
|
-
}
|
|
61
|
-
const bitcoinPublicKey = secp256k1_1.secp256k1.getPublicKey(bitcoinPrivateKey, true); // Compressed
|
|
62
|
-
result.secp256k1Bitcoin = {
|
|
63
|
-
privateKey: bytesToHex(bitcoinPrivateKey),
|
|
64
|
-
publicKey: bytesToHex(bitcoinPublicKey),
|
|
65
|
-
address: deriveP2PKHAddress(bitcoinPublicKey),
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
// Derivazione Ethereum (secp256k1 + Keccak256)
|
|
69
|
-
if (includeSecp256k1Ethereum) {
|
|
70
|
-
const ethereumSalt = TEXT_ENCODER.encode(`secp256k1-ethereum-${version}`);
|
|
71
|
-
const ethereumPrivateKey = await stretchKey(combinedInput, ethereumSalt);
|
|
72
|
-
if (!secp256k1_1.secp256k1.utils.isValidPrivateKey(ethereumPrivateKey)) {
|
|
73
|
-
throw new Error("Invalid secp256k1 private key for Ethereum");
|
|
74
|
-
}
|
|
75
|
-
const ethereumPublicKey = secp256k1_1.secp256k1.getPublicKey(ethereumPrivateKey, false); // Uncompressed
|
|
76
|
-
result.secp256k1Ethereum = {
|
|
77
|
-
privateKey: "0x" + bytesToHex(ethereumPrivateKey),
|
|
78
|
-
publicKey: "0x" + bytesToHex(ethereumPublicKey),
|
|
79
|
-
address: deriveKeccak256Address(ethereumPublicKey),
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
return result;
|
|
83
|
-
}
|
|
84
|
-
function arrayBufToBase64UrlEncode(buf) {
|
|
85
|
-
return btoa(String.fromCharCode(...buf))
|
|
86
|
-
.replace(/\//g, "_")
|
|
87
|
-
.replace(/=/g, "")
|
|
88
|
-
.replace(/\+/g, "-");
|
|
89
|
-
}
|
|
90
|
-
function keyBufferToJwk(publicKeyBuffer) {
|
|
91
|
-
if (publicKeyBuffer[0] !== 4)
|
|
92
|
-
throw new Error("Invalid uncompressed public key format");
|
|
93
|
-
return [
|
|
94
|
-
arrayBufToBase64UrlEncode(publicKeyBuffer.slice(1, 33)), // x
|
|
95
|
-
arrayBufToBase64UrlEncode(publicKeyBuffer.slice(33, 65)), // y
|
|
96
|
-
].join(".");
|
|
97
|
-
}
|
|
98
|
-
function normalizeString(str) {
|
|
99
|
-
return str.normalize("NFC").trim();
|
|
100
|
-
}
|
|
101
|
-
async function stretchKey(input, salt, iterations = 300000) {
|
|
102
|
-
try {
|
|
103
|
-
const baseKey = await crypto.subtle.importKey("raw", input, { name: "PBKDF2" }, false, ["deriveBits"]);
|
|
104
|
-
const keyBits = await crypto.subtle.deriveBits({
|
|
105
|
-
name: "PBKDF2",
|
|
106
|
-
salt: salt,
|
|
107
|
-
iterations,
|
|
108
|
-
hash: "SHA-256",
|
|
109
|
-
}, baseKey, 256);
|
|
110
|
-
const keyBytes = new Uint8Array(keyBits);
|
|
111
|
-
// Ensure the key is valid for secp256k1
|
|
112
|
-
return ensureValidSecp256k1Key(keyBytes);
|
|
113
|
-
}
|
|
114
|
-
catch (error) {
|
|
115
|
-
// Fallback: generate a deterministic key from input and salt
|
|
116
|
-
const fallbackKey = generateFallbackKey(input, salt);
|
|
117
|
-
return ensureValidSecp256k1Key(fallbackKey);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
function generateFallbackKey(input, salt) {
|
|
121
|
-
// Simple deterministic key generation as fallback
|
|
122
|
-
const key = new Uint8Array(32);
|
|
123
|
-
for (let i = 0; i < 32; i++) {
|
|
124
|
-
key[i] = (i * 7 + salt[i % salt.length]) % 256;
|
|
125
|
-
}
|
|
126
|
-
return key;
|
|
127
|
-
}
|
|
128
|
-
function ensureValidSecp256k1Key(keyBytes) {
|
|
129
|
-
// Ensure the key is not all zeros
|
|
130
|
-
if (keyBytes.every((byte) => byte === 0)) {
|
|
131
|
-
keyBytes[0] = 1;
|
|
132
|
-
}
|
|
133
|
-
// secp256k1 curve order is approximately 2^256 - 2^32 - 2^9 - 2^8 - 2^7 - 2^6 - 2^4 - 1
|
|
134
|
-
const maxValidKey = new Uint8Array([
|
|
135
|
-
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
136
|
-
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
137
|
-
0xff, 0xff, 0xff, 0xfe, 0xba, 0xae, 0xdc, 0xe6,
|
|
138
|
-
]);
|
|
139
|
-
// If the key is greater than or equal to the curve order, reduce it
|
|
140
|
-
let isGreaterOrEqual = true;
|
|
141
|
-
for (let i = 0; i < 32; i++) {
|
|
142
|
-
if (keyBytes[i] < maxValidKey[i]) {
|
|
143
|
-
isGreaterOrEqual = false;
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
else if (keyBytes[i] > maxValidKey[i]) {
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
if (isGreaterOrEqual) {
|
|
151
|
-
// Reduce the key by setting it to a safe value
|
|
152
|
-
keyBytes[31] = 0xe5; // Set to a value less than the curve order
|
|
153
|
-
}
|
|
154
|
-
// Additional validation: ensure the key is not too small
|
|
155
|
-
if (keyBytes.every((byte) => byte === 0) ||
|
|
156
|
-
keyBytes.every((byte) => byte === 1)) {
|
|
157
|
-
// Set to a safe default value
|
|
158
|
-
keyBytes.fill(0);
|
|
159
|
-
keyBytes[0] = 0x01;
|
|
160
|
-
keyBytes[31] = 0xff;
|
|
161
|
-
}
|
|
162
|
-
return keyBytes;
|
|
163
|
-
}
|
|
164
|
-
function bytesToHex(bytes) {
|
|
165
|
-
return Array.from(bytes)
|
|
166
|
-
.map((b) => b.toString(16).padStart(2, "0"))
|
|
167
|
-
.join("");
|
|
168
|
-
}
|
|
169
|
-
// Base58 encoding per Bitcoin
|
|
170
|
-
const BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
171
|
-
function base58Encode(bytes) {
|
|
172
|
-
if (bytes.length === 0)
|
|
173
|
-
return "";
|
|
174
|
-
// Count leading zeros
|
|
175
|
-
let zeros = 0;
|
|
176
|
-
for (let i = 0; i < bytes.length && bytes[i] === 0; i++) {
|
|
177
|
-
zeros++;
|
|
178
|
-
}
|
|
179
|
-
// Convert to base58
|
|
180
|
-
const digits = [0];
|
|
181
|
-
for (let i = zeros; i < bytes.length; i++) {
|
|
182
|
-
let carry = bytes[i];
|
|
183
|
-
for (let j = 0; j < digits.length; j++) {
|
|
184
|
-
carry += digits[j] << 8;
|
|
185
|
-
digits[j] = carry % 58;
|
|
186
|
-
carry = (carry / 58) | 0;
|
|
187
|
-
}
|
|
188
|
-
while (carry > 0) {
|
|
189
|
-
digits.push(carry % 58);
|
|
190
|
-
carry = (carry / 58) | 0;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
// Convert to string
|
|
194
|
-
let result = "";
|
|
195
|
-
for (let i = 0; i < zeros; i++) {
|
|
196
|
-
result += BASE58_ALPHABET[0];
|
|
197
|
-
}
|
|
198
|
-
for (let i = digits.length - 1; i >= 0; i--) {
|
|
199
|
-
result += BASE58_ALPHABET[digits[i]];
|
|
200
|
-
}
|
|
201
|
-
return result;
|
|
202
|
-
}
|
|
203
|
-
function deriveP2PKHAddress(publicKey) {
|
|
204
|
-
// Bitcoin P2PKH address derivation
|
|
205
|
-
// 1. SHA256 hash del public key
|
|
206
|
-
const sha256Hash = (0, sha256_1.sha256)(publicKey);
|
|
207
|
-
// 2. RIPEMD160 hash del risultato
|
|
208
|
-
const ripemd160Hash = (0, ripemd160_1.ripemd160)(sha256Hash);
|
|
209
|
-
// 3. Aggiungi version byte (0x00 per mainnet P2PKH)
|
|
210
|
-
const versionedHash = new Uint8Array(21);
|
|
211
|
-
versionedHash[0] = 0x00; // Mainnet P2PKH version
|
|
212
|
-
versionedHash.set(ripemd160Hash, 1);
|
|
213
|
-
// 4. Double SHA256 per checksum
|
|
214
|
-
const checksum = (0, sha256_1.sha256)((0, sha256_1.sha256)(versionedHash));
|
|
215
|
-
// 5. Aggiungi i primi 4 byte del checksum
|
|
216
|
-
const addressBytes = new Uint8Array(25);
|
|
217
|
-
addressBytes.set(versionedHash);
|
|
218
|
-
addressBytes.set(checksum.slice(0, 4), 21);
|
|
219
|
-
// 6. Base58 encode
|
|
220
|
-
return base58Encode(addressBytes);
|
|
221
|
-
}
|
|
222
|
-
function deriveKeccak256Address(publicKey) {
|
|
223
|
-
// Ethereum address derivation usando Keccak256
|
|
224
|
-
// 1. Rimuovi il prefix byte (0x04) dalla chiave pubblica non compressa
|
|
225
|
-
const publicKeyWithoutPrefix = publicKey.slice(1);
|
|
226
|
-
// 2. Calcola Keccak256 hash
|
|
227
|
-
const hash = (0, sha3_1.keccak_256)(publicKeyWithoutPrefix);
|
|
228
|
-
// 3. Prendi gli ultimi 20 byte
|
|
229
|
-
const address = hash.slice(-20);
|
|
230
|
-
// 4. Aggiungi '0x' prefix e converti in hex
|
|
231
|
-
return "0x" + bytesToHex(address);
|
|
232
|
-
}
|
package/dist/gundb/errors.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Error classes for Gun and Auth
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.NetworkError = exports.MultipleAuthError = exports.TimeoutError = exports.UserExists = exports.InvalidCredentials = exports.AuthError = exports.GunError = void 0;
|
|
7
|
-
/**
|
|
8
|
-
* Base error for Gun
|
|
9
|
-
*/
|
|
10
|
-
class GunError extends Error {
|
|
11
|
-
constructor(message) {
|
|
12
|
-
super(message);
|
|
13
|
-
this.name = "GunError";
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.GunError = GunError;
|
|
17
|
-
/**
|
|
18
|
-
* Generic authentication error
|
|
19
|
-
*/
|
|
20
|
-
class AuthError extends GunError {
|
|
21
|
-
constructor(message) {
|
|
22
|
-
super(message);
|
|
23
|
-
this.name = "AuthError";
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.AuthError = AuthError;
|
|
27
|
-
/**
|
|
28
|
-
* Invalid credentials error
|
|
29
|
-
*/
|
|
30
|
-
class InvalidCredentials extends AuthError {
|
|
31
|
-
constructor(message = "Credenziali non valide") {
|
|
32
|
-
super(message);
|
|
33
|
-
this.name = "InvalidCredentials";
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.InvalidCredentials = InvalidCredentials;
|
|
37
|
-
/**
|
|
38
|
-
* User already exists error
|
|
39
|
-
*/
|
|
40
|
-
class UserExists extends AuthError {
|
|
41
|
-
constructor(message = "Utente già esistente") {
|
|
42
|
-
super(message);
|
|
43
|
-
this.name = "UserExists";
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
exports.UserExists = UserExists;
|
|
47
|
-
/**
|
|
48
|
-
* Timeout error
|
|
49
|
-
*/
|
|
50
|
-
class TimeoutError extends GunError {
|
|
51
|
-
constructor(message = "Timeout durante l'operazione") {
|
|
52
|
-
super(message);
|
|
53
|
-
this.name = "TimeoutError";
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
exports.TimeoutError = TimeoutError;
|
|
57
|
-
/**
|
|
58
|
-
* Multiple authentication error
|
|
59
|
-
*/
|
|
60
|
-
class MultipleAuthError extends AuthError {
|
|
61
|
-
constructor(message = "Autenticazione multipla in corso") {
|
|
62
|
-
super(message);
|
|
63
|
-
this.name = "MultipleAuthError";
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
exports.MultipleAuthError = MultipleAuthError;
|
|
67
|
-
/** Base error related to the network. */
|
|
68
|
-
class NetworkError extends GunError {
|
|
69
|
-
}
|
|
70
|
-
exports.NetworkError = NetworkError;
|
|
71
|
-
const withDefaultMessage = (args, defaultMessage) => {
|
|
72
|
-
if (args.length === 0 || (args.length === 1 && !args[0])) {
|
|
73
|
-
args = [defaultMessage];
|
|
74
|
-
}
|
|
75
|
-
return args;
|
|
76
|
-
};
|
package/dist/gundb/gun-es.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SEA = exports.Gun = void 0;
|
|
4
|
-
const min_1 = require("./min");
|
|
5
|
-
Object.defineProperty(exports, "Gun", { enumerable: true, get: function () { return min_1.Gun; } });
|
|
6
|
-
Object.defineProperty(exports, "SEA", { enumerable: true, get: function () { return min_1.SEA; } });
|
|
7
|
-
require("gun/lib/then");
|
|
8
|
-
require("gun/lib/radix");
|
|
9
|
-
require("gun/lib/radisk");
|
|
10
|
-
require("gun/lib/store");
|
|
11
|
-
require("gun/lib/rindexed");
|
|
12
|
-
require("gun/lib/webrtc");
|
package/dist/gundb/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
// Export the main class
|
|
18
|
-
__exportStar(require("./db"), exports);
|
|
19
|
-
__exportStar(require("./gun-es"), exports);
|
|
20
|
-
// Export improved types
|
|
21
|
-
__exportStar(require("./types"), exports);
|
package/dist/gundb/min.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SEA = exports.Gun = void 0;
|
|
7
|
-
const gun_1 = __importDefault(require("gun"));
|
|
8
|
-
exports.Gun = gun_1.default;
|
|
9
|
-
const sea_js_1 = __importDefault(require("gun/sea.js"));
|
|
10
|
-
Object.defineProperty(exports, "SEA", { enumerable: true, get: function () { return sea_js_1.default; } });
|
package/dist/index.esm.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// ESM facade that re-exports named symbols from the CJS build for ESM consumers
|
|
2
|
-
import cjs from './index.js';
|
|
3
|
-
|
|
4
|
-
export const ShogunCore = cjs.ShogunCore;
|
|
5
|
-
export const RxJS = cjs.RxJS;
|
|
6
|
-
export const crypto = cjs.crypto;
|
|
7
|
-
export const derive = cjs.derive;
|
|
8
|
-
export const GunErrors = cjs.GunErrors;
|
|
9
|
-
export const DataBase = cjs.DataBase;
|
|
10
|
-
// Note: Gun and SEA are not exported - users should import them directly from 'gun' package
|
|
11
|
-
|
|
12
|
-
export const generateSeedPhrase = cjs.generateSeedPhrase;
|
|
13
|
-
export const validateSeedPhrase = cjs.validateSeedPhrase;
|
|
14
|
-
export const mnemonicToSeed = cjs.mnemonicToSeed;
|
|
15
|
-
export const seedToPassword = cjs.seedToPassword;
|
|
16
|
-
export const deriveCredentialsFromMnemonic = cjs.deriveCredentialsFromMnemonic;
|
|
17
|
-
export const formatSeedPhrase = cjs.formatSeedPhrase;
|
|
18
|
-
export const normalizeSeedPhrase = cjs.normalizeSeedPhrase;
|
|
19
|
-
|
|
20
|
-
export const CryptoIdentityManager = cjs.CryptoIdentityManager;
|
|
21
|
-
|
|
22
|
-
export default cjs;
|
package/dist/index.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.CryptoIdentityManager = exports.normalizeSeedPhrase = exports.formatSeedPhrase = exports.deriveCredentialsFromMnemonic = exports.seedToPassword = exports.mnemonicToSeed = exports.validateSeedPhrase = exports.generateSeedPhrase = exports.DataBase = exports.GunErrors = exports.derive = exports.crypto = exports.RxJS = exports.ShogunCore = void 0;
|
|
18
|
-
const core_1 = require("./core");
|
|
19
|
-
Object.defineProperty(exports, "ShogunCore", { enumerable: true, get: function () { return core_1.ShogunCore; } });
|
|
20
|
-
const db_1 = require("./gundb/db");
|
|
21
|
-
Object.defineProperty(exports, "RxJS", { enumerable: true, get: function () { return db_1.RxJS; } });
|
|
22
|
-
Object.defineProperty(exports, "crypto", { enumerable: true, get: function () { return db_1.crypto; } });
|
|
23
|
-
Object.defineProperty(exports, "derive", { enumerable: true, get: function () { return db_1.derive; } });
|
|
24
|
-
Object.defineProperty(exports, "GunErrors", { enumerable: true, get: function () { return db_1.GunErrors; } });
|
|
25
|
-
Object.defineProperty(exports, "DataBase", { enumerable: true, get: function () { return db_1.DataBase; } });
|
|
26
|
-
// Gun and SEA imports removed - users should import them directly from 'gun' package
|
|
27
|
-
// This prevents bundling issues in build systems like Vite
|
|
28
|
-
__exportStar(require("./utils/errorHandler"), exports);
|
|
29
|
-
__exportStar(require("./plugins"), exports);
|
|
30
|
-
__exportStar(require("./interfaces/shogun"), exports);
|
|
31
|
-
__exportStar(require("./gundb/gun-es"), exports);
|
|
32
|
-
// Note: Gun and SEA are not exported to avoid bundling issues
|
|
33
|
-
// Users should import Gun and SEA directly from the 'gun' package
|
|
34
|
-
// Export seed phrase utilities for WebAuthn multi-device support
|
|
35
|
-
var seedPhrase_1 = require("./utils/seedPhrase");
|
|
36
|
-
Object.defineProperty(exports, "generateSeedPhrase", { enumerable: true, get: function () { return seedPhrase_1.generateSeedPhrase; } });
|
|
37
|
-
Object.defineProperty(exports, "validateSeedPhrase", { enumerable: true, get: function () { return seedPhrase_1.validateSeedPhrase; } });
|
|
38
|
-
Object.defineProperty(exports, "mnemonicToSeed", { enumerable: true, get: function () { return seedPhrase_1.mnemonicToSeed; } });
|
|
39
|
-
Object.defineProperty(exports, "seedToPassword", { enumerable: true, get: function () { return seedPhrase_1.seedToPassword; } });
|
|
40
|
-
Object.defineProperty(exports, "deriveCredentialsFromMnemonic", { enumerable: true, get: function () { return seedPhrase_1.deriveCredentialsFromMnemonic; } });
|
|
41
|
-
Object.defineProperty(exports, "formatSeedPhrase", { enumerable: true, get: function () { return seedPhrase_1.formatSeedPhrase; } });
|
|
42
|
-
Object.defineProperty(exports, "normalizeSeedPhrase", { enumerable: true, get: function () { return seedPhrase_1.normalizeSeedPhrase; } });
|
|
43
|
-
// Export crypto module
|
|
44
|
-
__exportStar(require("./crypto"), exports);
|
|
45
|
-
// Export managers
|
|
46
|
-
var CryptoIdentityManager_1 = require("./managers/CryptoIdentityManager");
|
|
47
|
-
Object.defineProperty(exports, "CryptoIdentityManager", { enumerable: true, get: function () { return CryptoIdentityManager_1.CryptoIdentityManager; } });
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ShogunEventEmitter = void 0;
|
|
4
|
-
const eventEmitter_1 = require("../utils/eventEmitter");
|
|
5
|
-
/**
|
|
6
|
-
* Extended EventEmitter class with typed events for Shogun
|
|
7
|
-
* @class ShogunEventEmitter
|
|
8
|
-
* @extends EventEmitter
|
|
9
|
-
*/
|
|
10
|
-
class ShogunEventEmitter extends eventEmitter_1.EventEmitter {
|
|
11
|
-
/**
|
|
12
|
-
* Emit a typed Shogun event
|
|
13
|
-
* @template K - Event key type
|
|
14
|
-
* @param {K} event - Event name
|
|
15
|
-
* @param {ShogunEventMap[K]} data - Event data
|
|
16
|
-
* @returns {boolean} - Returns true if the event had listeners, false otherwise
|
|
17
|
-
*/
|
|
18
|
-
emit(event, data) {
|
|
19
|
-
return super.emit(event, data);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Register a listener for a typed Shogun event
|
|
23
|
-
* @template K - Event key type
|
|
24
|
-
* @param {K} event - Event name
|
|
25
|
-
* @param {(data: ShogunEventMap[K]) => void} listener - Event listener function
|
|
26
|
-
*/
|
|
27
|
-
on(event, listener) {
|
|
28
|
-
super.on(event, listener);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Remove a listener for a typed Shogun event
|
|
32
|
-
* @template K - Event key type
|
|
33
|
-
* @param {K} event - Event name
|
|
34
|
-
* @param {(data: ShogunEventMap[K]) => void} listener - Event listener function to remove
|
|
35
|
-
*/
|
|
36
|
-
off(event, listener) {
|
|
37
|
-
super.off(event, listener);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
exports.ShogunEventEmitter = ShogunEventEmitter;
|