Comments (3)
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.
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.
@berendsliedrecht Ty very much :)
from sd-jwt-ts.
Related Issues (15)
- Support disclosure frame for the `SdJwt.present` method HOT 1
- Library should assume default hashing algorithm of sha-256 HOT 1
- dependencies to workspace packages should be updated to actual version before publishing HOT 3
- BaseFrame causes issues when the type is `Record<string, unknown>` HOT 2
- Allow `nonce` to be passed in SD-JWT `verify` method HOT 4
- Confusing usage of pubilcKeyJwk in the verifier interface HOT 1
- Support recursive disclosures HOT 9
- Library should have better interfaces for properties that are required and always present in SD-JWT vcs
- Disclosure frame does not support nested disclosures for array items.
- Duplication between core and subpackages
- Disclosure encoding is lost which may result in incorrect matching HOT 2
- `payload` property serves two purposes
- Test directory contains built .js and .d.ts files
- Key binding JWT does not include add required `_sd_hash` field
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sd-jwt-ts.