openwallet-foundation / sd-jwt-js

A JavaScript implementation of the Selective Disclosure JWT (SD-JWT) spec.
https://sdjwt.js.org/
Apache License 2.0
44 stars 13 forks source link

Unable to retrieve presentable keys from a valid SD-JWT compact string #195

Closed Marcjazz closed 7 months ago

Marcjazz commented 7 months ago

I'm trying to retrieve presentable keys from an SD JWT compact string but I keep getting an empty array though the sdjwt.decode(sdjwtCompact) clearing affirm they're disclosures within the sdjwtCompact. Here my sample code

const sdjwtCompact = `eyJraWQiOiJKMUZ3SlA4N0M2LVFOX1dTSU9tSkFRYzZuNUNRX2JaZGFGSjVHRG5XMVJrIiwidHlwIjoidmMrc2Qtand0IiwiYWxnIjoiRVMyNTYifQ.eyJfc2QiOlsiMWM5ZUpBTzNEVm1NOTBMOU9xWjRoaWVudHFGaVQ0U1ZueUV2SzIxTzdRQSIsIjY5N3ZyRnRSNUFkWWMwTlg4cFBwNUN2WkN3V196d3VPTGxBV1dDM2c0c00iLCI2dENSazJjWUdqSDlLRmlidmlCYnNrUzdUem5qcW5Lb0Vab1MycFMtWENVIiwiRGFadVhKM3FtR2p1OFlvdkkyNFZGUnBhUzMyREFMV1RQd2RzVXQwcUtvWSIsIkhVRnRMaTFRR2p0XzUxVjlkcmlNYzJISjdaSTQ1WkNGRXFSTUloNUdjUEUiLCJJWjliSWNDSUtuaEYyOFZGQnM4TlNQUk5rWlU5cTBFT01hRW1ySE9FRVp3IiwiUzNqYk9VWS1RWUllVVlwZEsyXzVUZnZURUdJZ3B0VU9vTDJhRE5HdU5WcyIsIlc5SDUtU2FWRV91RnBNYWdXNi1ULThCWGRaS1gzUUpzeUVBd3VtOE9PUEEiXSwidmN0IjoiaHR0cHM6Ly9jcmVkZW50aWFscy5leGFtcGxlLmNvbS9pZGVudGl0eV9jcmVkZW50aWFsIiwiX3NkX2FsZyI6InNoYS0yNTYiLCJpc3MiOiJodHRwczovL3RyaWFsLmF1dGhsZXRlLm5ldCIsImNuZiI6eyJqd2siOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsImtpZCI6Ik5QSG44V0RWbUtHeGdiY25QSzdHMjRWa0V2UDQ3LS1lS2h3R1hiU3A0bWMiLCJ4IjoiNkZISllzSTBieTkxWFNsbERTSE1OUzIwUmx3NkxyUE5tUEFSN2phZGVGcyIsInkiOiJnSmlIQ0RQMWpiQUtfczVpSXRDN1J0S1Y4SHg1UmxMRG9QX21FYVdmZTl3In19LCJpYXQiOjE3MDg2MTMwOTh9.IXG7_24Rf8YVu1lM_altOUb5cLKkkMPNuRH0ya8ZFcZfIIhEcujSORNht5Zs82ROiF87yY0voud1q-oMruxzkg~WyJRQU1SMnY5ZmtXQ1VyV2pTOTBqMnZ3Iiwic3ViIiwiMTAwNCJd~WyIxT1BqMzlVZFloSmU0SlV0NHFUREpBIiwiZ2l2ZW5fbmFtZSIsIkluZ2EiXQ~WyJXYUpNUExEVFJQWU5WZVZhMzRzREdRIiwiZmFtaWx5X25hbWUiLCJTaWx2ZXJzdG9uZSJd~WyJPWkdsYWJMSXRwZGNwZFBTdlNRWmxnIiwiYmlydGhkYXRlIiwiMTk5MS0xMS0wNiJd~`;

const decodedSDJwt = sdjwt.decode(sdjwtCompact);
console.log('decodedSDJwt: ', decodedSDJwt);

const presentableKeys = await sdjwt.presentableKeys(sdjwtCompact);
console.log('presentableKeys', presentableKeys);

Here are the logs

  console.log
    decodedSDJwt:  SDJwt {
      jwt: Jwt {
        header: {
          kid: 'J1FwJP87C6-QN_WSIOmJAQc6n5CQ_bZdaFJ5GDnW1Rk',
          typ: 'vc+sd-jwt',
          alg: 'ES256'
        },
        payload: {
          _sd: [Array],
          vct: 'https://credentials.example.com/identity_credential',
          _sd_alg: 'sha-256',
          iss: 'https://trial.authlete.net',
          cnf: [Object],
          iat: 1708613098
        },
        signature: 'IXG7_24Rf8YVu1lM_altOUb5cLKkkMPNuRH0ya8ZFcZfIIhEcujSORNht5Zs82ROiF87yY0voud1q-oMruxzkg'
      },
      disclosures: [
        Disclosure {
          salt: 'QAMR2v9fkWCUrWjS90j2vw',
          key: 'sub',
          value: '1004'
        },
        Disclosure {
          salt: '1OPj39UdYhJe4JUt4qTDJA',
          key: 'given_name',
          value: 'Inga'
        },
        Disclosure {
          salt: 'WaJMPLDTRPYNVeVa34sDGQ',
          key: 'family_name',
          value: 'Silverstone'
        },
        Disclosure {
          salt: 'OZGlabLItpdcpdPSvSQZlg',
          key: 'birthdate',
          value: '1991-11-06'
        }
      ],
      kbJwt: undefined
    }

  console.log
    presentableKeys []

Even with this jwt I took from the sd-jwt-ts present test package I still don't get the presentable keys

eyJ0eXAiOiJzZC1qd3QiLCJhbGciOiJFZERTQSJ9.eyJ0ZXN0Ijp7Il9zZCI6WyJqVEszMHNleDZhYV9kUk1KSWZDR056Q0FwbVB5MzRRNjNBa3QzS3hhSktzIl19LCJfc2QiOlsiME9nMi1ReG95eW1UOGNnVzZZUjVSSFpQLUJuR2tHUi1NM2otLV92RWlzSSIsIkcwZ3lHNnExVFMyUlQxMkZ3X2RRRDVVcjlZc1AwZlVWOXVtQWdGMC1jQ1EiXSwiX3NkX2FsZyI6InNoYS0yNTYifQ.ggEyE4SeDO2Hu3tol3VLmi7NQj56yKzKQDaafocgkLrUBdivghohtzrfcbrMN7CRufJ_Cnh0EL54kymXLGTdDQ~WyIwNGU0MjAzOWU4ZWFiOWRjIiwiYSIsIjEiXQ~WyIwOGE1Yjc5MjMyYjAzYzBhIiwiMSJd~WyJiNWE2YjUzZGQwYTFmMGIwIiwienp6IiwieHh4Il0~WyIxYzdmOTE4ZTE0MjA2NzZiIiwiZm9vIiwiYmFyIl0~WyJmZjYxYzQ5ZGU2NjFiYzMxIiwiYXJyIixbeyIuLi4iOiJTSG96VW5KNUpkd0ZtTjVCbXB5dXZCWGZfZWRjckVvcExPYThTVlBFUmg0In0sIjIiLHsiX3NkIjpbIkpuODNhZkp0OGx4NG1FMzZpRkZyS2U2R2VnN0dlVUQ4Z3UwdVo3NnRZcW8iXX1dXQ~
lukasjhan commented 7 months ago

Hi @Marcjazz.

I was able to get accurate results with this code: https://github.com/lukasjhan/sd-jwt-bug-tests/blob/master/index.ts Can you check above sample project?

btw: my nodejs version is 20.11.1

Marcjazz commented 7 months ago

Hello @lukasjhan

I will try that, but I'm using the @hopae/sd-jwt package instead

lukasjhan commented 7 months ago

Oh That was the problem. Currently we change our package name to @sd-jwt/core Please use our latest package verison :)

If there is a place where the package name is marked as old, please let me know. I'll fix it.