Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New SEA features! (many new features) #1400

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

Conversation

akaoio
Copy link

@akaoio akaoio commented Feb 24, 2025

Hello Mark. I'm your old buddy mimiza, it's been a long time. I made some new COOL features:

New features:

Feature 1: Implemented globalThis to make gun, sea work better in Web Worker threads with type=module (es6).

Feature 2: Create a deterministic key pair from a given seed

SEA.pair(null, { seed: "seed" })

Feature 3: Create a deterministic key pair from a given private key

SEA.pair(null, { priv: test1.priv })

Feature 4: Put to user graph without having to be authenticated (provide pair):

var bob = await SEA.pair();
gun.get(`~${bob.pub}`).get('test').put('this is Bob', (ack) => {
  gun.get(`~${bob.pub}`).get('test').once((data) => {
    expect(ack.err).to.not.be.ok()
    expect(data).to.be('this is Bob')
    done();
  })
}, {opt: {authenticator: bob}})

Feature 5: Put to user graph using external authenticator (nested SEA.sign):

var bob = await SEA.pair();
async function authenticator(data) {
  const sig = await SEA.sign(data, bob)
  return sig
}
gun.get(`~${bob.pub}`).get('test').put('this is Bob', (ack) => {
  gun.get(`~${bob.pub}`).get('test').once((data) => {
    expect(ack.err).to.not.be.ok()
    expect(data).to.be('this is Bob')
    done();
  })
}, {opt: {authenticator: authenticator}})

Feature 6: SPECIALS! WebAuthn support: SEA now also support webauthn passkeys. It requires realtime user interaction on browser, so it is impossible to write Nodejs unit tests. So I wrote examples in /examples/webauthn.html and /examples/webauthn.js . User can now put to their gun graph using their webauthn passkey public key and realtime signature.

WebAuthn usage (read the example files for deeper understanding):

const authenticator = async (data) => {
    const challenge = new TextEncoder().encode(data);
    const options = {
        publicKey: {
            challenge,
            rpId: window.location.hostname,
            userVerification: "preferred",
            allowCredentials: [{
                type: "public-key",
                id: credential.rawId
            }],
            timeout: 60000
        }
    };

    const assertion = await navigator.credentials.get(options);
    console.log("SIGNED:", {options, assertion});
    return assertion.response;
};

// Calling webauthn is very simple, just put authenticator in opt.
gun.get(`~${pub}`).get('test').put("hello world", null, { opt: { authenticator }})

// If you are using a cert (SEA.certify) to put to someone else's graph using WebAuthn, call it like this:
gun.get(`~${pub}`).get('test').put("hello world", null, { opt: { authenticator, pub: 'your-pub', cert }})

I also fixed the http.js in examples because it crashes on Windows so often. I removed the "hello people" console.log in gun.js, it's annoying, sorry bro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant