-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement azure keyvault rest client #56
Changes from 45 commits
432339a
d6230d8
dc69703
1bfa3ec
6c161c5
3202b33
14a58a4
2bd7082
dcef76d
2dccda3
d067c14
9a3fda9
c910295
b26781d
cc5ad63
b968166
1359016
ffb8097
6e14c61
3cf0fd3
4dff1ad
627e21f
45808cb
6ff7b2a
d7397c3
65f9e91
742b3eb
39b2dd6
a3972fa
d6d4499
a70fbb6
3a629cd
6a9aa53
0ffefd5
3ae9bd8
f67be2d
217de7e
661e959
9a6d90e
16f0df8
42ba7ee
8f9e94e
3bac089
dccb084
10d34a9
b7b9f07
2e28f29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,9 +30,9 @@ const keyCodecs = { | |
} as const | ||
|
||
export class SphereonKeyDidProvider extends AbstractIdentifierProvider { | ||
private readonly kms: string | ||
private readonly kms?: string | ||
|
||
constructor(options: { defaultKms: string }) { | ||
constructor(options: { defaultKms?: string }) { | ||
super() | ||
this.kms = options.defaultKms | ||
} | ||
|
@@ -67,7 +67,7 @@ export class SphereonKeyDidProvider extends AbstractIdentifierProvider { | |
|
||
const key = await importProvidedOrGeneratedKey( | ||
{ | ||
kms: kms ?? this.kms, | ||
kms: kms ?? this.kms ?? '', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather have a ts-ignore here. Our KMS handles it correctly when no KMS is provided. Using an empty string will result in errors |
||
alias: alias, | ||
options: { ...options, type: keyType }, | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,9 @@ type IContext = IAgentContext<IKeyManager> | |
* @public | ||
*/ | ||
export class OydDIDProvider extends AbstractIdentifierProvider { | ||
private defaultKms: string | ||
private defaultKms?: string | ||
|
||
constructor(options: { defaultKms: string }) { | ||
constructor(options: { defaultKms?: string }) { | ||
super() | ||
this.defaultKms = options.defaultKms | ||
} | ||
|
@@ -48,7 +48,7 @@ export class OydDIDProvider extends AbstractIdentifierProvider { | |
const keyType: OydDidSupportedKeyTypes = options?.keyType || 'Ed25519' | ||
const key = await this.holdKeys( | ||
{ | ||
kms: kms || this.defaultKms, | ||
kms: kms || this.defaultKms || '', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather have a ts-ignore here. Our KMS handles it correctly when no KMS is provided. Using an empty string will result in errors |
||
options: { | ||
keyType, | ||
kid: didDoc.did + '#key-doc', | ||
|
@@ -102,7 +102,7 @@ export class OydDIDProvider extends AbstractIdentifierProvider { | |
private async holdKeys(args: OydDidHoldKeysArgs, context: IContext): Promise<IKey> { | ||
if (args.options.privateKeyHex) { | ||
return context.agent.keyManagerImport({ | ||
kms: args.kms || this.defaultKms, | ||
kms: args.kms || this.defaultKms || '', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather have a ts-ignore here. Our KMS handles it correctly when no KMS is provided. Using an empty string will result in errors |
||
type: args.options.keyType, | ||
kid: args.options.kid, | ||
privateKeyHex: args.options.privateKeyHex, | ||
|
@@ -113,7 +113,7 @@ export class OydDIDProvider extends AbstractIdentifierProvider { | |
} | ||
return context.agent.keyManagerCreate({ | ||
type: args.options.keyType, | ||
kms: args.kms || this.defaultKms, | ||
kms: args.kms || this.defaultKms || '', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather have a ts-ignore here. Our KMS handles it correctly when no KMS is provided. Using an empty string will result in errors |
||
meta: { | ||
algorithms: ['Ed25519'], | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Change Log | ||
|
||
All notable changes to this project will be documented in this file. | ||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. | ||
|
||
# [0.26.0](https://github.com/Sphereon-OpenSource/SSI-SDK-crypto-extensions/compare/v0.25.0...v0.26.0) (2024-11-26) | ||
|
||
### Features | ||
|
||
- create kms-azure plugin structure ([61e1a61](https://github.com/Sphereon-OpenSource/SSI-SDK-crypto-extensions/commit/61e1a61f7442acf376d5cc6e39cdacdc336b8aa3)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<!--suppress HtmlDeprecatedAttribute --> | ||
<h1 align="center"> | ||
<br> | ||
<a href="https://www.sphereon.com"><img src="https://sphereon.com/content/themes/sphereon/assets/img/logo.svg" alt="Sphereon" width="400"></a> | ||
<br>Sphereon's Azure KeyVault Key Management System REST Client Plugin | ||
<br> | ||
</h1> | ||
|
||
## Overview | ||
|
||
This module provides a Key Management System (KMS) wrapper that enables the use of Azure Key Vault REST client functionalities within your application. It extends the capabilities of the `AbstractKeyManagementSystem` by integrating with Azure's robust key management features. This ensures that key generation, signing, and verification operations are handled securely and efficiently, aligning with Veramo's key management functions. | ||
|
||
## Available Functions | ||
|
||
- `createKey` | ||
- `sign` | ||
- `verify` | ||
|
||
## Installation | ||
|
||
To install the module, use the following command: | ||
|
||
```bash | ||
yarn add @sphereon/ssi-sdk-ext.kms-azure-rest-client | ||
``` | ||
|
||
## Usage | ||
|
||
### Creating a Key | ||
|
||
To create a key, you need to specify the key type and optionally provide metadata, such as a key alias. Below is an example of how to create a key using the `AzureKeyVaultKeyManagementSystemRestClient`: | ||
|
||
```typescript | ||
import { AzureKeyVaultKeyManagementSystemRestClient } from '@sphereon/kms-azure-rest-client' | ||
|
||
const options = { | ||
applicationId: 'azure-keyvault-test', | ||
vaultUrl: 'https://example.vault.azure.net/', | ||
apiKey: 'your-api-key-here', | ||
} | ||
|
||
const keyManagementSystem = new AzureKeyVaultKeyManagementSystemRestClient(options) | ||
|
||
async function createKeyExample() { | ||
try { | ||
const key = await keyManagementSystem.createKey({ | ||
type: 'Secp256r1', | ||
meta: { keyAlias: 'my-secure-key' }, | ||
}) | ||
|
||
console.log('Key created:', key) | ||
} catch (error) { | ||
console.error('Error creating key:', error) | ||
} | ||
} | ||
|
||
createKeyExample() | ||
``` | ||
|
||
### Signing Data | ||
|
||
To sign data, provide the key reference (`kid`) and the data to be signed: | ||
|
||
```typescript | ||
async function signExample() { | ||
try { | ||
const signature = await keyManagementSystem.sign({ | ||
keyRef: { kid: 'your-key-id' }, | ||
data: new TextEncoder().encode('data-to-sign'), | ||
}) | ||
|
||
console.log('Signature:', signature) | ||
} catch (error) { | ||
console.error('Error signing data:', error) | ||
} | ||
} | ||
|
||
signExample() | ||
``` | ||
|
||
### Verifying Data | ||
|
||
To verify data, provide the key reference (`kid`), the data, and the signature: | ||
|
||
```typescript | ||
async function verifyExample() { | ||
try { | ||
const isValid = await keyManagementSystem.verify({ | ||
keyRef: { kid: 'your-key-id' }, | ||
data: new TextEncoder().encode('data-to-verify'), | ||
signature: 'signature-to-verify', | ||
}) | ||
|
||
console.log('Is signature valid?', isValid) | ||
} catch (error) { | ||
console.error('Error verifying signature:', error) | ||
} | ||
} | ||
|
||
verifyExample() | ||
``` | ||
|
||
## Configuration | ||
|
||
The `AzureKeyVaultKeyManagementSystemRestClient` requires the following configuration options: | ||
|
||
- `applicationId`: A unique identifier for your application. | ||
- `vaultUrl`: The base URL of your Azure Key Vault. | ||
- `apiKey`: The API key for authenticating requests. | ||
|
||
## Limitations | ||
|
||
This implementation currently supports the following key operations: | ||
|
||
- `createKey` | ||
- `sign` | ||
- `verify` | ||
|
||
Additional functionalities like `sharedSecret`, `importKey`, `deleteKey`, and `listKeys` are not implemented in this version and will throw an error if called. | ||
|
||
## License | ||
|
||
This project is licensed under the [MIT License](LICENSE). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"name": "@sphereon/ssi-sdk-ext.kms-azure-rest-client", | ||
"description": "Sphereon SSI-SDK plugin for Azure KeyVault Key Management System.", | ||
"version": "0.26.0", | ||
"source": "src/index.ts", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"build": "tsc --build", | ||
"build:clean": "tsc --build --clean && tsc --build" | ||
}, | ||
"dependencies": { | ||
"@sphereon/ssi-sdk-ext.did-utils": "workspace:*", | ||
"@sphereon/ssi-sdk-ext.key-utils": "workspace:*", | ||
"@sphereon/ssi-types": "0.30.2-feature.SDK.41.oidf.support.286", | ||
"@veramo/core": "4.2.0", | ||
"@veramo/key-manager": "4.2.0", | ||
"uint8arrays": "^3.1.1" | ||
}, | ||
"devDependencies": { | ||
"@types/text-encoding": "0.0.39" | ||
}, | ||
"files": [ | ||
"dist/**/*", | ||
"src/**/*", | ||
"README.md", | ||
"LICENSE" | ||
], | ||
"private": false, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": "[email protected]:Sphereon-OpenSource/SSI-SDK-crypto-extensions.git", | ||
"author": "Sphereon <[email protected]>", | ||
"license": "Apache-2.0", | ||
"keywords": [ | ||
"azure", | ||
"keyvault", | ||
"key-management", | ||
"react-native", | ||
"Veramo" | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather have a ts-ignore here. Our KMS handles it correctly when no KMS is provided. Using an empty string will result in errors