Skip to content

feat: support more than one certificate in the certificate chain when signing an mdoc#137

Open
TimoGlastra wants to merge 2 commits intomainfrom
feat/chain
Open

feat: support more than one certificate in the certificate chain when signing an mdoc#137
TimoGlastra wants to merge 2 commits intomainfrom
feat/chain

Conversation

@TimoGlastra
Copy link
Member

No description provided.

…ficate chain when signing an mdoc

Signed-off-by: Timo Glastra <timo@animo.id>
@changeset-bot
Copy link

changeset-bot bot commented Feb 3, 2026

🦋 Changeset detected

Latest commit: dd98001

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

validityInfo: ValidityInfo | ValidityInfoOptions
deviceKeyInfo: DeviceKeyInfo | DeviceKeyInfoOptions
certificate: Uint8Array
certificates: [Uint8Array, ...Uint8Array[]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the idea of this type, but for me at least I always end up casting my Array<Uint8Array> to [Uint8Array, ...Uint8Array[]] which is rather annoying. If you see the added benefit for the type we can keep it, but it annoys me more in general then it helps.

Copy link
Member Author

@TimoGlastra TimoGlastra Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me it ensures the user of this library needs to think about the length of the chain. If you pass it like this:

{
 certificates: [leafCertificates]
}

It will not complain

But if you pass it like this:

{
  certificates: certificateChain
}

it would require the user to have checked themselves that they have at least one cert. So i like it since it either requires a cast (excplicit) or enforce you to adhrere to the type (explicit)

Copy link
Member

@berendsliedrecht berendsliedrecht Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the type, but checking certificateChain.length > 1 does not transform the type in an "at-least-one-member" type. The example below does not work and still requires casting

function y(arr: [string, ...string[]]) {
    console.log(arr)
}

 const x= ['a']

if(x.length < 1) {
    throw new Error('a')
}

y(x) // <-- ERROR

Copy link
Member Author

@TimoGlastra TimoGlastra Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no agreed, you have to write it in a typescript compatible way. I like this pattern, as it requires your runtime validation to match your compile time validation

function isNonEmptyArray<T extends any>(array: T[]): array is [T, ...T[]] {
  return array.length > 1
}

function assertNonEmptyArray<T extends any>(array: T[]): asserts array is [T, ...T[]] {
  if (array.length === 0) {
  throw new Error('Expected array to at least contain one entry')
}
}

function y(arr: [string, ...string[]]) {
    console.log(arr)
}

 
 const x= ['a']

if (isNonEmptyArray(x)) {
  y(x) // <-- SUCCESS
}

assertNonEmptyArray(x)
y(x) // <-- SUCCESS

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can change it, it's fine

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