shogun-core
Version:
SHOGUN SDK - Core library for Shogun SDK
115 lines (114 loc) • 5.26 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const gun_1 = __importDefault(require("gun"));
const webauthn_1 = require("./webauthn");
const webauthnSigner_1 = require("./webauthnSigner");
const webauthnChain = () => {
const webauthn = new webauthn_1.Webauthn();
const signer = new webauthnSigner_1.WebAuthnSigner(webauthn);
gun_1.default.chain.webauthn = {};
gun_1.default.chain.webauthn.isSupported = function () {
return webauthn.isSupported();
};
gun_1.default.chain.webauthn.createAccount = async function (username, credentials = null, isNewDevice = false) {
return await webauthn.createAccount(username, credentials, isNewDevice);
};
gun_1.default.chain.webauthn.authenticateUser = async function (username, salt, options = {}) {
return await webauthn.authenticateUser(username, salt, options);
};
gun_1.default.chain.webauthn.generateCredentials = async function (username, existingCredential = null, isLogin = false) {
return await webauthn.generateCredentials(username, existingCredential, isLogin);
};
gun_1.default.chain.webauthn.abortAuthentication = function () {
return webauthn.abortAuthentication();
};
gun_1.default.chain.webauthn.removeDevice = async function (username, credentialId, credentials) {
return await webauthn.removeDevice(username, credentialId, credentials);
};
gun_1.default.chain.webauthn.sign = async function (data) {
return await webauthn.sign(data);
};
gun_1.default.chain.webauthn.validateUsername = function (username) {
return webauthn.validateUsername(username);
};
gun_1.default.chain.webauthn.createSigningCredential = async function (username) {
return await signer.createSigningCredential(username);
};
gun_1.default.chain.webauthn.createAuthenticator = function (credentialId) {
return signer.createAuthenticator(credentialId);
};
gun_1.default.chain.webauthn.createDerivedKeyPair = async function (credentialId, username, extra) {
return await signer.createDerivedKeyPair(credentialId, username, extra);
};
gun_1.default.chain.webauthn.signWithDerivedKeys = async function (data, credentialId, username, extra) {
return await signer.signWithDerivedKeys(data, credentialId, username, extra);
};
gun_1.default.chain.webauthn.getSigningCredential = function (credentialId) {
return signer.getCredential(credentialId);
};
gun_1.default.chain.webauthn.listSigningCredentials = function () {
return signer.listCredentials();
};
gun_1.default.chain.webauthn.removeSigningCredential = function (credentialId) {
return signer.removeCredential(credentialId);
};
gun_1.default.chain.webauthn.setupOneshotSigning = async function (username) {
const credential = await signer.createSigningCredential(username);
const authenticator = signer.createAuthenticator(credential.id);
return {
credential,
authenticator,
pub: credential.pub,
};
};
gun_1.default.chain.webauthn.quickSign = async function (data, credentialId, username, extra) {
return await signer.signWithDerivedKeys(data, credentialId, username, extra);
};
// === CONSISTENCY METHODS ===
/**
* Creates a Gun user from WebAuthn signing credential
* Ensures SAME user as normal approach
*/
gun_1.default.chain.webauthn.createGunUserFromSigningCredential =
async function (credentialId, username) {
return await signer.createGunUser(credentialId, username, this);
};
/**
* Get the Gun user public key for a signing credential
*/
gun_1.default.chain.webauthn.getGunUserPubFromSigningCredential = function (credentialId) {
return signer.getGunUserPub(credentialId);
};
/**
* Get the hashed credential ID (for consistency checking)
*/
gun_1.default.chain.webauthn.getHashedCredentialId = function (credentialId) {
return signer.getHashedCredentialId(credentialId);
};
/**
* Verify consistency between oneshot and normal approaches
*/
gun_1.default.chain.webauthn.verifyConsistency = async function (credentialId, username, expectedUserPub) {
return await signer.verifyConsistency(credentialId, username, expectedUserPub);
};
/**
* Complete consistent oneshot signing workflow
* Creates the SAME Gun user as normal approach
*/
gun_1.default.chain.webauthn.setupConsistentOneshotSigning = async function (username) {
const credential = await signer.createSigningCredential(username);
const authenticator = signer.createAuthenticator(credential.id);
const gunUser = await signer.createGunUser(credential.id, username, this);
return {
credential,
authenticator,
gunUser,
pub: credential.pub,
hashedCredentialId: credential.hashedCredentialId,
};
};
};
exports.default = webauthnChain;