Skip to content

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.

@amark
Copy link
Owner

amark commented Mar 8, 2025

@akaoio @mimiza w000000000 just landed back home, sorry GitHub doesn't notify me anymore. This looks awesome, let's jump on a call to review? DM me on twitter or telegram or whatsapp? (actually, starting a new GUN dev chat on twitter would like to add you to!)

console.log gonna stay until I'm not poor :P

@akaoio
Copy link
Author

akaoio commented Mar 9, 2025

@amark Yo let's talk on telegram, my id is @hpoqou (it's nobody upside down). X suspended my account.

@akaoio akaoio changed the base branch from master to sea-webauthn March 24, 2025 18:39
@amark
Copy link
Owner

amark commented Mar 24, 2025

just finished doing a screen call with you, making a temporary branch to merge and refactor a few things then will review with you again. Awesome work, MIND BLOWING were able to finally get WebAuthn to sign data, this'll be epic. Please pester to finish the refactor & merging.

@amark amark merged commit f0cce07 into amark:sea-webauthn Mar 24, 2025
@akaoio
Copy link
Author

akaoio commented Mar 25, 2025

Yeah glad we finally made one step closer to the big merge

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.

2 participants