Skip to content

Commit

Permalink
fix: Be a bit more relaxed when deleting an LTO DID, eventhough oncha…
Browse files Browse the repository at this point in the history
…in support is not present
  • Loading branch information
nklomp committed Dec 17, 2021
1 parent 6e44b07 commit 7347914
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions packages/lto-did-provider/src/lto-did-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import { IAgentContext, IIdentifier, IKey, IKeyManager, IService, TKeyType } fro
import { Account, LTO } from 'lto-api'
import { DIDService, hexToBase58, base58ToHex } from '@sphereon/lto-did-ts'
import Debug from 'debug'
import { ICreateIdentifierOpts, ILtoDidProviderOpts, IRequiredContext, IDidConnectionMode, IAddKeyOpts } from './types/lto-provider-types'
import {
ICreateIdentifierOpts,
ILtoDidProviderOpts,
IRequiredContext,
IDidConnectionMode,
IAddKeyOpts,
} from './types/lto-provider-types'
import { UniRegistrar } from '@sphereon/did-uni-client'

const debug = Debug('veramo:did-provider-lto')
Expand All @@ -26,7 +32,7 @@ export class LtoDidProvider extends AbstractIdentifierProvider {

async createIdentifier(
{ kms, options }: { kms?: string; options?: ICreateIdentifierOpts },
context: IRequiredContext
context: IRequiredContext,
): Promise<Omit<IIdentifier, 'provider'>> {
if (this.isUniRegistrarMode()) {
return this.createIdentifierUsingUniRegistrar(context, kms, options)
Expand All @@ -42,7 +48,7 @@ export class LtoDidProvider extends AbstractIdentifierProvider {
private async createIdentifierUsingUniRegistrar(
_context: IAgentContext<IKeyManager>,
_kms?: string,
_options?: ICreateIdentifierOpts
_options?: ICreateIdentifierOpts,
): Promise<Omit<IIdentifier, 'provider'>> {
if (!this.uniRegistrar) {
throw new Error(`Uni registrar mode used, but no registrar is present`)
Expand Down Expand Up @@ -76,7 +82,7 @@ export class LtoDidProvider extends AbstractIdentifierProvider {
private async createIdentifierUsingNodeRPC(
context: IAgentContext<IKeyManager>,
kms?: string,
options?: ICreateIdentifierOpts
options?: ICreateIdentifierOpts,
): Promise<Omit<IIdentifier, 'provider'>> {
const ltoAPI = new LTO(this.opts?.network)
const providedPrivateKeyBase58 = options?.privateKeyHex ? hexToBase58(options?.privateKeyHex) : undefined
Expand All @@ -86,7 +92,7 @@ export class LtoDidProvider extends AbstractIdentifierProvider {
context,
{ kms },
didAccount,
didAccount.sign.privateKey ? base58ToHex(didAccount.getPrivateSignKey()) : undefined
didAccount.sign.privateKey ? base58ToHex(didAccount.getPrivateSignKey()) : undefined,
)

return didService
Expand Down Expand Up @@ -125,7 +131,8 @@ export class LtoDidProvider extends AbstractIdentifierProvider {
}

async deleteIdentifier(args: IIdentifier, context: IAgentContext<IKeyManager>): Promise<boolean> {
return Promise.reject(new Error('Not implemented yet'))
console.log(`Onchain deletion of LTO DID not supported yet: ${args.did}`)
return new Promise(() => false)
}

async addKey(args: { identifier: IIdentifier; key: IKey; options: IAddKeyOpts }, context: IAgentContext<IKeyManager>): Promise<string> {
Expand Down Expand Up @@ -173,20 +180,20 @@ export class LtoDidProvider extends AbstractIdentifierProvider {
{ kms }: { kms?: string; alias?: string; options?: any },
didAccount?: Account,
privateKeyHex?: string,
keyType?: TKeyType
keyType?: TKeyType,
): Promise<IKey> {
const key = privateKeyHex
? await context.agent.keyManagerImport({
kms: kms || this.defaultKms,
publicKeyHex: didAccount ? base58ToHex(didAccount.getPublicSignKey()) : undefined,
kid: didAccount ? `did:lto:${didAccount.address}#sign` : undefined,
type: keyType || 'Ed25519',
privateKeyHex,
})
kms: kms || this.defaultKms,
publicKeyHex: didAccount ? base58ToHex(didAccount.getPublicSignKey()) : undefined,
kid: didAccount ? `did:lto:${didAccount.address}#sign` : undefined,
type: keyType || 'Ed25519',
privateKeyHex,
})
: await context.agent.keyManagerCreate({
kms: kms || this.defaultKms,
type: keyType || 'Ed25519',
})
kms: kms || this.defaultKms,
type: keyType || 'Ed25519',
})

return key
}
Expand Down

0 comments on commit 7347914

Please sign in to comment.