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,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ShogunCore Example with Existing Gun Instance
|
|
3
|
+
*
|
|
4
|
+
* This example shows how to use ShogunCore with an existing Gun instance.
|
|
5
|
+
* ShogunCore now requires an existing Gun instance to be passed in.
|
|
6
|
+
*/
|
|
7
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
17
|
+
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);
|
|
18
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
19
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
20
|
+
function step(op) {
|
|
21
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
22
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
23
|
+
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;
|
|
24
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
25
|
+
switch (op[0]) {
|
|
26
|
+
case 0: case 1: t = op; break;
|
|
27
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
28
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
29
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
30
|
+
default:
|
|
31
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
32
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
33
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
34
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
35
|
+
if (t[2]) _.ops.pop();
|
|
36
|
+
_.trys.pop(); continue;
|
|
37
|
+
}
|
|
38
|
+
op = body.call(thisArg, _);
|
|
39
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
40
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
import { Gun } from "../index.js";
|
|
44
|
+
import { ShogunCore } from "../core.js";
|
|
45
|
+
function shogunCoreExample() {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
+
var peers, gunInstance, shogun, db, username, password, signupResult, signupStartTime, signupDuration, error_1, canLogin, loginStartTime, loginResult, loginDuration, error_2, isLoggedInNow, currentUser;
|
|
48
|
+
var _a, _b, _c, _d;
|
|
49
|
+
return __generator(this, function (_e) {
|
|
50
|
+
switch (_e.label) {
|
|
51
|
+
case 0:
|
|
52
|
+
console.log("🚀 ShogunCore Example with Existing Gun Instance\n");
|
|
53
|
+
// === STEP 1: CREATE GUN INSTANCE ===
|
|
54
|
+
console.log("📦 === CREATING GUN INSTANCE ===\n");
|
|
55
|
+
peers = [
|
|
56
|
+
"https://g3ru5bwxmezpuu3ktnoclbpiw4.srv.us/gun",
|
|
57
|
+
"https://5eh4twk2f62autunsje4panime.srv.us/gun",
|
|
58
|
+
];
|
|
59
|
+
console.log("Using peers: ".concat(peers.join(", ")));
|
|
60
|
+
console.log("ℹ️ Note: If peers are unreachable, operations may timeout.");
|
|
61
|
+
console.log(" Consider using localStorage: true for offline testing.\n");
|
|
62
|
+
gunInstance = Gun({
|
|
63
|
+
peers: peers,
|
|
64
|
+
radisk: false,
|
|
65
|
+
localStorage: true, // Enable localStorage for offline operations and faster testing
|
|
66
|
+
// Reduce log noise from SEA verification errors (these are expected when checking invalid credentials)
|
|
67
|
+
log: function () { }, // Disable Gun.js console logging to reduce noise
|
|
68
|
+
});
|
|
69
|
+
console.log("✓ Gun instance created");
|
|
70
|
+
// === STEP 2: INITIALIZE SHOGUN CORE ===
|
|
71
|
+
console.log("\n🔧 === INITIALIZING SHOGUN CORE ===\n");
|
|
72
|
+
shogun = new ShogunCore({
|
|
73
|
+
gunInstance: gunInstance, // Required: existing Gun instance
|
|
74
|
+
webauthn: {
|
|
75
|
+
enabled: true,
|
|
76
|
+
rpName: "ShogunCore Example",
|
|
77
|
+
},
|
|
78
|
+
web3: {
|
|
79
|
+
enabled: true,
|
|
80
|
+
},
|
|
81
|
+
silent: false, // Enable console logs
|
|
82
|
+
});
|
|
83
|
+
console.log("✓ ShogunCore initialized with existing Gun instance");
|
|
84
|
+
// === STEP 3: USE SHOGUN CORE ===
|
|
85
|
+
console.log("\n🎯 === USING SHOGUN CORE ===\n");
|
|
86
|
+
db = shogun.db;
|
|
87
|
+
console.log("Database available:", !!db);
|
|
88
|
+
// Check if user is logged in
|
|
89
|
+
console.log("User logged in:", shogun.isLoggedIn());
|
|
90
|
+
// Example: Sign up a new user
|
|
91
|
+
console.log("\n--- Sign Up Example ---");
|
|
92
|
+
username = "testuser_".concat(Date.now());
|
|
93
|
+
password = "testpass123";
|
|
94
|
+
console.log("Attempting signup for: ".concat(username));
|
|
95
|
+
console.log("⏳ This may take up to 30 seconds if peers are unreachable...\n");
|
|
96
|
+
_e.label = 1;
|
|
97
|
+
case 1:
|
|
98
|
+
_e.trys.push([1, 3, , 4]);
|
|
99
|
+
signupStartTime = Date.now();
|
|
100
|
+
return [4 /*yield*/, shogun.signUp(username, password)];
|
|
101
|
+
case 2:
|
|
102
|
+
signupResult = _e.sent();
|
|
103
|
+
signupDuration = Date.now() - signupStartTime;
|
|
104
|
+
if (signupResult.success) {
|
|
105
|
+
console.log("\u2713 User signed up successfully in ".concat(signupDuration, "ms"));
|
|
106
|
+
console.log(" Username:", signupResult.username);
|
|
107
|
+
console.log(" UserPub:", ((_a = signupResult.userPub) === null || _a === void 0 ? void 0 : _a.substring(0, 20)) + "...");
|
|
108
|
+
console.log(" Has SEA Pair:", !!signupResult.sea);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
console.log("\u274C Sign up failed after ".concat(signupDuration, "ms"));
|
|
112
|
+
console.log(" Error:", signupResult.error);
|
|
113
|
+
console.log("\n💡 Troubleshooting:");
|
|
114
|
+
console.log(" - Check if username already exists");
|
|
115
|
+
console.log(" - Verify network connection to peers");
|
|
116
|
+
console.log(" - Try with localStorage: true for offline testing");
|
|
117
|
+
}
|
|
118
|
+
return [3 /*break*/, 4];
|
|
119
|
+
case 3:
|
|
120
|
+
error_1 = _e.sent();
|
|
121
|
+
console.log("❌ Sign up exception:", error_1);
|
|
122
|
+
console.log(" Error type:", error_1 instanceof Error ? error_1.constructor.name : typeof error_1);
|
|
123
|
+
signupResult = { success: false, error: String(error_1) };
|
|
124
|
+
return [3 /*break*/, 4];
|
|
125
|
+
case 4:
|
|
126
|
+
// Example: Login (only if signup succeeded or user already exists)
|
|
127
|
+
console.log("\n--- Login Example ---");
|
|
128
|
+
canLogin = (signupResult === null || signupResult === void 0 ? void 0 : signupResult.success) || ((_b = signupResult === null || signupResult === void 0 ? void 0 : signupResult.error) === null || _b === void 0 ? void 0 : _b.includes("already"));
|
|
129
|
+
if (!canLogin) return [3 /*break*/, 9];
|
|
130
|
+
if (signupResult === null || signupResult === void 0 ? void 0 : signupResult.success) {
|
|
131
|
+
console.log("✓ User created, attempting login...");
|
|
132
|
+
}
|
|
133
|
+
else if ((_c = signupResult === null || signupResult === void 0 ? void 0 : signupResult.error) === null || _c === void 0 ? void 0 : _c.includes("already")) {
|
|
134
|
+
console.log("ℹ️ User already exists, attempting login...");
|
|
135
|
+
}
|
|
136
|
+
_e.label = 5;
|
|
137
|
+
case 5:
|
|
138
|
+
_e.trys.push([5, 7, , 8]);
|
|
139
|
+
console.log("⏳ Login may take up to 30 seconds if peers are unreachable...");
|
|
140
|
+
loginStartTime = Date.now();
|
|
141
|
+
return [4 /*yield*/, shogun.login(username, password)];
|
|
142
|
+
case 6:
|
|
143
|
+
loginResult = _e.sent();
|
|
144
|
+
loginDuration = Date.now() - loginStartTime;
|
|
145
|
+
if (loginResult.success) {
|
|
146
|
+
console.log("\u2713 User logged in successfully in ".concat(loginDuration, "ms"));
|
|
147
|
+
console.log(" Username:", loginResult.username);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
console.log("\u274C Login failed after ".concat(loginDuration, "ms"));
|
|
151
|
+
console.log(" Error:", loginResult.error);
|
|
152
|
+
console.log("\n💡 Troubleshooting:");
|
|
153
|
+
console.log(" - Verify username and password are correct");
|
|
154
|
+
console.log(" - Check network connection to peers");
|
|
155
|
+
console.log(" - User may not have been created successfully");
|
|
156
|
+
}
|
|
157
|
+
return [3 /*break*/, 8];
|
|
158
|
+
case 7:
|
|
159
|
+
error_2 = _e.sent();
|
|
160
|
+
console.log("❌ Login exception:", error_2);
|
|
161
|
+
return [3 /*break*/, 8];
|
|
162
|
+
case 8: return [3 /*break*/, 10];
|
|
163
|
+
case 9:
|
|
164
|
+
console.log("⚠️ Skipping login - signup failed:", signupResult === null || signupResult === void 0 ? void 0 : signupResult.error);
|
|
165
|
+
_e.label = 10;
|
|
166
|
+
case 10:
|
|
167
|
+
// Example: Check current user
|
|
168
|
+
console.log("\n--- Current User ---");
|
|
169
|
+
isLoggedInNow = shogun.isLoggedIn();
|
|
170
|
+
currentUser = shogun.getCurrentUser();
|
|
171
|
+
console.log("Is logged in:", isLoggedInNow);
|
|
172
|
+
if (currentUser) {
|
|
173
|
+
console.log("Current user:", {
|
|
174
|
+
pub: ((_d = currentUser.pub) === null || _d === void 0 ? void 0 : _d.substring(0, 20)) + "..." || "N/A",
|
|
175
|
+
hasUser: !!currentUser.user,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
console.log("Current user: null (not logged in)");
|
|
180
|
+
}
|
|
181
|
+
// Example: Logout
|
|
182
|
+
console.log("\n--- Logout Example ---");
|
|
183
|
+
if (isLoggedInNow) {
|
|
184
|
+
shogun.logout();
|
|
185
|
+
console.log("✓ User logged out");
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
console.log("ℹ️ No user to logout");
|
|
189
|
+
}
|
|
190
|
+
console.log("\n🎉 Example completed!");
|
|
191
|
+
console.log("\n💡 Tips:");
|
|
192
|
+
console.log(" - Enable localStorage: true for offline testing");
|
|
193
|
+
console.log(" - Use unique usernames to avoid conflicts");
|
|
194
|
+
console.log(" - Timeout errors usually indicate peer connectivity issues");
|
|
195
|
+
return [2 /*return*/];
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
// Run the example
|
|
201
|
+
if (require.main === module) {
|
|
202
|
+
shogunCoreExample().catch(console.error);
|
|
203
|
+
}
|
|
204
|
+
export { shogunCoreExample };
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
// Signal Protocol test
|
|
38
|
+
import { demonstrateSignalProtocol } from "../crypto/index.js";
|
|
39
|
+
// Test Signal Protocol
|
|
40
|
+
function testSignalProtocol() {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
42
|
+
var result, error_1;
|
|
43
|
+
return __generator(this, function (_a) {
|
|
44
|
+
switch (_a.label) {
|
|
45
|
+
case 0:
|
|
46
|
+
_a.trys.push([0, 2, , 3]);
|
|
47
|
+
console.log("📡 Starting Signal Protocol test...");
|
|
48
|
+
return [4 /*yield*/, demonstrateSignalProtocol()];
|
|
49
|
+
case 1:
|
|
50
|
+
result = _a.sent();
|
|
51
|
+
if (result.success) {
|
|
52
|
+
console.log("✅ Signal Protocol test successful!");
|
|
53
|
+
console.log("Alice and Bob have the same secret:", result.aliceSecret === result.bobSecret);
|
|
54
|
+
console.log("One-time prekey used:", result.usedOneTimePrekey);
|
|
55
|
+
console.log("Alice secret (first 20 chars):", result.aliceSecret.substring(0, 20) + "...");
|
|
56
|
+
console.log("Bob secret (first 20 chars):", result.bobSecret.substring(0, 20) + "...");
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
console.log("❌ Signal Protocol test failed");
|
|
60
|
+
}
|
|
61
|
+
return [2 /*return*/, result];
|
|
62
|
+
case 2:
|
|
63
|
+
error_1 = _a.sent();
|
|
64
|
+
console.error("❌ Signal Protocol test error:", error_1);
|
|
65
|
+
return [2 /*return*/, {
|
|
66
|
+
success: false,
|
|
67
|
+
error: error_1 instanceof Error ? error_1.message : "Unknown error",
|
|
68
|
+
}];
|
|
69
|
+
case 3: return [2 /*return*/];
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
// Run the test
|
|
75
|
+
testSignalProtocol()
|
|
76
|
+
.then(function (result) {
|
|
77
|
+
console.log("\n📊 Signal Protocol Result:");
|
|
78
|
+
console.log(JSON.stringify(result, null, 2));
|
|
79
|
+
})
|
|
80
|
+
.catch(function (error) {
|
|
81
|
+
console.error("💥 Signal Protocol test execution failed:", error);
|
|
82
|
+
});
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ZK-Proof Verifiable Credentials Example
|
|
3
|
+
*
|
|
4
|
+
* This demonstrates how to use ZK-Proof for proving attributes
|
|
5
|
+
* about documents and identity without revealing sensitive data
|
|
6
|
+
*/
|
|
7
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
17
|
+
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);
|
|
18
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
19
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
20
|
+
function step(op) {
|
|
21
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
22
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
23
|
+
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;
|
|
24
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
25
|
+
switch (op[0]) {
|
|
26
|
+
case 0: case 1: t = op; break;
|
|
27
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
28
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
29
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
30
|
+
default:
|
|
31
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
32
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
33
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
34
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
35
|
+
if (t[2]) _.ops.pop();
|
|
36
|
+
_.trys.pop(); continue;
|
|
37
|
+
}
|
|
38
|
+
op = body.call(thisArg, _);
|
|
39
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
40
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
import { Gun } from "../index.js";
|
|
44
|
+
import { ShogunCore } from "../core.js";
|
|
45
|
+
import { ZkCredentials, CredentialType, } from "../plugins/zkproof/zkCredentials.js";
|
|
46
|
+
import { Identity } from "@semaphore-protocol/identity";
|
|
47
|
+
// Example 1: Age Verification
|
|
48
|
+
function ageVerificationExample() {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
50
|
+
var peers, shogun, zkPlugin, identity, semaphoreIdentity, zkCreds, birthDate, actualAge, ageProof, verification, error_1;
|
|
51
|
+
return __generator(this, function (_a) {
|
|
52
|
+
switch (_a.label) {
|
|
53
|
+
case 0:
|
|
54
|
+
console.log("=== Age Verification Example ===\n");
|
|
55
|
+
peers = [
|
|
56
|
+
"https://g3ru5bwxmezpuu3ktnoclbpiw4.srv.us/gun",
|
|
57
|
+
"https://5eh4twk2f62autunsje4panime.srv.us/gun",
|
|
58
|
+
];
|
|
59
|
+
shogun = new ShogunCore({
|
|
60
|
+
gunInstance: Gun({ peers: peers }),
|
|
61
|
+
zkproof: { enabled: true },
|
|
62
|
+
});
|
|
63
|
+
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 100); })];
|
|
64
|
+
case 1:
|
|
65
|
+
_a.sent();
|
|
66
|
+
zkPlugin = shogun.getPlugin("zkproof");
|
|
67
|
+
if (!zkPlugin)
|
|
68
|
+
return [2 /*return*/];
|
|
69
|
+
return [4 /*yield*/, zkPlugin.generateIdentity()];
|
|
70
|
+
case 2:
|
|
71
|
+
identity = _a.sent();
|
|
72
|
+
semaphoreIdentity = new Identity(identity.trapdoor);
|
|
73
|
+
zkCreds = new ZkCredentials();
|
|
74
|
+
console.log("Scenario: User wants to prove they're 18+ without revealing birthdate\n");
|
|
75
|
+
birthDate = new Date("1990-05-15");
|
|
76
|
+
actualAge = Math.floor((Date.now() - birthDate.getTime()) / (365.25 * 24 * 60 * 60 * 1000));
|
|
77
|
+
console.log("Private data (NOT revealed):");
|
|
78
|
+
console.log(" Birth date: ".concat(birthDate.toDateString()));
|
|
79
|
+
console.log(" Actual age: ".concat(actualAge, "\n"));
|
|
80
|
+
_a.label = 3;
|
|
81
|
+
case 3:
|
|
82
|
+
_a.trys.push([3, 6, , 7]);
|
|
83
|
+
return [4 /*yield*/, zkCreds.proveAge(semaphoreIdentity, birthDate, 18)];
|
|
84
|
+
case 4:
|
|
85
|
+
ageProof = _a.sent();
|
|
86
|
+
console.log("Public proof generated:");
|
|
87
|
+
console.log(" Claim: \"".concat(ageProof.claim, "\""));
|
|
88
|
+
console.log(" Type: ".concat(ageProof.type));
|
|
89
|
+
console.log(" \u2705 Birth date NOT revealed!");
|
|
90
|
+
console.log(" \u2705 Exact age NOT revealed!");
|
|
91
|
+
return [4 /*yield*/, zkCreds.verifyCredential(ageProof)];
|
|
92
|
+
case 5:
|
|
93
|
+
verification = _a.sent();
|
|
94
|
+
console.log("\nVerification result: ".concat(verification.verified ? "✅ VALID" : "❌ INVALID"));
|
|
95
|
+
return [3 /*break*/, 7];
|
|
96
|
+
case 6:
|
|
97
|
+
error_1 = _a.sent();
|
|
98
|
+
console.log("Note: Full proof generation requires circuit files");
|
|
99
|
+
console.log("Run: yarn setup:zkproof");
|
|
100
|
+
return [3 /*break*/, 7];
|
|
101
|
+
case 7: return [2 /*return*/];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
// Example 2: Citizenship Verification
|
|
107
|
+
function citizenshipExample() {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
109
|
+
var shogun, zkPlugin, identity, semaphoreIdentity, zkCreds, citizenshipProof, error_2;
|
|
110
|
+
return __generator(this, function (_a) {
|
|
111
|
+
switch (_a.label) {
|
|
112
|
+
case 0:
|
|
113
|
+
console.log("\n=== Citizenship Verification Example ===\n");
|
|
114
|
+
shogun = new ShogunCore({
|
|
115
|
+
gunInstance: Gun({ peers: ["https://peer.wallie.io/gun"] }),
|
|
116
|
+
zkproof: { enabled: true },
|
|
117
|
+
});
|
|
118
|
+
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 100); })];
|
|
119
|
+
case 1:
|
|
120
|
+
_a.sent();
|
|
121
|
+
zkPlugin = shogun.getPlugin("zkproof");
|
|
122
|
+
if (!zkPlugin)
|
|
123
|
+
return [2 /*return*/];
|
|
124
|
+
return [4 /*yield*/, zkPlugin.generateIdentity()];
|
|
125
|
+
case 2:
|
|
126
|
+
identity = _a.sent();
|
|
127
|
+
semaphoreIdentity = new Identity(identity.trapdoor);
|
|
128
|
+
zkCreds = new ZkCredentials();
|
|
129
|
+
console.log("Scenario: Prove EU citizenship without revealing country\n");
|
|
130
|
+
console.log("Private data (NOT revealed):");
|
|
131
|
+
console.log(" Country: Italy");
|
|
132
|
+
console.log(" Passport: IT123456789\n");
|
|
133
|
+
_a.label = 3;
|
|
134
|
+
case 3:
|
|
135
|
+
_a.trys.push([3, 5, , 6]);
|
|
136
|
+
return [4 /*yield*/, zkCreds.proveCitizenship(semaphoreIdentity, "Italy", "EU")];
|
|
137
|
+
case 4:
|
|
138
|
+
citizenshipProof = _a.sent();
|
|
139
|
+
console.log("Public proof:");
|
|
140
|
+
console.log(" Claim: \"".concat(citizenshipProof.claim, "\""));
|
|
141
|
+
console.log(" \u2705 Specific country NOT revealed!");
|
|
142
|
+
console.log(" \u2705 Passport number NOT revealed!");
|
|
143
|
+
return [3 /*break*/, 6];
|
|
144
|
+
case 5:
|
|
145
|
+
error_2 = _a.sent();
|
|
146
|
+
console.log("Note: Full proof requires circuit files");
|
|
147
|
+
return [3 /*break*/, 6];
|
|
148
|
+
case 6: return [2 /*return*/];
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
// Example 3: Education Credentials
|
|
154
|
+
function educationExample() {
|
|
155
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
156
|
+
var shogun, zkPlugin, identity, semaphoreIdentity, zkCreds, eduProof, error_3;
|
|
157
|
+
return __generator(this, function (_a) {
|
|
158
|
+
switch (_a.label) {
|
|
159
|
+
case 0:
|
|
160
|
+
console.log("\n=== Education Credential Example ===\n");
|
|
161
|
+
shogun = new ShogunCore({
|
|
162
|
+
gunInstance: Gun({ peers: ["https://peer.wallie.io/gun"] }),
|
|
163
|
+
zkproof: { enabled: true },
|
|
164
|
+
});
|
|
165
|
+
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 100); })];
|
|
166
|
+
case 1:
|
|
167
|
+
_a.sent();
|
|
168
|
+
zkPlugin = shogun.getPlugin("zkproof");
|
|
169
|
+
if (!zkPlugin)
|
|
170
|
+
return [2 /*return*/];
|
|
171
|
+
return [4 /*yield*/, zkPlugin.generateIdentity()];
|
|
172
|
+
case 2:
|
|
173
|
+
identity = _a.sent();
|
|
174
|
+
semaphoreIdentity = new Identity(identity.trapdoor);
|
|
175
|
+
zkCreds = new ZkCredentials();
|
|
176
|
+
console.log("Scenario: Prove you have a degree without revealing details\n");
|
|
177
|
+
console.log("Private data (NOT revealed):");
|
|
178
|
+
console.log(" University: MIT");
|
|
179
|
+
console.log(" Degree: Computer Science");
|
|
180
|
+
console.log(" Year: 2020");
|
|
181
|
+
console.log(" Grade: 110/110\n");
|
|
182
|
+
_a.label = 3;
|
|
183
|
+
case 3:
|
|
184
|
+
_a.trys.push([3, 5, , 6]);
|
|
185
|
+
return [4 /*yield*/, zkCreds.proveEducation(semaphoreIdentity, "Bachelor of Science", "MIT", 2020)];
|
|
186
|
+
case 4:
|
|
187
|
+
eduProof = _a.sent();
|
|
188
|
+
console.log("Public proof:");
|
|
189
|
+
console.log(" Claim: \"".concat(eduProof.claim, "\""));
|
|
190
|
+
console.log(" \u2705 University name NOT revealed!");
|
|
191
|
+
console.log(" \u2705 Grades NOT revealed!");
|
|
192
|
+
console.log(" \u2705 Only proves you HAVE the degree");
|
|
193
|
+
return [3 /*break*/, 6];
|
|
194
|
+
case 5:
|
|
195
|
+
error_3 = _a.sent();
|
|
196
|
+
console.log("Note: Full proof requires circuit files");
|
|
197
|
+
return [3 /*break*/, 6];
|
|
198
|
+
case 6: return [2 /*return*/];
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
// Example 4: Income Verification
|
|
204
|
+
function incomeExample() {
|
|
205
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
206
|
+
var shogun, zkPlugin, identity, semaphoreIdentity, zkCreds, incomeProof, error_4;
|
|
207
|
+
return __generator(this, function (_a) {
|
|
208
|
+
switch (_a.label) {
|
|
209
|
+
case 0:
|
|
210
|
+
console.log("\n=== Income Verification Example ===\n");
|
|
211
|
+
shogun = new ShogunCore({
|
|
212
|
+
gunInstance: Gun({ peers: ["https://peer.wallie.io/gun"] }),
|
|
213
|
+
zkproof: { enabled: true },
|
|
214
|
+
});
|
|
215
|
+
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 100); })];
|
|
216
|
+
case 1:
|
|
217
|
+
_a.sent();
|
|
218
|
+
zkPlugin = shogun.getPlugin("zkproof");
|
|
219
|
+
if (!zkPlugin)
|
|
220
|
+
return [2 /*return*/];
|
|
221
|
+
return [4 /*yield*/, zkPlugin.generateIdentity()];
|
|
222
|
+
case 2:
|
|
223
|
+
identity = _a.sent();
|
|
224
|
+
semaphoreIdentity = new Identity(identity.trapdoor);
|
|
225
|
+
zkCreds = new ZkCredentials();
|
|
226
|
+
console.log("Scenario: Apply for loan proving income > 50k without revealing exact salary\n");
|
|
227
|
+
console.log("Private data (NOT revealed):");
|
|
228
|
+
console.log(" Actual salary: 75,000 EUR");
|
|
229
|
+
console.log(" Employer: Tech Company XYZ\n");
|
|
230
|
+
_a.label = 3;
|
|
231
|
+
case 3:
|
|
232
|
+
_a.trys.push([3, 5, , 6]);
|
|
233
|
+
return [4 /*yield*/, zkCreds.proveIncome(semaphoreIdentity, 75000, 50000, "EUR")];
|
|
234
|
+
case 4:
|
|
235
|
+
incomeProof = _a.sent();
|
|
236
|
+
console.log("Public proof sent to bank:");
|
|
237
|
+
console.log(" Claim: \"".concat(incomeProof.claim, "\""));
|
|
238
|
+
console.log(" \u2705 Exact salary NOT revealed!");
|
|
239
|
+
console.log(" \u2705 Only proves income >= 50,000 EUR");
|
|
240
|
+
console.log("\n Bank sees: \"This person earns at least 50k\"");
|
|
241
|
+
console.log(" Bank does NOT see: Actual amount or employer");
|
|
242
|
+
return [3 /*break*/, 6];
|
|
243
|
+
case 5:
|
|
244
|
+
error_4 = _a.sent();
|
|
245
|
+
console.log("Note: Full proof requires circuit files");
|
|
246
|
+
return [3 /*break*/, 6];
|
|
247
|
+
case 6: return [2 /*return*/];
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
// Example 5: Custom Credential
|
|
253
|
+
function customCredentialExample() {
|
|
254
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
255
|
+
var shogun, zkPlugin, identity, semaphoreIdentity, zkCreds, devProof, error_5;
|
|
256
|
+
return __generator(this, function (_a) {
|
|
257
|
+
switch (_a.label) {
|
|
258
|
+
case 0:
|
|
259
|
+
console.log("\n=== Custom Credential Example ===\n");
|
|
260
|
+
shogun = new ShogunCore({
|
|
261
|
+
gunInstance: Gun({ peers: ["https://peer.wallie.io/gun"] }),
|
|
262
|
+
zkproof: { enabled: true },
|
|
263
|
+
});
|
|
264
|
+
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 100); })];
|
|
265
|
+
case 1:
|
|
266
|
+
_a.sent();
|
|
267
|
+
zkPlugin = shogun.getPlugin("zkproof");
|
|
268
|
+
if (!zkPlugin)
|
|
269
|
+
return [2 /*return*/];
|
|
270
|
+
return [4 /*yield*/, zkPlugin.generateIdentity()];
|
|
271
|
+
case 2:
|
|
272
|
+
identity = _a.sent();
|
|
273
|
+
semaphoreIdentity = new Identity(identity.trapdoor);
|
|
274
|
+
zkCreds = new ZkCredentials();
|
|
275
|
+
console.log("Scenario: Prove you're a verified developer without revealing GitHub profile\n");
|
|
276
|
+
console.log("Private data (NOT revealed):");
|
|
277
|
+
console.log(" GitHub: @johndoe");
|
|
278
|
+
console.log(" Repositories: 150");
|
|
279
|
+
console.log(" Stars: 5,234");
|
|
280
|
+
console.log(" Years active: 8\n");
|
|
281
|
+
_a.label = 3;
|
|
282
|
+
case 3:
|
|
283
|
+
_a.trys.push([3, 5, , 6]);
|
|
284
|
+
return [4 /*yield*/, zkCreds.proveAttribute(semaphoreIdentity, {
|
|
285
|
+
type: CredentialType.CUSTOM,
|
|
286
|
+
claim: "Verified GitHub developer with 5+ years experience",
|
|
287
|
+
privateData: {
|
|
288
|
+
githubUsername: "johndoe",
|
|
289
|
+
repositories: 150,
|
|
290
|
+
stars: 5234,
|
|
291
|
+
yearsActive: 8,
|
|
292
|
+
verified: true,
|
|
293
|
+
},
|
|
294
|
+
})];
|
|
295
|
+
case 4:
|
|
296
|
+
devProof = _a.sent();
|
|
297
|
+
console.log("Public proof:");
|
|
298
|
+
console.log(" Claim: \"".concat(devProof.claim, "\""));
|
|
299
|
+
console.log(" \u2705 GitHub username NOT revealed!");
|
|
300
|
+
console.log(" \u2705 Exact stats NOT revealed!");
|
|
301
|
+
console.log(" \u2705 Privacy-preserving reputation proof");
|
|
302
|
+
return [3 /*break*/, 6];
|
|
303
|
+
case 5:
|
|
304
|
+
error_5 = _a.sent();
|
|
305
|
+
console.log("Note: Full proof requires circuit files");
|
|
306
|
+
return [3 /*break*/, 6];
|
|
307
|
+
case 6: return [2 /*return*/];
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
// Run all examples
|
|
313
|
+
function main() {
|
|
314
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
315
|
+
var error_6;
|
|
316
|
+
return __generator(this, function (_a) {
|
|
317
|
+
switch (_a.label) {
|
|
318
|
+
case 0:
|
|
319
|
+
console.log("🔐 ZK-Proof Verifiable Credentials Examples");
|
|
320
|
+
console.log("==========================================\n");
|
|
321
|
+
_a.label = 1;
|
|
322
|
+
case 1:
|
|
323
|
+
_a.trys.push([1, 7, , 8]);
|
|
324
|
+
return [4 /*yield*/, ageVerificationExample()];
|
|
325
|
+
case 2:
|
|
326
|
+
_a.sent();
|
|
327
|
+
return [4 /*yield*/, citizenshipExample()];
|
|
328
|
+
case 3:
|
|
329
|
+
_a.sent();
|
|
330
|
+
return [4 /*yield*/, educationExample()];
|
|
331
|
+
case 4:
|
|
332
|
+
_a.sent();
|
|
333
|
+
return [4 /*yield*/, incomeExample()];
|
|
334
|
+
case 5:
|
|
335
|
+
_a.sent();
|
|
336
|
+
return [4 /*yield*/, customCredentialExample()];
|
|
337
|
+
case 6:
|
|
338
|
+
_a.sent();
|
|
339
|
+
console.log("\n✨ All credential examples completed!");
|
|
340
|
+
console.log("\nℹ️ Note: These examples show the credential structure.");
|
|
341
|
+
console.log(" For full ZK proof generation, run: yarn setup:zkproof");
|
|
342
|
+
return [3 /*break*/, 8];
|
|
343
|
+
case 7:
|
|
344
|
+
error_6 = _a.sent();
|
|
345
|
+
console.error("\n❌ Error:", error_6);
|
|
346
|
+
return [3 /*break*/, 8];
|
|
347
|
+
case 8:
|
|
348
|
+
process.exit(0);
|
|
349
|
+
return [2 /*return*/];
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
if (require.main === module) {
|
|
355
|
+
main();
|
|
356
|
+
}
|
|
357
|
+
export { ageVerificationExample, citizenshipExample, educationExample, incomeExample, customCredentialExample, };
|