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
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
38
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
39
|
+
if (!m) return o;
|
|
40
|
+
var i = m.call(o), r, ar = [], e;
|
|
41
|
+
try {
|
|
42
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
43
|
+
}
|
|
44
|
+
catch (error) { e = { error: error }; }
|
|
45
|
+
finally {
|
|
46
|
+
try {
|
|
47
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
48
|
+
}
|
|
49
|
+
finally { if (e) throw e.error; }
|
|
50
|
+
}
|
|
51
|
+
return ar;
|
|
52
|
+
};
|
|
53
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
54
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
55
|
+
if (ar || !(i in from)) {
|
|
56
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
57
|
+
ar[i] = from[i];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
61
|
+
};
|
|
62
|
+
import { p256 } from "@noble/curves/p256";
|
|
63
|
+
import { secp256k1 } from "@noble/curves/secp256k1";
|
|
64
|
+
import { sha256 } from "@noble/hashes/sha256";
|
|
65
|
+
import { keccak_256 } from "@noble/hashes/sha3";
|
|
66
|
+
import { ripemd160 } from "@noble/hashes/ripemd160";
|
|
67
|
+
export default function (pwd_1, extra_1) {
|
|
68
|
+
return __awaiter(this, arguments, void 0, function (pwd, extra, options) {
|
|
69
|
+
var TEXT_ENCODER, pwdBytes, extras, extraBuf, combinedInput, version, result, _a, includeP256, _b, includeSecp256k1Bitcoin, _c, includeSecp256k1Ethereum, salts, _d, signingKeys, encryptionKeys, bitcoinSalt, bitcoinPrivateKey, bitcoinPublicKey, ethereumSalt, ethereumPrivateKey, ethereumPublicKey;
|
|
70
|
+
var _this = this;
|
|
71
|
+
if (options === void 0) { options = {}; }
|
|
72
|
+
return __generator(this, function (_e) {
|
|
73
|
+
switch (_e.label) {
|
|
74
|
+
case 0:
|
|
75
|
+
TEXT_ENCODER = new TextEncoder();
|
|
76
|
+
pwdBytes = pwd
|
|
77
|
+
? typeof pwd === "string"
|
|
78
|
+
? TEXT_ENCODER.encode(normalizeString(pwd))
|
|
79
|
+
: pwd
|
|
80
|
+
: crypto.getRandomValues(new Uint8Array(32));
|
|
81
|
+
extras = extra
|
|
82
|
+
? (Array.isArray(extra) ? extra : [extra]).map(function (e) {
|
|
83
|
+
return normalizeString(e.toString());
|
|
84
|
+
})
|
|
85
|
+
: [];
|
|
86
|
+
extraBuf = TEXT_ENCODER.encode(extras.join("|"));
|
|
87
|
+
combinedInput = new Uint8Array(pwdBytes.length + extraBuf.length);
|
|
88
|
+
combinedInput.set(pwdBytes);
|
|
89
|
+
combinedInput.set(extraBuf, pwdBytes.length);
|
|
90
|
+
if (combinedInput.length < 16) {
|
|
91
|
+
throw new Error("Insufficient input entropy (".concat(combinedInput.length, ")"));
|
|
92
|
+
}
|
|
93
|
+
version = "v1";
|
|
94
|
+
result = {};
|
|
95
|
+
_a = options.includeP256, includeP256 = _a === void 0 ? true : _a, _b = options.includeSecp256k1Bitcoin, includeSecp256k1Bitcoin = _b === void 0 ? true : _b, _c = options.includeSecp256k1Ethereum, includeSecp256k1Ethereum = _c === void 0 ? true : _c;
|
|
96
|
+
if (!includeP256) return [3 /*break*/, 2];
|
|
97
|
+
salts = [
|
|
98
|
+
{ label: "signing", type: "pub/priv" },
|
|
99
|
+
{ label: "encryption", type: "epub/epriv" },
|
|
100
|
+
];
|
|
101
|
+
return [4 /*yield*/, Promise.all(salts.map(function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
|
|
102
|
+
var salt, privateKey, publicKey;
|
|
103
|
+
var label = _b.label;
|
|
104
|
+
return __generator(this, function (_c) {
|
|
105
|
+
switch (_c.label) {
|
|
106
|
+
case 0:
|
|
107
|
+
salt = TEXT_ENCODER.encode("".concat(label, "-").concat(version));
|
|
108
|
+
return [4 /*yield*/, stretchKey(combinedInput, salt)];
|
|
109
|
+
case 1:
|
|
110
|
+
privateKey = _c.sent();
|
|
111
|
+
if (!p256.utils.isValidPrivateKey(privateKey)) {
|
|
112
|
+
throw new Error("Invalid private key for ".concat(label));
|
|
113
|
+
}
|
|
114
|
+
publicKey = p256.getPublicKey(privateKey, false);
|
|
115
|
+
return [2 /*return*/, {
|
|
116
|
+
pub: keyBufferToJwk(publicKey),
|
|
117
|
+
priv: arrayBufToBase64UrlEncode(privateKey),
|
|
118
|
+
}];
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}); }))];
|
|
122
|
+
case 1:
|
|
123
|
+
_d = __read.apply(void 0, [_e.sent(), 2]), signingKeys = _d[0], encryptionKeys = _d[1];
|
|
124
|
+
// Chiavi P-256 esistenti
|
|
125
|
+
result.pub = signingKeys.pub;
|
|
126
|
+
result.priv = signingKeys.priv;
|
|
127
|
+
result.epub = encryptionKeys.pub;
|
|
128
|
+
result.epriv = encryptionKeys.priv;
|
|
129
|
+
_e.label = 2;
|
|
130
|
+
case 2:
|
|
131
|
+
if (!includeSecp256k1Bitcoin) return [3 /*break*/, 4];
|
|
132
|
+
bitcoinSalt = TEXT_ENCODER.encode("secp256k1-bitcoin-".concat(version));
|
|
133
|
+
return [4 /*yield*/, stretchKey(combinedInput, bitcoinSalt)];
|
|
134
|
+
case 3:
|
|
135
|
+
bitcoinPrivateKey = _e.sent();
|
|
136
|
+
if (!secp256k1.utils.isValidPrivateKey(bitcoinPrivateKey)) {
|
|
137
|
+
throw new Error("Invalid secp256k1 private key for Bitcoin");
|
|
138
|
+
}
|
|
139
|
+
bitcoinPublicKey = secp256k1.getPublicKey(bitcoinPrivateKey, true);
|
|
140
|
+
result.secp256k1Bitcoin = {
|
|
141
|
+
privateKey: bytesToHex(bitcoinPrivateKey),
|
|
142
|
+
publicKey: bytesToHex(bitcoinPublicKey),
|
|
143
|
+
address: deriveP2PKHAddress(bitcoinPublicKey),
|
|
144
|
+
};
|
|
145
|
+
_e.label = 4;
|
|
146
|
+
case 4:
|
|
147
|
+
if (!includeSecp256k1Ethereum) return [3 /*break*/, 6];
|
|
148
|
+
ethereumSalt = TEXT_ENCODER.encode("secp256k1-ethereum-".concat(version));
|
|
149
|
+
return [4 /*yield*/, stretchKey(combinedInput, ethereumSalt)];
|
|
150
|
+
case 5:
|
|
151
|
+
ethereumPrivateKey = _e.sent();
|
|
152
|
+
if (!secp256k1.utils.isValidPrivateKey(ethereumPrivateKey)) {
|
|
153
|
+
throw new Error("Invalid secp256k1 private key for Ethereum");
|
|
154
|
+
}
|
|
155
|
+
ethereumPublicKey = secp256k1.getPublicKey(ethereumPrivateKey, false);
|
|
156
|
+
result.secp256k1Ethereum = {
|
|
157
|
+
privateKey: "0x" + bytesToHex(ethereumPrivateKey),
|
|
158
|
+
publicKey: "0x" + bytesToHex(ethereumPublicKey),
|
|
159
|
+
address: deriveKeccak256Address(ethereumPublicKey),
|
|
160
|
+
};
|
|
161
|
+
_e.label = 6;
|
|
162
|
+
case 6: return [2 /*return*/, result];
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
function arrayBufToBase64UrlEncode(buf) {
|
|
168
|
+
return btoa(String.fromCharCode.apply(String, __spreadArray([], __read(buf), false)))
|
|
169
|
+
.replace(/\//g, "_")
|
|
170
|
+
.replace(/=/g, "")
|
|
171
|
+
.replace(/\+/g, "-");
|
|
172
|
+
}
|
|
173
|
+
function keyBufferToJwk(publicKeyBuffer) {
|
|
174
|
+
if (publicKeyBuffer[0] !== 4)
|
|
175
|
+
throw new Error("Invalid uncompressed public key format");
|
|
176
|
+
return [
|
|
177
|
+
arrayBufToBase64UrlEncode(publicKeyBuffer.slice(1, 33)), // x
|
|
178
|
+
arrayBufToBase64UrlEncode(publicKeyBuffer.slice(33, 65)), // y
|
|
179
|
+
].join(".");
|
|
180
|
+
}
|
|
181
|
+
function normalizeString(str) {
|
|
182
|
+
return str.normalize("NFC").trim();
|
|
183
|
+
}
|
|
184
|
+
function stretchKey(input_1, salt_1) {
|
|
185
|
+
return __awaiter(this, arguments, void 0, function (input, salt, iterations) {
|
|
186
|
+
var baseKey, keyBits, keyBytes, error_1, fallbackKey;
|
|
187
|
+
if (iterations === void 0) { iterations = 300000; }
|
|
188
|
+
return __generator(this, function (_a) {
|
|
189
|
+
switch (_a.label) {
|
|
190
|
+
case 0:
|
|
191
|
+
_a.trys.push([0, 3, , 4]);
|
|
192
|
+
return [4 /*yield*/, crypto.subtle.importKey("raw", input, { name: "PBKDF2" }, false, ["deriveBits"])];
|
|
193
|
+
case 1:
|
|
194
|
+
baseKey = _a.sent();
|
|
195
|
+
return [4 /*yield*/, crypto.subtle.deriveBits({
|
|
196
|
+
name: "PBKDF2",
|
|
197
|
+
salt: salt,
|
|
198
|
+
iterations: iterations,
|
|
199
|
+
hash: "SHA-256",
|
|
200
|
+
}, baseKey, 256)];
|
|
201
|
+
case 2:
|
|
202
|
+
keyBits = _a.sent();
|
|
203
|
+
keyBytes = new Uint8Array(keyBits);
|
|
204
|
+
// Ensure the key is valid for secp256k1
|
|
205
|
+
return [2 /*return*/, ensureValidSecp256k1Key(keyBytes)];
|
|
206
|
+
case 3:
|
|
207
|
+
error_1 = _a.sent();
|
|
208
|
+
fallbackKey = generateFallbackKey(input, salt);
|
|
209
|
+
return [2 /*return*/, ensureValidSecp256k1Key(fallbackKey)];
|
|
210
|
+
case 4: return [2 /*return*/];
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
function generateFallbackKey(input, salt) {
|
|
216
|
+
// Simple deterministic key generation as fallback
|
|
217
|
+
var key = new Uint8Array(32);
|
|
218
|
+
for (var i = 0; i < 32; i++) {
|
|
219
|
+
key[i] = (i * 7 + salt[i % salt.length]) % 256;
|
|
220
|
+
}
|
|
221
|
+
return key;
|
|
222
|
+
}
|
|
223
|
+
function ensureValidSecp256k1Key(keyBytes) {
|
|
224
|
+
// Ensure the key is not all zeros
|
|
225
|
+
if (keyBytes.every(function (byte) { return byte === 0; })) {
|
|
226
|
+
keyBytes[0] = 1;
|
|
227
|
+
}
|
|
228
|
+
// secp256k1 curve order is approximately 2^256 - 2^32 - 2^9 - 2^8 - 2^7 - 2^6 - 2^4 - 1
|
|
229
|
+
var maxValidKey = new Uint8Array([
|
|
230
|
+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
231
|
+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
232
|
+
0xff, 0xff, 0xff, 0xfe, 0xba, 0xae, 0xdc, 0xe6,
|
|
233
|
+
]);
|
|
234
|
+
// If the key is greater than or equal to the curve order, reduce it
|
|
235
|
+
var isGreaterOrEqual = true;
|
|
236
|
+
for (var i = 0; i < 32; i++) {
|
|
237
|
+
if (keyBytes[i] < maxValidKey[i]) {
|
|
238
|
+
isGreaterOrEqual = false;
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
else if (keyBytes[i] > maxValidKey[i]) {
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (isGreaterOrEqual) {
|
|
246
|
+
// Reduce the key by setting it to a safe value
|
|
247
|
+
keyBytes[31] = 0xe5; // Set to a value less than the curve order
|
|
248
|
+
}
|
|
249
|
+
// Additional validation: ensure the key is not too small
|
|
250
|
+
if (keyBytes.every(function (byte) { return byte === 0; }) ||
|
|
251
|
+
keyBytes.every(function (byte) { return byte === 1; })) {
|
|
252
|
+
// Set to a safe default value
|
|
253
|
+
keyBytes.fill(0);
|
|
254
|
+
keyBytes[0] = 0x01;
|
|
255
|
+
keyBytes[31] = 0xff;
|
|
256
|
+
}
|
|
257
|
+
return keyBytes;
|
|
258
|
+
}
|
|
259
|
+
function bytesToHex(bytes) {
|
|
260
|
+
return Array.from(bytes)
|
|
261
|
+
.map(function (b) { return b.toString(16).padStart(2, "0"); })
|
|
262
|
+
.join("");
|
|
263
|
+
}
|
|
264
|
+
// Base58 encoding per Bitcoin
|
|
265
|
+
var BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
266
|
+
function base58Encode(bytes) {
|
|
267
|
+
if (bytes.length === 0)
|
|
268
|
+
return "";
|
|
269
|
+
// Count leading zeros
|
|
270
|
+
var zeros = 0;
|
|
271
|
+
for (var i = 0; i < bytes.length && bytes[i] === 0; i++) {
|
|
272
|
+
zeros++;
|
|
273
|
+
}
|
|
274
|
+
// Convert to base58
|
|
275
|
+
var digits = [0];
|
|
276
|
+
for (var i = zeros; i < bytes.length; i++) {
|
|
277
|
+
var carry = bytes[i];
|
|
278
|
+
for (var j = 0; j < digits.length; j++) {
|
|
279
|
+
carry += digits[j] << 8;
|
|
280
|
+
digits[j] = carry % 58;
|
|
281
|
+
carry = (carry / 58) | 0;
|
|
282
|
+
}
|
|
283
|
+
while (carry > 0) {
|
|
284
|
+
digits.push(carry % 58);
|
|
285
|
+
carry = (carry / 58) | 0;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
// Convert to string
|
|
289
|
+
var result = "";
|
|
290
|
+
for (var i = 0; i < zeros; i++) {
|
|
291
|
+
result += BASE58_ALPHABET[0];
|
|
292
|
+
}
|
|
293
|
+
for (var i = digits.length - 1; i >= 0; i--) {
|
|
294
|
+
result += BASE58_ALPHABET[digits[i]];
|
|
295
|
+
}
|
|
296
|
+
return result;
|
|
297
|
+
}
|
|
298
|
+
function deriveP2PKHAddress(publicKey) {
|
|
299
|
+
// Bitcoin P2PKH address derivation
|
|
300
|
+
// 1. SHA256 hash del public key
|
|
301
|
+
var sha256Hash = sha256(publicKey);
|
|
302
|
+
// 2. RIPEMD160 hash del risultato
|
|
303
|
+
var ripemd160Hash = ripemd160(sha256Hash);
|
|
304
|
+
// 3. Aggiungi version byte (0x00 per mainnet P2PKH)
|
|
305
|
+
var versionedHash = new Uint8Array(21);
|
|
306
|
+
versionedHash[0] = 0x00; // Mainnet P2PKH version
|
|
307
|
+
versionedHash.set(ripemd160Hash, 1);
|
|
308
|
+
// 4. Double SHA256 per checksum
|
|
309
|
+
var checksum = sha256(sha256(versionedHash));
|
|
310
|
+
// 5. Aggiungi i primi 4 byte del checksum
|
|
311
|
+
var addressBytes = new Uint8Array(25);
|
|
312
|
+
addressBytes.set(versionedHash);
|
|
313
|
+
addressBytes.set(checksum.slice(0, 4), 21);
|
|
314
|
+
// 6. Base58 encode
|
|
315
|
+
return base58Encode(addressBytes);
|
|
316
|
+
}
|
|
317
|
+
function deriveKeccak256Address(publicKey) {
|
|
318
|
+
// Ethereum address derivation usando Keccak256
|
|
319
|
+
// 1. Rimuovi il prefix byte (0x04) dalla chiave pubblica non compressa
|
|
320
|
+
var publicKeyWithoutPrefix = publicKey.slice(1);
|
|
321
|
+
// 2. Calcola Keccak256 hash
|
|
322
|
+
var hash = keccak_256(publicKeyWithoutPrefix);
|
|
323
|
+
// 3. Prendi gli ultimi 20 byte
|
|
324
|
+
var address = hash.slice(-20);
|
|
325
|
+
// 4. Aggiungi '0x' prefix e converti in hex
|
|
326
|
+
return "0x" + bytesToHex(address);
|
|
327
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error classes for Gun and Auth
|
|
3
|
+
*/
|
|
4
|
+
var __extends = (this && this.__extends) || (function () {
|
|
5
|
+
var extendStatics = function (d, b) {
|
|
6
|
+
extendStatics = Object.setPrototypeOf ||
|
|
7
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
8
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
9
|
+
return extendStatics(d, b);
|
|
10
|
+
};
|
|
11
|
+
return function (d, b) {
|
|
12
|
+
if (typeof b !== "function" && b !== null)
|
|
13
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
14
|
+
extendStatics(d, b);
|
|
15
|
+
function __() { this.constructor = d; }
|
|
16
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
17
|
+
};
|
|
18
|
+
})();
|
|
19
|
+
/**
|
|
20
|
+
* Base error for Gun
|
|
21
|
+
*/
|
|
22
|
+
var GunError = /** @class */ (function (_super) {
|
|
23
|
+
__extends(GunError, _super);
|
|
24
|
+
function GunError(message) {
|
|
25
|
+
var _this = _super.call(this, message) || this;
|
|
26
|
+
_this.name = "GunError";
|
|
27
|
+
return _this;
|
|
28
|
+
}
|
|
29
|
+
return GunError;
|
|
30
|
+
}(Error));
|
|
31
|
+
export { GunError };
|
|
32
|
+
/**
|
|
33
|
+
* Generic authentication error
|
|
34
|
+
*/
|
|
35
|
+
var AuthError = /** @class */ (function (_super) {
|
|
36
|
+
__extends(AuthError, _super);
|
|
37
|
+
function AuthError(message) {
|
|
38
|
+
var _this = _super.call(this, message) || this;
|
|
39
|
+
_this.name = "AuthError";
|
|
40
|
+
return _this;
|
|
41
|
+
}
|
|
42
|
+
return AuthError;
|
|
43
|
+
}(GunError));
|
|
44
|
+
export { AuthError };
|
|
45
|
+
/**
|
|
46
|
+
* Invalid credentials error
|
|
47
|
+
*/
|
|
48
|
+
var InvalidCredentials = /** @class */ (function (_super) {
|
|
49
|
+
__extends(InvalidCredentials, _super);
|
|
50
|
+
function InvalidCredentials(message) {
|
|
51
|
+
if (message === void 0) { message = "Credenziali non valide"; }
|
|
52
|
+
var _this = _super.call(this, message) || this;
|
|
53
|
+
_this.name = "InvalidCredentials";
|
|
54
|
+
return _this;
|
|
55
|
+
}
|
|
56
|
+
return InvalidCredentials;
|
|
57
|
+
}(AuthError));
|
|
58
|
+
export { InvalidCredentials };
|
|
59
|
+
/**
|
|
60
|
+
* User already exists error
|
|
61
|
+
*/
|
|
62
|
+
var UserExists = /** @class */ (function (_super) {
|
|
63
|
+
__extends(UserExists, _super);
|
|
64
|
+
function UserExists(message) {
|
|
65
|
+
if (message === void 0) { message = "Utente già esistente"; }
|
|
66
|
+
var _this = _super.call(this, message) || this;
|
|
67
|
+
_this.name = "UserExists";
|
|
68
|
+
return _this;
|
|
69
|
+
}
|
|
70
|
+
return UserExists;
|
|
71
|
+
}(AuthError));
|
|
72
|
+
export { UserExists };
|
|
73
|
+
/**
|
|
74
|
+
* Timeout error
|
|
75
|
+
*/
|
|
76
|
+
var TimeoutError = /** @class */ (function (_super) {
|
|
77
|
+
__extends(TimeoutError, _super);
|
|
78
|
+
function TimeoutError(message) {
|
|
79
|
+
if (message === void 0) { message = "Timeout durante l'operazione"; }
|
|
80
|
+
var _this = _super.call(this, message) || this;
|
|
81
|
+
_this.name = "TimeoutError";
|
|
82
|
+
return _this;
|
|
83
|
+
}
|
|
84
|
+
return TimeoutError;
|
|
85
|
+
}(GunError));
|
|
86
|
+
export { TimeoutError };
|
|
87
|
+
/**
|
|
88
|
+
* Multiple authentication error
|
|
89
|
+
*/
|
|
90
|
+
var MultipleAuthError = /** @class */ (function (_super) {
|
|
91
|
+
__extends(MultipleAuthError, _super);
|
|
92
|
+
function MultipleAuthError(message) {
|
|
93
|
+
if (message === void 0) { message = "Autenticazione multipla in corso"; }
|
|
94
|
+
var _this = _super.call(this, message) || this;
|
|
95
|
+
_this.name = "MultipleAuthError";
|
|
96
|
+
return _this;
|
|
97
|
+
}
|
|
98
|
+
return MultipleAuthError;
|
|
99
|
+
}(AuthError));
|
|
100
|
+
export { MultipleAuthError };
|
|
101
|
+
/** Base error related to the network. */
|
|
102
|
+
var NetworkError = /** @class */ (function (_super) {
|
|
103
|
+
__extends(NetworkError, _super);
|
|
104
|
+
function NetworkError() {
|
|
105
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
106
|
+
}
|
|
107
|
+
return NetworkError;
|
|
108
|
+
}(GunError));
|
|
109
|
+
export { NetworkError };
|
|
110
|
+
var withDefaultMessage = function (args, defaultMessage) {
|
|
111
|
+
if (args.length === 0 || (args.length === 1 && !args[0])) {
|
|
112
|
+
args = [defaultMessage];
|
|
113
|
+
}
|
|
114
|
+
return args;
|
|
115
|
+
};
|