Giter VIP home page Giter VIP logo

Comments (3)

berendsliedrecht avatar berendsliedrecht commented on June 24, 2024 1

Ahhh I see. You are using an interface and not a type.

A type in typescript extends Record<string, unknown> (or {[key: string]: unknown}), but an interface does not. If you swap the Foo to a type, it will work.

Or, you do not define the type Foo and TypeScript will infer the generic of the object you passed in.

create({ foo: "hi!" }, { foo: true, __decoyCount: 1 }).then(console.log);

This has full type completion on the disclosureframe even if Foo is not supplied.

to make the interface with [key: string]: unknown work, I would have to dive into the disclosure frame typing, but for now I'd just suggest to make it a type.

from sd-jwt-ts.

berendsliedrecht avatar berendsliedrecht commented on June 24, 2024

Are you on the latest version? My code succeeds when I try to recreate your example:

import {
  DisclosureFrame,
  HasherAlgorithm,
  SdJwt,
  SignatureAndEncryptionAlgorithm,
} from "jwt-sd";

type JWTHeader = {
  alg: string;
  typ: string;
};

function create<Payload extends Record<string, unknown>>(
  payload: Payload,
  disclosureFrame: DisclosureFrame<Payload>
): Promise<SdJwt<JWTHeader, Payload>> {
  const sdJwt = new SdJwt<JWTHeader, Payload>(
    {
      header: {
        alg: SignatureAndEncryptionAlgorithm.EdDSA,
        typ: "sd-jwt",
      },
      payload: payload,
    },
    {
      saltGenerator: () => "salt",
      signer: () => new Uint8Array(32).fill(42),
      hasherAndAlgorithm: {
        algorithm: HasherAlgorithm.Sha256,
        hasher: () => new Uint8Array(32).fill(32),
      },
      disclosureFrame,
    }
  );
  return Promise.resolve(sdJwt);
}

type Foo = {
  foo: string;
};

create<Foo>({ foo: "hi!" }, { foo: true, __decoyCount: 2 }).then(console.log)

output:

jwt-sd-demo λ npx ts-node index.ts
SdJwt {
  header: { alg: 'EdDSA', typ: 'sd-jwt' },
  payload: { foo: 'hi!' },
  signature: undefined,
  signer: [Function: signer],
  disclosures: undefined,
  keyBinding: undefined,
  hasherAndAlgorithm: { algorithm: 'sha-256', hasher: [Function: hasher] },
  saltGenerator: [Function: saltGenerator],
  disclosureFrame: { foo: true, __decoyCount: 2 }
}

from sd-jwt-ts.

cre8 avatar cre8 commented on June 24, 2024

@berendsliedrecht Ty very much :)

from sd-jwt-ts.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.