@gjgd/ion-sdk
Advanced tools
Comparing version 0.5.0 to 0.5.1
@@ -18,4 +18,9 @@ /** | ||
JwkEs256kHasIncorrectLengthOfD: 'JwkEs256kHasIncorrectLengthOfD', | ||
JwkEd25519MissingOrInvalidCrv: 'JwkEd25519MissingOrInvalidCrv', | ||
JwkEd25519MissingOrInvalidKty: 'JwkEd25519MissingOrInvalidKty', | ||
JwkEd25519HasIncorrectLengthOfX: 'JwkEd25519HasIncorrectLengthOfX', | ||
JwkEd25519HasIncorrectLengthOfD: 'JwkEd25519HasIncorrectLengthOfD', | ||
MultihashStringNotAMultihash: 'MultihashStringNotAMultihash', | ||
MultihashUnsupportedHashAlgorithm: 'MultihashUnsupportedHashAlgorithm', | ||
PublicKeyJwkEd25519HasUnexpectedProperty: 'PublicKeyJwkEd25519HasUnexpectedProperty', | ||
PublicKeyJwkEs256kHasUnexpectedProperty: 'PublicKeyJwkEs256kHasUnexpectedProperty', | ||
@@ -25,3 +30,4 @@ PublicKeyPurposeDuplicated: 'PublicKeyPurposeDuplicated', | ||
ServiceEndpointStringNotValidUri: 'ServiceEndpointStringNotValidUri', | ||
ServiceTypeTooLong: 'ServiceTypeTooLong' | ||
ServiceTypeTooLong: 'ServiceTypeTooLong', | ||
UnsupportedKeyType: 'UnsupportedKeyType' | ||
}; |
import Encoder from './Encoder'; | ||
import ErrorCode from './ErrorCode'; | ||
import IonError from './IonError'; | ||
import IonKey from './IonKey'; | ||
import IonPublicKeyPurpose from './enums/IonPublicKeyPurpose'; | ||
import JwkEd25519 from './models/JwkEd25519'; | ||
import JwkEs256k from './models/JwkEs256k'; | ||
import OperationKeyType from './enums/OperationKeyType'; | ||
import SidetreeKeyJwk from './models/SidetreeKeyJwk'; | ||
@@ -13,2 +16,15 @@ /** | ||
/** | ||
* Validates the schema of a Ed25519 or secp256k1 JWK | ||
*/ | ||
public static validateOperationKey (operationKeyJwk: SidetreeKeyJwk, operationKeyType: OperationKeyType) { | ||
if (IonKey.isJwkEs256k(operationKeyJwk)) { | ||
InputValidator.validateEs256kOperationKey(operationKeyJwk, operationKeyType); | ||
} else if (IonKey.isJwkEd25519(operationKeyJwk)) { | ||
InputValidator.validateEd25519OperationKey(operationKeyJwk, operationKeyType); | ||
} else { | ||
throw new IonError(ErrorCode.UnsupportedKeyType, `JWK key should be secp256k1 or Ed25519.`); | ||
} | ||
} | ||
/** | ||
* Validates the schema of a ES256K JWK key. | ||
@@ -50,2 +66,34 @@ */ | ||
/** | ||
* Validates the schema of a Ed25519 JWK key. | ||
*/ | ||
public static validateEd25519OperationKey (operationKeyJwk: JwkEd25519, operationKeyType: OperationKeyType) { | ||
const allowedProperties = new Set(['kty', 'crv', 'x']); | ||
if (operationKeyType === OperationKeyType.Private) { | ||
allowedProperties.add('d'); | ||
} | ||
for (const property in operationKeyJwk) { | ||
if (!allowedProperties.has(property)) { | ||
throw new IonError(ErrorCode.PublicKeyJwkEd25519HasUnexpectedProperty, `Ed25519 JWK key has unexpected property '${property}'.`); | ||
} | ||
} | ||
if (operationKeyJwk.crv !== 'Ed25519') { | ||
throw new IonError(ErrorCode.JwkEd25519MissingOrInvalidCrv, `Ed25519 JWK 'crv' property must be 'Ed25519' but got '${operationKeyJwk.crv}.'`); | ||
} | ||
if (operationKeyJwk.kty !== 'OKP') { | ||
throw new IonError(ErrorCode.JwkEd25519MissingOrInvalidKty, `Ed25519 JWK 'kty' property must be 'OKP' but got '${operationKeyJwk.kty}.'`); | ||
} | ||
// `x` needs 43 Base64URL encoded bytes to contain 256 bits. | ||
if (operationKeyJwk.x.length !== 43) { | ||
throw new IonError(ErrorCode.JwkEd25519HasIncorrectLengthOfX, `Ed25519 JWK 'x' property must be 43 bytes.`); | ||
} | ||
if (operationKeyType === OperationKeyType.Private && (operationKeyJwk.d === undefined || operationKeyJwk.d.length !== 43)) { | ||
throw new IonError(ErrorCode.JwkEd25519HasIncorrectLengthOfD, `Ed25519 JWK 'd' property must be 43 bytes.`); | ||
} | ||
} | ||
/** | ||
* Validates an `id` property (in `IonPublicKeyModel` and `IonServiceModel`). | ||
@@ -52,0 +100,0 @@ */ |
@@ -6,4 +6,4 @@ import Encoder from './Encoder'; | ||
import JsonCanonicalizer from './JsonCanonicalizer'; | ||
import JwkEs256k from './models/JwkEs256k'; | ||
import Multihash from './Multihash'; | ||
import SidetreeKeyJwk from './models/SidetreeKeyJwk'; | ||
@@ -19,4 +19,4 @@ /** | ||
public static createLongFormDid (input: { | ||
recoveryKey: JwkEs256k; | ||
updateKey: JwkEs256k; | ||
recoveryKey: SidetreeKeyJwk; | ||
updateKey: SidetreeKeyJwk; | ||
document: IonDocumentModel; | ||
@@ -23,0 +23,0 @@ }): string { |
@@ -8,2 +8,3 @@ import { JsonWebKey2020, Secp256k1KeyPair } from '@transmute/secp256k1-key-pair'; | ||
import JwkEs256k from './models/JwkEs256k'; | ||
import SidetreeKeyJwk from './models/SidetreeKeyJwk'; | ||
const randomBytes = require('randombytes'); | ||
@@ -111,9 +112,9 @@ | ||
public static isJwkEs256k (key: JwkEs256k | JwkEd25519): key is JwkEs256k { | ||
public static isJwkEs256k (key: SidetreeKeyJwk): key is JwkEs256k { | ||
return key.crv === 'secp256k1' && key.kty === 'EC'; | ||
}; | ||
public static isJwkEd25519 (key: JwkEs256k | JwkEd25519): key is JwkEd25519 { | ||
public static isJwkEd25519 (key: SidetreeKeyJwk): key is JwkEd25519 { | ||
return key.crv === 'Ed25519' && key.kty === 'OKP'; | ||
}; | ||
} |
@@ -15,3 +15,2 @@ import * as URI from 'uri-js'; | ||
import JsonCanonicalizer from './JsonCanonicalizer'; | ||
import JwkEs256k from './models/JwkEs256k'; | ||
import Multihash from './Multihash'; | ||
@@ -21,2 +20,3 @@ import OperationKeyType from './enums/OperationKeyType'; | ||
import PatchAction from './enums/PatchAction'; | ||
import SidetreeKeyJwk from './models/SidetreeKeyJwk'; | ||
@@ -32,4 +32,4 @@ /** | ||
public static createCreateRequest (input: { | ||
recoveryKey: JwkEs256k; | ||
updateKey: JwkEs256k; | ||
recoveryKey: SidetreeKeyJwk; | ||
updateKey: SidetreeKeyJwk; | ||
document: IonDocumentModel; | ||
@@ -43,4 +43,4 @@ }): IonCreateRequestModel { | ||
// Validate recovery and update public keys. | ||
InputValidator.validateEs256kOperationKey(recoveryKey, OperationKeyType.Public); | ||
InputValidator.validateEs256kOperationKey(updateKey, OperationKeyType.Public); | ||
InputValidator.validateOperationKey(recoveryKey, OperationKeyType.Public); | ||
InputValidator.validateOperationKey(updateKey, OperationKeyType.Public); | ||
@@ -85,3 +85,3 @@ // Validate all given DID Document keys. | ||
didSuffix: string, | ||
recoveryPublicKey: JwkEs256k, | ||
recoveryPublicKey: SidetreeKeyJwk, | ||
signer: ISigner | ||
@@ -93,3 +93,3 @@ }): Promise<IonDeactivateRequestModel> { | ||
// Validates recovery public key | ||
InputValidator.validateEs256kOperationKey(input.recoveryPublicKey, OperationKeyType.Public); | ||
InputValidator.validateOperationKey(input.recoveryPublicKey, OperationKeyType.Public); | ||
@@ -116,5 +116,5 @@ const hashAlgorithmInMultihashCode = IonSdkConfig.hashAlgorithmInMultihashCode; | ||
didSuffix: string, | ||
recoveryPublicKey: JwkEs256k, | ||
nextRecoveryPublicKey: JwkEs256k, | ||
nextUpdatePublicKey: JwkEs256k, | ||
recoveryPublicKey: SidetreeKeyJwk, | ||
nextRecoveryPublicKey: SidetreeKeyJwk, | ||
nextUpdatePublicKey: SidetreeKeyJwk, | ||
document: IonDocumentModel, | ||
@@ -127,9 +127,9 @@ signer: ISigner | ||
// Validate recovery public key | ||
InputValidator.validateEs256kOperationKey(input.recoveryPublicKey, OperationKeyType.Public); | ||
InputValidator.validateOperationKey(input.recoveryPublicKey, OperationKeyType.Public); | ||
// Validate next recovery public key | ||
InputValidator.validateEs256kOperationKey(input.nextRecoveryPublicKey, OperationKeyType.Public); | ||
InputValidator.validateOperationKey(input.nextRecoveryPublicKey, OperationKeyType.Public); | ||
// Validate next update public key | ||
InputValidator.validateEs256kOperationKey(input.nextUpdatePublicKey, OperationKeyType.Public); | ||
InputValidator.validateOperationKey(input.nextUpdatePublicKey, OperationKeyType.Public); | ||
@@ -178,4 +178,4 @@ // Validate all given DID Document keys. | ||
didSuffix: string; | ||
updatePublicKey: JwkEs256k; | ||
nextUpdatePublicKey: JwkEs256k; | ||
updatePublicKey: SidetreeKeyJwk; | ||
nextUpdatePublicKey: SidetreeKeyJwk; | ||
signer: ISigner; | ||
@@ -191,6 +191,6 @@ servicesToAdd?: IonServiceModel[]; | ||
// Validate update public key | ||
InputValidator.validateEs256kOperationKey(input.updatePublicKey, OperationKeyType.Public); | ||
InputValidator.validateOperationKey(input.updatePublicKey, OperationKeyType.Public); | ||
// Validate next update public key | ||
InputValidator.validateEs256kOperationKey(input.nextUpdatePublicKey, OperationKeyType.Public); | ||
InputValidator.validateOperationKey(input.nextUpdatePublicKey, OperationKeyType.Public); | ||
@@ -197,0 +197,0 @@ // Validate all given service. |
@@ -0,7 +1,11 @@ | ||
import { Ed25519KeyPair } from '@transmute/ed25519-key-pair'; | ||
import ErrorCode from './ErrorCode'; | ||
import ISigner from './interfaces/ISigner'; | ||
import InputValidator from './InputValidator'; | ||
import IonError from './IonError'; | ||
import IonKey from './IonKey'; | ||
import { JWS } from '@transmute/jose-ld'; | ||
import JwkEs256k from './models/JwkEs256k'; | ||
import OperationKeyType from './enums/OperationKeyType'; | ||
import { Secp256k1KeyPair } from '@transmute/secp256k1-key-pair'; | ||
import SidetreeKeyJwk from './models/SidetreeKeyJwk'; | ||
@@ -15,8 +19,8 @@ /** | ||
*/ | ||
public static create (privateKey: JwkEs256k): ISigner { | ||
public static create (privateKey: SidetreeKeyJwk): ISigner { | ||
return new LocalSigner(privateKey); | ||
} | ||
private constructor (private privateKey: JwkEs256k) { | ||
InputValidator.validateEs256kOperationKey(privateKey, OperationKeyType.Private); | ||
private constructor (private privateKey: SidetreeKeyJwk) { | ||
InputValidator.validateOperationKey(privateKey, OperationKeyType.Private); | ||
} | ||
@@ -29,15 +33,32 @@ | ||
}; | ||
const key = await Secp256k1KeyPair.from({ | ||
type: 'JsonWebKey2020', | ||
publicKeyJwk, | ||
privateKeyJwk: this.privateKey | ||
} as any); | ||
const signer = key.signer(); | ||
const jwsSigner = await JWS.createSigner(signer, 'ES256K', { | ||
detached: false, | ||
header | ||
}); | ||
const compactJws = await jwsSigner.sign({ data: content }); | ||
return compactJws; | ||
if (IonKey.isJwkEs256k(publicKeyJwk)) { | ||
const key = await Secp256k1KeyPair.from({ | ||
type: 'JsonWebKey2020', | ||
publicKeyJwk, | ||
privateKeyJwk: this.privateKey | ||
} as any); | ||
const signer = key.signer(); | ||
const jwsSigner = await JWS.createSigner(signer, 'ES256K', { | ||
detached: false, | ||
header | ||
}); | ||
const compactJws = await jwsSigner.sign({ data: content }); | ||
return compactJws; | ||
} else if (IonKey.isJwkEd25519(publicKeyJwk)) { | ||
const key = await Ed25519KeyPair.from({ | ||
type: 'JsonWebKey2020', | ||
publicKeyJwk, | ||
privateKeyJwk: this.privateKey | ||
} as any); | ||
const signer = key.signer(); | ||
const jwsSigner = await JWS.createSigner(signer, 'EdDSA', { | ||
detached: false, | ||
header | ||
}); | ||
const compactJws = await jwsSigner.sign({ data: content }); | ||
return compactJws; | ||
} else { | ||
throw new IonError(ErrorCode.UnsupportedKeyType, `JWK key should be secp256k1 or Ed25119.`); | ||
} | ||
} | ||
} |
{ | ||
"name": "@gjgd/ion-sdk", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "TypeScript SDK for ION", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/decentralized-identity/ion-sdk", |
@@ -16,2 +16,58 @@ import InputValidator from '../lib/InputValidator'; | ||
it('should throw if given key does not have crv', () => { | ||
const publicKey = require('./vectors/inputs/jwkEs256k1Public.json'); | ||
const publicKeyWithoutCrv = { | ||
...publicKey, | ||
crv: undefined | ||
}; | ||
try { | ||
InputValidator.validateEs256kOperationKey(publicKeyWithoutCrv, OperationKeyType.Public); | ||
fail(); | ||
} catch (e) { | ||
expect(e.message).toEqual(`JwkEs256kMissingOrInvalidCrv: SECP256K1 JWK 'crv' property must be 'secp256k1' but got 'undefined.'`); | ||
} | ||
}); | ||
it('should throw if given key does not have kty', () => { | ||
const publicKey = require('./vectors/inputs/jwkEs256k1Public.json'); | ||
const publicKeyWithoutKty = { | ||
...publicKey, | ||
kty: undefined | ||
}; | ||
try { | ||
InputValidator.validateEs256kOperationKey(publicKeyWithoutKty, OperationKeyType.Public); | ||
fail(); | ||
} catch (e) { | ||
expect(e.message).toEqual(`JwkEs256kMissingOrInvalidKty: SECP256K1 JWK 'kty' property must be 'EC' but got 'undefined.'`); | ||
} | ||
}); | ||
it('should throw if given key has extra properties', () => { | ||
const publicKey = require('./vectors/inputs/jwkEs256k1Public.json'); | ||
const publicKeyWithExtraProperty = { | ||
...publicKey, | ||
extra: true | ||
}; | ||
try { | ||
InputValidator.validateEs256kOperationKey(publicKeyWithExtraProperty, OperationKeyType.Public); | ||
fail(); | ||
} catch (e) { | ||
expect(e.message).toEqual(`PublicKeyJwkEs256kHasUnexpectedProperty: SECP256K1 JWK key has unexpected property 'extra'.`); | ||
} | ||
}); | ||
it('should throw if given key x value is not the correct length', () => { | ||
const publicKey = require('./vectors/inputs/jwkEs256k1Public.json'); | ||
const publicKeyWithInvalidX = { | ||
...publicKey, | ||
x: 'abc' | ||
}; | ||
try { | ||
InputValidator.validateEs256kOperationKey(publicKeyWithInvalidX, OperationKeyType.Public); | ||
fail(); | ||
} catch (e) { | ||
expect(e.message).toEqual(`JwkEs256kHasIncorrectLengthOfX: SECP256K1 JWK 'x' property must be 43 bytes.`); | ||
} | ||
}); | ||
it('should throw if given private key d value is not the correct length', () => { | ||
@@ -29,2 +85,82 @@ const privateKey = require('./vectors/inputs/jwkEs256k1Private.json'); | ||
}); | ||
describe('validateEd25519OperationKey', () => { | ||
it('should throw if given private key does not have d', () => { | ||
const publicKey = require('./vectors/inputs/jwkEd255191Public.json'); | ||
try { | ||
InputValidator.validateEd25519OperationKey(publicKey, OperationKeyType.Private); | ||
fail(); | ||
} catch (e) { | ||
expect(e.message).toEqual(`JwkEd25519HasIncorrectLengthOfD: Ed25519 JWK 'd' property must be 43 bytes.`); | ||
} | ||
}); | ||
it('should throw if given key does not have crv', () => { | ||
const publicKey = require('./vectors/inputs/jwkEd255191Public.json'); | ||
const publicKeyWithoutCrv = { | ||
...publicKey, | ||
crv: undefined | ||
}; | ||
try { | ||
InputValidator.validateEd25519OperationKey(publicKeyWithoutCrv, OperationKeyType.Public); | ||
fail(); | ||
} catch (e) { | ||
expect(e.message).toEqual(`JwkEd25519MissingOrInvalidCrv: Ed25519 JWK 'crv' property must be 'Ed25519' but got 'undefined.'`); | ||
} | ||
}); | ||
it('should throw if given key does not have kty', () => { | ||
const publicKey = require('./vectors/inputs/jwkEd255191Public.json'); | ||
const publicKeyWithoutKty = { | ||
...publicKey, | ||
kty: undefined | ||
}; | ||
try { | ||
InputValidator.validateEd25519OperationKey(publicKeyWithoutKty, OperationKeyType.Public); | ||
fail(); | ||
} catch (e) { | ||
expect(e.message).toEqual(`JwkEd25519MissingOrInvalidKty: Ed25519 JWK 'kty' property must be 'OKP' but got 'undefined.'`); | ||
} | ||
}); | ||
it('should throw if given key has extra properties', () => { | ||
const publicKey = require('./vectors/inputs/jwkEd255191Public.json'); | ||
const publicKeyWithExtraProperty = { | ||
...publicKey, | ||
extra: true | ||
}; | ||
try { | ||
InputValidator.validateEd25519OperationKey(publicKeyWithExtraProperty, OperationKeyType.Public); | ||
fail(); | ||
} catch (e) { | ||
expect(e.message).toEqual(`PublicKeyJwkEd25519HasUnexpectedProperty: Ed25519 JWK key has unexpected property 'extra'.`); | ||
} | ||
}); | ||
it('should throw if given key x value is not the correct length', () => { | ||
const publicKey = require('./vectors/inputs/jwkEd255191Public.json'); | ||
const publicKeyWithInvalidX = { | ||
...publicKey, | ||
x: 'abc' | ||
}; | ||
try { | ||
InputValidator.validateEd25519OperationKey(publicKeyWithInvalidX, OperationKeyType.Public); | ||
fail(); | ||
} catch (e) { | ||
expect(e.message).toEqual(`JwkEd25519HasIncorrectLengthOfX: Ed25519 JWK 'x' property must be 43 bytes.`); | ||
} | ||
}); | ||
it('should throw if given private key d value is not the correct length', () => { | ||
const privateKey = require('./vectors/inputs/jwkEd255191Private.json'); | ||
const privateKeyClone = Object.assign({}, privateKey); // Make a copy so this test does not affect other tests. | ||
privateKeyClone.d = 'abc'; | ||
try { | ||
InputValidator.validateEd25519OperationKey(privateKeyClone, OperationKeyType.Private); | ||
fail(); | ||
} catch (e) { | ||
expect(e.message).toEqual(`JwkEd25519HasIncorrectLengthOfD: Ed25519 JWK 'd' property must be 43 bytes.`); | ||
} | ||
}); | ||
}); | ||
}); |
@@ -0,4 +1,7 @@ | ||
import * as jwkEd255191Public from './vectors/inputs/jwkEd255191Public.json'; | ||
import * as jwkEd255192Public from './vectors/inputs/jwkEd255192Public.json'; | ||
import * as jwkEs256k1Public from './vectors/inputs/jwkEs256k1Public.json'; | ||
import * as jwkEs256k2Public from './vectors/inputs/jwkEs256k2Public.json'; | ||
import * as publicKeyModel1 from './vectors/inputs/publicKeyModel1.json'; | ||
import * as publicKeyModelEd25519 from './vectors/inputs/publicKeyModelEd25519.json'; | ||
import * as service1 from './vectors/inputs/service1.json'; | ||
@@ -18,3 +21,3 @@ import { IonDid, IonKey, IonPublicKeyPurpose, IonSdkConfig } from '../lib/index'; | ||
describe('createLongFormDid()', async () => { | ||
it('vector test - should create a long-form DID correctly.', async () => { | ||
it('vector test - should create a long-form DID correctly with ES256K keys.', async () => { | ||
const recoveryKey = jwkEs256k1Public; | ||
@@ -36,2 +39,19 @@ const updateKey = jwkEs256k2Public; | ||
it('vector test - should create a long-form DID correctly with Ed25519 keys.', async () => { | ||
const recoveryKey = jwkEd255191Public; | ||
const updateKey = jwkEd255192Public; | ||
const didDocumentKeys = [publicKeyModelEd25519 as any]; | ||
const services = [service1]; | ||
const document = { | ||
publicKeys: didDocumentKeys, | ||
services | ||
}; | ||
const longFormDid = IonDid.createLongFormDid({ recoveryKey, updateKey, document }); | ||
const expectedMethodSpecificId = 'did:ion:EiBks49Ah-ZxE1-6Se-PUDk_4_ffylpeqmfMCWUBwwTM-g:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJwdWJsaWNLZXlNb2RlbEVkMjU1MTkiLCJwdWJsaWNLZXlKd2siOnsiY3J2IjoiRWQyNTUxOSIsImt0eSI6Ik9LUCIsIngiOiJoQ3hhTVI2TlVPWEkxQzd3Nlh6MW1jaGMyd1M4RlZ2WGhuZ3NnWjBodHNZIn0sInB1cnBvc2VzIjpbImF1dGhlbnRpY2F0aW9uIiwia2V5QWdyZWVtZW50Il0sInR5cGUiOiJKc29uV2ViS2V5MjAyMCJ9XSwic2VydmljZXMiOlt7ImlkIjoic2VydmljZTFJZCIsInNlcnZpY2VFbmRwb2ludCI6Imh0dHA6Ly93d3cuc2VydmljZTEuY29tIiwidHlwZSI6InNlcnZpY2UxVHlwZSJ9XX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpQ0VEZkdaZkdxeXJuMmVsTU1MbGRfMGxQVE8xTXlQbi1MdFlhZWJEYl9xQncifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaUI2TVJSNFc5NFhhc21obVhXM2NhUlluWDdUWGYyZktwcUhuZGhqTmcwb2R3IiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlEbHNIVkFScDgwYTF2azhHQTlxMWcwaFNGbEp3VGdlQkZOMmkyME9sMlRJUSJ9fQ'; | ||
expect(longFormDid).toEqual(expectedMethodSpecificId); | ||
}); | ||
it('should not generate invalid JSON when `services` and/or `publicKeys` in given document are `undefined`.', async () => { | ||
@@ -93,3 +113,3 @@ const recoveryKey = jwkEs256k1Public; | ||
() => IonDid.createLongFormDid({ recoveryKey, updateKey, document: { } }), | ||
ErrorCode.JwkEs256kMissingOrInvalidCrv | ||
ErrorCode.UnsupportedKeyType | ||
); | ||
@@ -105,3 +125,3 @@ }); | ||
() => IonDid.createLongFormDid({ recoveryKey, updateKey, document: { } }), | ||
ErrorCode.JwkEs256kMissingOrInvalidKty | ||
ErrorCode.UnsupportedKeyType | ||
); | ||
@@ -108,0 +128,0 @@ }); |
@@ -6,3 +6,3 @@ import IonDocumentModel from '../lib/models/IonDocumentModel'; | ||
describe('IonRequest', () => { | ||
describe('IonRequest with Es256k keys', () => { | ||
describe('createCreateRequest', () => { | ||
@@ -147,1 +147,115 @@ it('should generate a create request with desired arguments', async () => { | ||
}); | ||
describe('IonRequest with Ed25519 keys', () => { | ||
const didSuffix = 'EiBks49Ah-ZxE1-6Se-PUDk_4_ffylpeqmfMCWUBwwTM-g'; | ||
describe('createCreateRequest', () => { | ||
it('should generate a create request with desired arguments', async () => { | ||
const recoveryKey = require('./vectors/inputs/jwkEd255191Public.json'); | ||
const updateKey = require('./vectors/inputs/jwkEd255192Public.json'); | ||
const publicKey = require('./vectors/inputs/publicKeyModelEd25519.json'); | ||
const publicKeys = [publicKey]; | ||
const service = require('./vectors/inputs/service1.json'); | ||
const services = [service]; | ||
const document : IonDocumentModel = { | ||
publicKeys, | ||
services | ||
}; | ||
const input = { recoveryKey, updateKey, document }; | ||
const result = IonRequest.createCreateRequest(input); | ||
expect(result.type).toEqual(OperationType.Create); | ||
expect(result.delta.updateCommitment).toEqual('EiCEDfGZfGqyrn2elMMLld_0lPTO1MyPn-LtYaebDb_qBw'); | ||
expect(result.delta.patches.length).toEqual(1); | ||
expect(result.suffixData.recoveryCommitment).toEqual('EiDlsHVARp80a1vk8GA9q1g0hSFlJwTgeBFN2i20Ol2TIQ'); | ||
expect(result.suffixData.deltaHash).toEqual('EiB6MRR4W94XasmhmXW3caRYnX7TXf2fKpqHndhjNg0odw'); | ||
}); | ||
}); | ||
describe('createUpdateRequest', () => { | ||
it('should generate an update request with the given arguments', async () => { | ||
const publicKey = require('./vectors/inputs/publicKeyModelEd25519.json'); | ||
const publicKeys = [publicKey]; | ||
const service = require('./vectors/inputs/service1.json'); | ||
const services = [service]; | ||
const input = { | ||
didSuffix, | ||
updatePublicKey: require('./vectors/inputs/jwkEd255191Public.json'), | ||
nextUpdatePublicKey: require('./vectors/inputs/jwkEd255192Public.json'), | ||
signer: LocalSigner.create(require('./vectors/inputs/jwkEd255191Private.json')), | ||
servicesToAdd: services, | ||
idsOfServicesToRemove: ['someId1'], | ||
publicKeysToAdd: publicKeys, | ||
idsOfPublicKeysToRemove: ['someId2'] | ||
}; | ||
const result = await IonRequest.createUpdateRequest(input); | ||
expect(result.didSuffix).toEqual(didSuffix); | ||
expect(result.type).toEqual(OperationType.Update); | ||
expect(result.revealValue).toEqual('EiDEn43TJxGpPXjVD-HWeR2i-OQSF8jUKxWA62OvCjc64w'); | ||
expect(result.signedData).toEqual('eyJhbGciOiJFUzI1NksifQ.eyJ1cGRhdGVLZXkiOnsiY3J2IjoiRWQyNTUxOSIsIngiOiJ5eC11Z3M4Sl9kM0JfVEUwcFY3c3E0Q016RFRFRDNScVRRY1cyZGxENjVnIiwia3R5IjoiT0tQIn0sImRlbHRhSGFzaCI6IkVpQzItdEx2MjlqWkFnRVhmY2NxYXVaaXNJb1p5TTlZVjZGMUduZXR2cEE3aXcifQ.tOQ9Gh0aFXiBEtioFPbNbf0YL_rIaQigk1gD5dnMLIUZead_LN2sU6KE_LG4XdV5Zhser6_aNouSg7zTN4aHAg'); | ||
expect(result.delta.updateCommitment).toEqual('EiCEDfGZfGqyrn2elMMLld_0lPTO1MyPn-LtYaebDb_qBw'); | ||
expect(result.delta.patches.length).toEqual(4); // add/remove service and add/remove key | ||
}); | ||
it('should generate an update request with the no arguments', async () => { | ||
const input = { | ||
didSuffix, | ||
updatePublicKey: require('./vectors/inputs/jwkEd255191Public.json'), | ||
nextUpdatePublicKey: require('./vectors/inputs/jwkEd255192Public.json'), | ||
signer: LocalSigner.create(require('./vectors/inputs/jwkEd255191Private.json')) | ||
}; | ||
const result = await IonRequest.createUpdateRequest(input); | ||
expect(result.didSuffix).toEqual(didSuffix); | ||
}); | ||
}); | ||
describe('createRecoverRequest', () => { | ||
it('should generate a recover request with given arguments', async () => { | ||
const publicKey = require('./vectors/inputs/publicKeyModelEd25519.json'); | ||
const publicKeys = [publicKey]; | ||
const service = require('./vectors/inputs/service1.json'); | ||
const services = [service]; | ||
const document : IonDocumentModel = { | ||
publicKeys, | ||
services | ||
}; | ||
const result = await IonRequest.createRecoverRequest({ | ||
didSuffix, | ||
recoveryPublicKey: require('./vectors/inputs/jwkEd255191Public.json'), | ||
nextRecoveryPublicKey: require('./vectors/inputs/jwkEd255192Public.json'), | ||
nextUpdatePublicKey: require('./vectors/inputs/jwkEd255193Public.json'), | ||
document, | ||
signer: LocalSigner.create(require('./vectors/inputs/jwkEd255191Private.json')) | ||
}); | ||
expect(result.didSuffix).toEqual(didSuffix); | ||
expect(result.revealValue).toEqual('EiDEn43TJxGpPXjVD-HWeR2i-OQSF8jUKxWA62OvCjc64w'); | ||
expect(result.type).toEqual(OperationType.Recover); | ||
expect(result.signedData).toEqual('eyJhbGciOiJFUzI1NksifQ.eyJyZWNvdmVyeUNvbW1pdG1lbnQiOiJFaUNFRGZHWmZHcXlybjJlbE1NTGxkXzBsUFRPMU15UG4tTHRZYWViRGJfcUJ3IiwicmVjb3ZlcnlLZXkiOnsiY3J2IjoiRWQyNTUxOSIsIngiOiJ5eC11Z3M4Sl9kM0JfVEUwcFY3c3E0Q016RFRFRDNScVRRY1cyZGxENjVnIiwia3R5IjoiT0tQIn0sImRlbHRhSGFzaCI6IkVpRGFnb2lHRDhscTg2OG1naHYwMGNJQTllSk1yM0xTOEtOaWZadjBHajlJYmcifQ.fwBEM0wR1nIgU2XF5ci_NAtFA9IGGR2XjxSKdXI25aIAG9pT0s0oN0aKZLnPpUqsYPFKLSJ2yLimE5kznf_9DQ'); | ||
expect(result.delta.updateCommitment).toEqual('EiCQBVBSp20ozAll1ZUjuvUSfkSKwvOtmlzGW-QLbKeGzg'); | ||
expect(result.delta.patches.length).toEqual(1); // replace | ||
}); | ||
}); | ||
describe('createDeactivateRequest', () => { | ||
it('should generate a deactivate request with the given arguments', async () => { | ||
const result = await IonRequest.createDeactivateRequest({ | ||
didSuffix, | ||
recoveryPublicKey: require('./vectors/inputs/jwkEd255191Public.json'), | ||
signer: LocalSigner.create(require('./vectors/inputs/jwkEd255191Private.json')) | ||
}); | ||
expect(result.didSuffix).toEqual(didSuffix); | ||
expect(result.type).toEqual(OperationType.Deactivate); | ||
expect(result.revealValue).toEqual('EiDEn43TJxGpPXjVD-HWeR2i-OQSF8jUKxWA62OvCjc64w'); | ||
expect(result.signedData).toEqual('eyJhbGciOiJFUzI1NksifQ.eyJkaWRTdWZmaXgiOiJFaUJrczQ5QWgtWnhFMS02U2UtUFVEa180X2ZmeWxwZXFtZk1DV1VCd3dUTS1nIiwicmVjb3ZlcnlLZXkiOnsiY3J2IjoiRWQyNTUxOSIsIngiOiJ5eC11Z3M4Sl9kM0JfVEUwcFY3c3E0Q016RFRFRDNScVRRY1cyZGxENjVnIiwia3R5IjoiT0tQIn19.EakaSOPRlceKelvYoS_toZWyNd1yxjgbMz_tjQKw3ARF19_xiyS851mB2-DQF1Lwd9BPNgZtYmpQk8SsrSwmCA'); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
271737
197
4341