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
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* ZK-Proof Verifiable Credentials Example
|
|
4
|
-
*
|
|
5
|
-
* This demonstrates how to use ZK-Proof for proving attributes
|
|
6
|
-
* about documents and identity without revealing sensitive data
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.ageVerificationExample = ageVerificationExample;
|
|
10
|
-
exports.citizenshipExample = citizenshipExample;
|
|
11
|
-
exports.educationExample = educationExample;
|
|
12
|
-
exports.incomeExample = incomeExample;
|
|
13
|
-
exports.customCredentialExample = customCredentialExample;
|
|
14
|
-
const index_1 = require("../index");
|
|
15
|
-
const core_1 = require("../core");
|
|
16
|
-
const zkCredentials_1 = require("../plugins/zkproof/zkCredentials");
|
|
17
|
-
const identity_1 = require("@semaphore-protocol/identity");
|
|
18
|
-
// Example 1: Age Verification
|
|
19
|
-
async function ageVerificationExample() {
|
|
20
|
-
console.log("=== Age Verification Example ===\n");
|
|
21
|
-
const peers = [
|
|
22
|
-
"https://g3ru5bwxmezpuu3ktnoclbpiw4.srv.us/gun",
|
|
23
|
-
"https://5eh4twk2f62autunsje4panime.srv.us/gun",
|
|
24
|
-
];
|
|
25
|
-
const shogun = new core_1.ShogunCore({
|
|
26
|
-
gunInstance: (0, index_1.Gun)({ peers: peers }),
|
|
27
|
-
zkproof: { enabled: true },
|
|
28
|
-
});
|
|
29
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
30
|
-
const zkPlugin = shogun.getPlugin("zkproof");
|
|
31
|
-
if (!zkPlugin)
|
|
32
|
-
return;
|
|
33
|
-
// Create ZK identity
|
|
34
|
-
const identity = await zkPlugin.generateIdentity();
|
|
35
|
-
const semaphoreIdentity = new identity_1.Identity(identity.trapdoor);
|
|
36
|
-
// Create credentials manager
|
|
37
|
-
const zkCreds = new zkCredentials_1.ZkCredentials();
|
|
38
|
-
console.log("Scenario: User wants to prove they're 18+ without revealing birthdate\n");
|
|
39
|
-
// User's actual birthdate (PRIVATE)
|
|
40
|
-
const birthDate = new Date("1990-05-15");
|
|
41
|
-
const actualAge = Math.floor((Date.now() - birthDate.getTime()) / (365.25 * 24 * 60 * 60 * 1000));
|
|
42
|
-
console.log(`Private data (NOT revealed):`);
|
|
43
|
-
console.log(` Birth date: ${birthDate.toDateString()}`);
|
|
44
|
-
console.log(` Actual age: ${actualAge}\n`);
|
|
45
|
-
try {
|
|
46
|
-
// Generate proof that age >= 18 WITHOUT revealing exact age
|
|
47
|
-
const ageProof = await zkCreds.proveAge(semaphoreIdentity, birthDate, 18);
|
|
48
|
-
console.log(`Public proof generated:`);
|
|
49
|
-
console.log(` Claim: "${ageProof.claim}"`);
|
|
50
|
-
console.log(` Type: ${ageProof.type}`);
|
|
51
|
-
console.log(` ✅ Birth date NOT revealed!`);
|
|
52
|
-
console.log(` ✅ Exact age NOT revealed!`);
|
|
53
|
-
// Anyone can verify the proof
|
|
54
|
-
const verification = await zkCreds.verifyCredential(ageProof);
|
|
55
|
-
console.log(`\nVerification result: ${verification.verified ? "✅ VALID" : "❌ INVALID"}`);
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
console.log(`Note: Full proof generation requires circuit files`);
|
|
59
|
-
console.log(`Run: yarn setup:zkproof`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
// Example 2: Citizenship Verification
|
|
63
|
-
async function citizenshipExample() {
|
|
64
|
-
console.log("\n=== Citizenship Verification Example ===\n");
|
|
65
|
-
const shogun = new core_1.ShogunCore({
|
|
66
|
-
gunInstance: (0, index_1.Gun)({ peers: ["https://peer.wallie.io/gun"] }),
|
|
67
|
-
zkproof: { enabled: true },
|
|
68
|
-
});
|
|
69
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
70
|
-
const zkPlugin = shogun.getPlugin("zkproof");
|
|
71
|
-
if (!zkPlugin)
|
|
72
|
-
return;
|
|
73
|
-
const identity = await zkPlugin.generateIdentity();
|
|
74
|
-
const semaphoreIdentity = new identity_1.Identity(identity.trapdoor);
|
|
75
|
-
const zkCreds = new zkCredentials_1.ZkCredentials();
|
|
76
|
-
console.log("Scenario: Prove EU citizenship without revealing country\n");
|
|
77
|
-
console.log(`Private data (NOT revealed):`);
|
|
78
|
-
console.log(` Country: Italy`);
|
|
79
|
-
console.log(` Passport: IT123456789\n`);
|
|
80
|
-
try {
|
|
81
|
-
const citizenshipProof = await zkCreds.proveCitizenship(semaphoreIdentity, "Italy", "EU");
|
|
82
|
-
console.log(`Public proof:`);
|
|
83
|
-
console.log(` Claim: "${citizenshipProof.claim}"`);
|
|
84
|
-
console.log(` ✅ Specific country NOT revealed!`);
|
|
85
|
-
console.log(` ✅ Passport number NOT revealed!`);
|
|
86
|
-
}
|
|
87
|
-
catch (error) {
|
|
88
|
-
console.log(`Note: Full proof requires circuit files`);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
// Example 3: Education Credentials
|
|
92
|
-
async function educationExample() {
|
|
93
|
-
console.log("\n=== Education Credential Example ===\n");
|
|
94
|
-
const shogun = new core_1.ShogunCore({
|
|
95
|
-
gunInstance: (0, index_1.Gun)({ peers: ["https://peer.wallie.io/gun"] }),
|
|
96
|
-
zkproof: { enabled: true },
|
|
97
|
-
});
|
|
98
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
99
|
-
const zkPlugin = shogun.getPlugin("zkproof");
|
|
100
|
-
if (!zkPlugin)
|
|
101
|
-
return;
|
|
102
|
-
const identity = await zkPlugin.generateIdentity();
|
|
103
|
-
const semaphoreIdentity = new identity_1.Identity(identity.trapdoor);
|
|
104
|
-
const zkCreds = new zkCredentials_1.ZkCredentials();
|
|
105
|
-
console.log("Scenario: Prove you have a degree without revealing details\n");
|
|
106
|
-
console.log(`Private data (NOT revealed):`);
|
|
107
|
-
console.log(` University: MIT`);
|
|
108
|
-
console.log(` Degree: Computer Science`);
|
|
109
|
-
console.log(` Year: 2020`);
|
|
110
|
-
console.log(` Grade: 110/110\n`);
|
|
111
|
-
try {
|
|
112
|
-
const eduProof = await zkCreds.proveEducation(semaphoreIdentity, "Bachelor of Science", "MIT", 2020);
|
|
113
|
-
console.log(`Public proof:`);
|
|
114
|
-
console.log(` Claim: "${eduProof.claim}"`);
|
|
115
|
-
console.log(` ✅ University name NOT revealed!`);
|
|
116
|
-
console.log(` ✅ Grades NOT revealed!`);
|
|
117
|
-
console.log(` ✅ Only proves you HAVE the degree`);
|
|
118
|
-
}
|
|
119
|
-
catch (error) {
|
|
120
|
-
console.log(`Note: Full proof requires circuit files`);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
// Example 4: Income Verification
|
|
124
|
-
async function incomeExample() {
|
|
125
|
-
console.log("\n=== Income Verification Example ===\n");
|
|
126
|
-
const shogun = new core_1.ShogunCore({
|
|
127
|
-
gunInstance: (0, index_1.Gun)({ peers: ["https://peer.wallie.io/gun"] }),
|
|
128
|
-
zkproof: { enabled: true },
|
|
129
|
-
});
|
|
130
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
131
|
-
const zkPlugin = shogun.getPlugin("zkproof");
|
|
132
|
-
if (!zkPlugin)
|
|
133
|
-
return;
|
|
134
|
-
const identity = await zkPlugin.generateIdentity();
|
|
135
|
-
const semaphoreIdentity = new identity_1.Identity(identity.trapdoor);
|
|
136
|
-
const zkCreds = new zkCredentials_1.ZkCredentials();
|
|
137
|
-
console.log("Scenario: Apply for loan proving income > 50k without revealing exact salary\n");
|
|
138
|
-
console.log(`Private data (NOT revealed):`);
|
|
139
|
-
console.log(` Actual salary: 75,000 EUR`);
|
|
140
|
-
console.log(` Employer: Tech Company XYZ\n`);
|
|
141
|
-
try {
|
|
142
|
-
const incomeProof = await zkCreds.proveIncome(semaphoreIdentity, 75000, 50000, "EUR");
|
|
143
|
-
console.log(`Public proof sent to bank:`);
|
|
144
|
-
console.log(` Claim: "${incomeProof.claim}"`);
|
|
145
|
-
console.log(` ✅ Exact salary NOT revealed!`);
|
|
146
|
-
console.log(` ✅ Only proves income >= 50,000 EUR`);
|
|
147
|
-
console.log(`\n Bank sees: "This person earns at least 50k"`);
|
|
148
|
-
console.log(` Bank does NOT see: Actual amount or employer`);
|
|
149
|
-
}
|
|
150
|
-
catch (error) {
|
|
151
|
-
console.log(`Note: Full proof requires circuit files`);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
// Example 5: Custom Credential
|
|
155
|
-
async function customCredentialExample() {
|
|
156
|
-
console.log("\n=== Custom Credential Example ===\n");
|
|
157
|
-
const shogun = new core_1.ShogunCore({
|
|
158
|
-
gunInstance: (0, index_1.Gun)({ peers: ["https://peer.wallie.io/gun"] }),
|
|
159
|
-
zkproof: { enabled: true },
|
|
160
|
-
});
|
|
161
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
162
|
-
const zkPlugin = shogun.getPlugin("zkproof");
|
|
163
|
-
if (!zkPlugin)
|
|
164
|
-
return;
|
|
165
|
-
const identity = await zkPlugin.generateIdentity();
|
|
166
|
-
const semaphoreIdentity = new identity_1.Identity(identity.trapdoor);
|
|
167
|
-
const zkCreds = new zkCredentials_1.ZkCredentials();
|
|
168
|
-
console.log("Scenario: Prove you're a verified developer without revealing GitHub profile\n");
|
|
169
|
-
console.log(`Private data (NOT revealed):`);
|
|
170
|
-
console.log(` GitHub: @johndoe`);
|
|
171
|
-
console.log(` Repositories: 150`);
|
|
172
|
-
console.log(` Stars: 5,234`);
|
|
173
|
-
console.log(` Years active: 8\n`);
|
|
174
|
-
try {
|
|
175
|
-
const devProof = await zkCreds.proveAttribute(semaphoreIdentity, {
|
|
176
|
-
type: zkCredentials_1.CredentialType.CUSTOM,
|
|
177
|
-
claim: "Verified GitHub developer with 5+ years experience",
|
|
178
|
-
privateData: {
|
|
179
|
-
githubUsername: "johndoe",
|
|
180
|
-
repositories: 150,
|
|
181
|
-
stars: 5234,
|
|
182
|
-
yearsActive: 8,
|
|
183
|
-
verified: true,
|
|
184
|
-
},
|
|
185
|
-
});
|
|
186
|
-
console.log(`Public proof:`);
|
|
187
|
-
console.log(` Claim: "${devProof.claim}"`);
|
|
188
|
-
console.log(` ✅ GitHub username NOT revealed!`);
|
|
189
|
-
console.log(` ✅ Exact stats NOT revealed!`);
|
|
190
|
-
console.log(` ✅ Privacy-preserving reputation proof`);
|
|
191
|
-
}
|
|
192
|
-
catch (error) {
|
|
193
|
-
console.log(`Note: Full proof requires circuit files`);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
// Run all examples
|
|
197
|
-
async function main() {
|
|
198
|
-
console.log("🔐 ZK-Proof Verifiable Credentials Examples");
|
|
199
|
-
console.log("==========================================\n");
|
|
200
|
-
try {
|
|
201
|
-
await ageVerificationExample();
|
|
202
|
-
await citizenshipExample();
|
|
203
|
-
await educationExample();
|
|
204
|
-
await incomeExample();
|
|
205
|
-
await customCredentialExample();
|
|
206
|
-
console.log("\n✨ All credential examples completed!");
|
|
207
|
-
console.log("\nℹ️ Note: These examples show the credential structure.");
|
|
208
|
-
console.log(" For full ZK proof generation, run: yarn setup:zkproof");
|
|
209
|
-
}
|
|
210
|
-
catch (error) {
|
|
211
|
-
console.error("\n❌ Error:", error);
|
|
212
|
-
}
|
|
213
|
-
process.exit(0);
|
|
214
|
-
}
|
|
215
|
-
if (require.main === module) {
|
|
216
|
-
main();
|
|
217
|
-
}
|
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Zero-Knowledge Proof Authentication Example
|
|
4
|
-
*
|
|
5
|
-
* This example demonstrates how to use the ZK-Proof plugin with Shogun Core
|
|
6
|
-
* for privacy-preserving authentication using Semaphore protocol.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.basicExample = basicExample;
|
|
10
|
-
exports.deterministicExample = deterministicExample;
|
|
11
|
-
exports.proofExample = proofExample;
|
|
12
|
-
exports.multiDeviceExample = multiDeviceExample;
|
|
13
|
-
const index_1 = require("../index");
|
|
14
|
-
const core_1 = require("../core");
|
|
15
|
-
// Example 1: Basic ZK-Proof signup and login
|
|
16
|
-
async function basicExample() {
|
|
17
|
-
console.log("=== Basic ZK-Proof Authentication Example ===\n");
|
|
18
|
-
const gunInstance = (0, index_1.Gun)({
|
|
19
|
-
peers: [
|
|
20
|
-
"https://g3ru5bwxmezpuu3ktnoclbpiw4.srv.us/gun",
|
|
21
|
-
"https://5eh4twk2f62autunsje4panime.srv.us/gun",
|
|
22
|
-
],
|
|
23
|
-
radisk: false,
|
|
24
|
-
localStorage: false, // Enable for testing - allows offline operations
|
|
25
|
-
// Reduce log noise from SEA verification errors (these are expected when checking invalid credentials)
|
|
26
|
-
log: () => { }, // Disable Gun.js console logging to reduce noise
|
|
27
|
-
});
|
|
28
|
-
// Initialize Shogun with ZK-Proof plugin
|
|
29
|
-
const shogun = new core_1.ShogunCore({
|
|
30
|
-
gunInstance: gunInstance,
|
|
31
|
-
zkproof: {
|
|
32
|
-
enabled: true,
|
|
33
|
-
defaultGroupId: "my-app-users",
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
// Wait for plugin initialization
|
|
37
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
38
|
-
// Get the ZK-Proof plugin
|
|
39
|
-
const zkPlugin = shogun.getPlugin("zkproof");
|
|
40
|
-
if (!zkPlugin) {
|
|
41
|
-
console.error("ZK-Proof plugin not available");
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
// SIGN UP - Generate new anonymous identity
|
|
45
|
-
console.log("1. Creating new ZK identity...");
|
|
46
|
-
const signupResult = await zkPlugin.signUp();
|
|
47
|
-
if (signupResult.success) {
|
|
48
|
-
console.log("✅ Signup successful!");
|
|
49
|
-
console.log(` Username (commitment): ${signupResult.username}`);
|
|
50
|
-
console.log(` User Public Key: ${signupResult.userPub?.slice(0, 16)}...`);
|
|
51
|
-
console.log("\n⚠️ CRITICAL: Save this trapdoor for account recovery:");
|
|
52
|
-
console.log(` Trapdoor: ${signupResult.seedPhrase}\n`);
|
|
53
|
-
// Simulate user saving the trapdoor
|
|
54
|
-
const savedTrapdoor = signupResult.seedPhrase;
|
|
55
|
-
// Logout
|
|
56
|
-
shogun.logout();
|
|
57
|
-
console.log("2. Logged out\n");
|
|
58
|
-
// LOGIN - Authenticate with trapdoor
|
|
59
|
-
console.log("3. Logging in with trapdoor...");
|
|
60
|
-
const loginResult = await zkPlugin.login(savedTrapdoor);
|
|
61
|
-
if (loginResult.success) {
|
|
62
|
-
console.log("✅ Login successful!");
|
|
63
|
-
console.log(` Username: ${loginResult.username}`);
|
|
64
|
-
console.log(` User Public Key: ${loginResult.userPub?.slice(0, 16)}...`);
|
|
65
|
-
console.log(` Auth Method: ${loginResult.authMethod}`);
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
console.error("❌ Login failed:", loginResult.error);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
console.error("❌ Signup failed:", signupResult.error);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
// Example 2: Deterministic identity generation
|
|
76
|
-
async function deterministicExample() {
|
|
77
|
-
console.log("\n=== Deterministic ZK Identity Example ===\n");
|
|
78
|
-
const gunInstance = (0, index_1.Gun)({
|
|
79
|
-
peers: [
|
|
80
|
-
"https://lindanode.scobrudot.dev/gun",
|
|
81
|
-
"https://shogunnode.scobrudot.dev/gun",
|
|
82
|
-
],
|
|
83
|
-
radisk: false,
|
|
84
|
-
localStorage: false, // Enable for testing - allows offline operations
|
|
85
|
-
// Reduce log noise from SEA verification errors (these are expected when checking invalid credentials)
|
|
86
|
-
log: () => { }, // Disable Gun.js console logging to reduce noise
|
|
87
|
-
});
|
|
88
|
-
const shogun = new core_1.ShogunCore({
|
|
89
|
-
gunInstance: gunInstance,
|
|
90
|
-
zkproof: {
|
|
91
|
-
enabled: true,
|
|
92
|
-
deterministic: true,
|
|
93
|
-
},
|
|
94
|
-
});
|
|
95
|
-
// Wait for plugin initialization
|
|
96
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
97
|
-
const zkPlugin = shogun.getPlugin("zkproof");
|
|
98
|
-
if (!zkPlugin) {
|
|
99
|
-
console.error("ZK-Proof plugin not available");
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
// Use a seed for deterministic generation
|
|
103
|
-
const seed = "my-secret-seed-phrase-12345";
|
|
104
|
-
console.log("1. Creating identity from seed...");
|
|
105
|
-
const signupResult = await zkPlugin.signUp(seed);
|
|
106
|
-
if (signupResult.success) {
|
|
107
|
-
console.log("✅ Identity created from seed");
|
|
108
|
-
console.log(` Commitment: ${signupResult.username}`);
|
|
109
|
-
// With the same seed, you'll always get the same identity
|
|
110
|
-
const identity2 = await zkPlugin.generateIdentity(seed);
|
|
111
|
-
console.log("\n2. Regenerating from same seed...");
|
|
112
|
-
console.log(` Same commitment? ${identity2.commitment === signupResult.username?.replace("zk_", "")}`);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
// Example 3: Generate and verify ZK proofs
|
|
116
|
-
async function proofExample() {
|
|
117
|
-
console.log("\n=== ZK Proof Generation & Verification Example ===\n");
|
|
118
|
-
const gunInstance = (0, index_1.Gun)({
|
|
119
|
-
peers: [
|
|
120
|
-
"https://lindanode.scobrudot.dev/gun",
|
|
121
|
-
"https://shogunnode.scobrudot.dev/gun",
|
|
122
|
-
],
|
|
123
|
-
radisk: false,
|
|
124
|
-
localStorage: false, // Enable for testing - allows offline operations
|
|
125
|
-
// Reduce log noise from SEA verification errors (these are expected when checking invalid credentials)
|
|
126
|
-
log: () => { }, // Disable Gun.js console logging to reduce noise
|
|
127
|
-
});
|
|
128
|
-
const shogun = new core_1.ShogunCore({
|
|
129
|
-
gunInstance: gunInstance,
|
|
130
|
-
zkproof: {
|
|
131
|
-
enabled: true,
|
|
132
|
-
defaultGroupId: "proof-demo-group",
|
|
133
|
-
},
|
|
134
|
-
});
|
|
135
|
-
// Wait for plugin initialization
|
|
136
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
137
|
-
const zkPlugin = shogun.getPlugin("zkproof");
|
|
138
|
-
if (!zkPlugin) {
|
|
139
|
-
console.error("ZK-Proof plugin not available");
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
// Create identity
|
|
143
|
-
console.log("1. Generating identity...");
|
|
144
|
-
const identity = await zkPlugin.generateIdentity();
|
|
145
|
-
console.log(` Commitment: ${identity.commitment.slice(0, 16)}...`);
|
|
146
|
-
// Add to group
|
|
147
|
-
console.log("\n2. Adding to group...");
|
|
148
|
-
zkPlugin.addToGroup(identity.commitment, "proof-demo-group");
|
|
149
|
-
// Generate proof of membership
|
|
150
|
-
console.log("\n3. Generating ZK proof...");
|
|
151
|
-
const proof = await zkPlugin.generateProof(identity, {
|
|
152
|
-
groupId: "proof-demo-group",
|
|
153
|
-
message: "I am a member of this group",
|
|
154
|
-
scope: "membership-verification",
|
|
155
|
-
});
|
|
156
|
-
console.log(" Proof generated!");
|
|
157
|
-
console.log(` Merkle root: ${proof.merkleTreeRoot.slice(0, 16)}...`);
|
|
158
|
-
console.log(` Nullifier hash: ${proof.nullifierHash.slice(0, 16)}...`);
|
|
159
|
-
// Verify the proof
|
|
160
|
-
console.log("\n4. Verifying proof...");
|
|
161
|
-
const verificationResult = await zkPlugin.verifyProof(proof);
|
|
162
|
-
if (verificationResult.verified) {
|
|
163
|
-
console.log("✅ Proof verified successfully!");
|
|
164
|
-
console.log(" User proved group membership without revealing identity");
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
console.error("❌ Proof verification failed");
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
// Example 4: Multi-device scenario
|
|
171
|
-
async function multiDeviceExample() {
|
|
172
|
-
console.log("\n=== Multi-Device ZK Authentication Example ===\n");
|
|
173
|
-
// Device 1: Create account
|
|
174
|
-
console.log("📱 DEVICE 1: Creating account...");
|
|
175
|
-
const gunInstance1 = (0, index_1.Gun)({
|
|
176
|
-
peers: [
|
|
177
|
-
"https://lindanode.scobrudot.dev/gun",
|
|
178
|
-
"https://shogunnode.scobrudot.dev/gun",
|
|
179
|
-
],
|
|
180
|
-
radisk: false,
|
|
181
|
-
localStorage: false, // Enable for testing - allows offline operations
|
|
182
|
-
// Reduce log noise from SEA verification errors (these are expected when checking invalid credentials)
|
|
183
|
-
log: () => { }, // Disable Gun.js console logging to reduce noise
|
|
184
|
-
});
|
|
185
|
-
const shogun1 = new core_1.ShogunCore({
|
|
186
|
-
gunInstance: gunInstance1,
|
|
187
|
-
zkproof: { enabled: true },
|
|
188
|
-
});
|
|
189
|
-
// Wait for plugin initialization
|
|
190
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
191
|
-
const zkPlugin1 = shogun1.getPlugin("zkproof");
|
|
192
|
-
const signupResult = await zkPlugin1.signUp();
|
|
193
|
-
console.log("✅ Account created on Device 1");
|
|
194
|
-
console.log(` Commitment: ${signupResult.username}`);
|
|
195
|
-
// User writes down the trapdoor
|
|
196
|
-
const trapdoor = signupResult.seedPhrase;
|
|
197
|
-
console.log(`\n📝 User writes down trapdoor: ${trapdoor.slice(0, 20)}...`);
|
|
198
|
-
// Device 2: Import account
|
|
199
|
-
console.log("\n💻 DEVICE 2: Importing account with trapdoor...");
|
|
200
|
-
const gunInstance2 = (0, index_1.Gun)({
|
|
201
|
-
peers: [
|
|
202
|
-
"https://lindanode.scobrudot.dev/gun",
|
|
203
|
-
"https://shogunnode.scobrudot.dev/gun",
|
|
204
|
-
],
|
|
205
|
-
radisk: false,
|
|
206
|
-
localStorage: false, // Enable for testing - allows offline operations
|
|
207
|
-
// Reduce log noise from SEA verification errors (these are expected when checking invalid credentials)
|
|
208
|
-
log: () => { }, // Disable Gun.js console logging to reduce noise
|
|
209
|
-
});
|
|
210
|
-
const shogun2 = new core_1.ShogunCore({
|
|
211
|
-
gunInstance: gunInstance2,
|
|
212
|
-
zkproof: { enabled: true },
|
|
213
|
-
});
|
|
214
|
-
// Wait for plugin initialization
|
|
215
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
216
|
-
const zkPlugin2 = shogun2.getPlugin("zkproof");
|
|
217
|
-
const loginResult = await zkPlugin2.login(trapdoor);
|
|
218
|
-
if (loginResult.success) {
|
|
219
|
-
console.log("✅ Successfully logged in on Device 2");
|
|
220
|
-
console.log(` Same user: ${loginResult.username === signupResult.username}`);
|
|
221
|
-
console.log("\n🎉 Multi-device authentication working!");
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
// Run examples
|
|
225
|
-
async function main() {
|
|
226
|
-
try {
|
|
227
|
-
// Run all examples
|
|
228
|
-
await basicExample();
|
|
229
|
-
await deterministicExample();
|
|
230
|
-
// await proofExample(); // Requires ZK circuit files - see README for setup
|
|
231
|
-
await multiDeviceExample();
|
|
232
|
-
console.log("\n✨ All examples completed successfully!");
|
|
233
|
-
}
|
|
234
|
-
catch (error) {
|
|
235
|
-
console.error("\n❌ Error running examples:", error);
|
|
236
|
-
}
|
|
237
|
-
process.exit(0);
|
|
238
|
-
}
|
|
239
|
-
// Run if executed directly
|
|
240
|
-
if (require.main === module) {
|
|
241
|
-
main();
|
|
242
|
-
}
|