Skip to content
This repository has been archived by the owner on Jan 1, 2025. It is now read-only.

Commit

Permalink
fix: 4.0.0 test fixes (#70)
Browse files Browse the repository at this point in the history
* fix: test fixes

* fix: test coverage ready
  • Loading branch information
elribonazo authored Jan 4, 2024
1 parent 02b9f47 commit b21f7b8
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 241 deletions.
145 changes: 71 additions & 74 deletions packages/database/src/index.ts

Large diffs are not rendered by default.

29 changes: 11 additions & 18 deletions packages/database/src/schemas/Credential.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
AnonCredsCredential,
AnonCredsCredentialProperties,
AnonCredsRecoveryId,
type Domain,
JWTCredential,
JWTVerifiableCredentialRecoveryId
} from '@atala/prism-wallet-sdk'
import SDK from '@atala/prism-wallet-sdk'
import type { Schema } from '../types'
import { type RxCollection, type RxDocument } from 'rxdb'

Expand Down Expand Up @@ -78,27 +71,27 @@ const CredentialSchema: Schema<CredentialSchemaType> = {

export type CredentialDocument = RxDocument<CredentialSchemaType>
export interface CredentialMethodTypes {
toDomainCredential: (this: CredentialSchemaType) => Domain.Credential
toDomainCredential: (this: CredentialSchemaType) => SDK.Domain.Credential
}

export const CredentialMethods: CredentialMethodTypes = {
toDomainCredential: function toDomainCredential(this: CredentialSchemaType) {
if (this.recoveryId === JWTVerifiableCredentialRecoveryId) {
if (this.recoveryId === SDK.JWTVerifiableCredentialRecoveryId) {
const jwtString = Buffer.from(this.credentialData).toString()
const jwtObj = JSON.parse(jwtString)
return JWTCredential.fromJWT(jwtObj, jwtString)
} else if (this.recoveryId === AnonCredsRecoveryId) {
return SDK.JWTCredential.fromJWT(jwtObj, jwtString)
} else if (this.recoveryId === SDK.AnonCredsRecoveryId) {
const credentialData = Buffer.from(this.credentialData).toString()
const credentialJson = JSON.parse(credentialData)
return new AnonCredsCredential({
schema_id: credentialJson[AnonCredsCredentialProperties.schemaId],
return new SDK.AnonCredsCredential({
schema_id: credentialJson[SDK.AnonCredsCredentialProperties.schemaId],
cred_def_id:
credentialJson[AnonCredsCredentialProperties.credentialDefinitionId],
values: credentialJson[AnonCredsCredentialProperties.values],
signature: credentialJson[AnonCredsCredentialProperties.signature],
credentialJson[SDK.AnonCredsCredentialProperties.credentialDefinitionId],
values: credentialJson[SDK.AnonCredsCredentialProperties.values],
signature: credentialJson[SDK.AnonCredsCredentialProperties.signature],
signature_correctness_proof:
credentialJson[
AnonCredsCredentialProperties.signatureCorrectnessProof
SDK.AnonCredsCredentialProperties.signatureCorrectnessProof
]
})
} else {
Expand Down
14 changes: 6 additions & 8 deletions packages/database/src/schemas/CredentialRequestMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {
type Domain
} from '@atala/prism-wallet-sdk'
import SDK from '@atala/prism-wallet-sdk'
import type { Schema } from '../types'
import { type RxCollection, type RxDocument } from 'rxdb'

Expand Down Expand Up @@ -48,23 +46,23 @@ export type CredentialRequestMetadataDocument =
export interface CredentialRequestMetadataMethodTypes {
toDomainCredentialRequestMetadata: (
this: CredentialRequestMetadataSchemaType
) => Domain.Anoncreds.CredentialRequestMeta
) => SDK.Domain.Anoncreds.CredentialRequestMeta
}

export const CredentialRequestMetadataMethods: CredentialRequestMetadataMethodTypes =
{
toDomainCredentialRequestMetadata:
function toDomainCredentialRequestMetadata (
function toDomainCredentialRequestMetadata(
this: CredentialRequestMetadataSchemaType
) {
return this
}
}

export type CredentialRequestMetadataCollection = RxCollection<
CredentialRequestMetadataSchemaType,
CredentialRequestMetadataMethodTypes,
CredentialRequestMetadataDocument
CredentialRequestMetadataSchemaType,
CredentialRequestMetadataMethodTypes,
CredentialRequestMetadataDocument
>

export default CredentialRequestMetadataSchema
16 changes: 8 additions & 8 deletions packages/database/src/schemas/LinkSecret.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Domain } from '@atala/prism-wallet-sdk'
import SDK from '@atala/prism-wallet-sdk'
import type { Schema } from '../types'
import { type RxCollection, type RxDocument } from 'rxdb'

Expand All @@ -25,22 +25,22 @@ const LinkSecretSchema: Schema<LinkSecretSchemaType> = {
}

export type LinkSecretDocument = RxDocument<
LinkSecretSchemaType,
LinkSecretMethodTypes
LinkSecretSchemaType,
LinkSecretMethodTypes
>

export interface LinkSecretMethodTypes {
toDomainLinkSecret: (this: LinkSecretDocument) => Domain.Anoncreds.LinkSecret
toDomainLinkSecret: (this: LinkSecretDocument) => SDK.Domain.Anoncreds.LinkSecret
}

export type LinkSecretColletion = RxCollection<
LinkSecretSchemaType,
LinkSecretMethodTypes,
LinkSecretDocument
LinkSecretSchemaType,
LinkSecretMethodTypes,
LinkSecretDocument
>

export const LinkSecretMethods: LinkSecretMethodTypes = {
toDomainLinkSecret: function toDomainLinkSecret (this: LinkSecretDocument) {
toDomainLinkSecret: function toDomainLinkSecret(this: LinkSecretDocument) {
return this.secret
}
}
Expand Down
18 changes: 9 additions & 9 deletions packages/database/src/schemas/Mediator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type RxCollection, type RxDocument } from 'rxdb'
import type { Schema } from '../types'
import { Domain } from '@atala/prism-wallet-sdk'
import SDK from '@atala/prism-wallet-sdk'

export interface MediatorSchemaType {
id: string
Expand Down Expand Up @@ -34,21 +34,21 @@ const MediatorSchema: Schema<MediatorSchemaType> = {

export type MediatorDocument = RxDocument<MediatorSchemaType>
export interface MediatorMethodTypes {
toDomainMediator: (this: RxDocument<MediatorSchemaType, MediatorMethodTypes>) => Domain.Mediator
toDomainMediator: (this: RxDocument<MediatorSchemaType, MediatorMethodTypes>) => SDK.Domain.Mediator
}
export type MediatorCollection = RxCollection<
MediatorSchemaType,
MediatorMethodTypes,
MediatorDocument
MediatorSchemaType,
MediatorMethodTypes,
MediatorDocument
>

export const MediatorMethods: MediatorMethodTypes = {
toDomainMediator: function toDomainMediator (this: RxDocument<MediatorSchemaType, MediatorMethodTypes>) {
toDomainMediator: function toDomainMediator(this: RxDocument<MediatorSchemaType, MediatorMethodTypes>) {
const mediator = this.toJSON()
return {
hostDID: Domain.DID.fromString(mediator.hostDID),
routingDID: Domain.DID.fromString(mediator.routingDID),
mediatorDID: Domain.DID.fromString(mediator.mediatorDID)
hostDID: SDK.Domain.DID.fromString(mediator.hostDID),
routingDID: SDK.Domain.DID.fromString(mediator.routingDID),
mediatorDID: SDK.Domain.DID.fromString(mediator.mediatorDID)
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions packages/database/src/schemas/Message.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Domain } from '@atala/prism-wallet-sdk'
import SDK from '@atala/prism-wallet-sdk'
import type { Schema } from '../types'
import { type RxCollection, type RxDocument } from 'rxdb'

Expand All @@ -8,13 +8,13 @@ export interface MessageSchemaType {
readonly piuri: string
readonly from?: string | undefined
readonly to?: string | undefined
readonly attachments: Domain.AttachmentDescriptor[]
readonly attachments: SDK.Domain.AttachmentDescriptor[]
readonly thid?: string
readonly extraHeaders: string[]
readonly createdTime: string
readonly expiresTimePlus: string
readonly ack: string[]
readonly direction: Domain.MessageDirection
readonly direction: SDK.Domain.MessageDirection
readonly fromPrior?: string | undefined
readonly pthid?: string | undefined
}
Expand Down Expand Up @@ -107,18 +107,18 @@ const MessageSchema: Schema<MessageSchemaType> = {
export type MessageDocument = RxDocument<MessageSchemaType, MessageMethodTypes>

export interface MessageMethodTypes {
toDomainMessage: (this: MessageDocument) => Domain.Message
toDomainMessage: (this: MessageDocument) => SDK.Domain.Message
}

export type MessageColletion = RxCollection<
MessageSchemaType,
MessageMethodTypes,
MessageDocument
MessageSchemaType,
MessageMethodTypes,
MessageDocument
>

export const MessageMethods: MessageMethodTypes = {
toDomainMessage: function toDomainMessage (this: MessageDocument) {
return Domain.Message.fromJson(JSON.stringify(this))
toDomainMessage: function toDomainMessage(this: MessageDocument) {
return SDK.Domain.Message.fromJson(JSON.stringify(this))
}
}

Expand Down
73 changes: 34 additions & 39 deletions packages/database/src/schemas/PrivateKey.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import {
Ed25519PrivateKey,
KeyProperties,
Secp256k1PrivateKey,
X25519PrivateKey,
Domain
} from '@atala/prism-wallet-sdk'
import SDK from '@atala/prism-wallet-sdk'
import type { Schema } from '../types'
import { type RxCollection, type RxDocument } from 'rxdb'


export interface KeySpec {
name: string
type: string
Expand Down Expand Up @@ -59,38 +54,38 @@ const PrivateKeySchema: Schema<KeySchemaType> = {
}

export interface PrivateKeyMethodTypes {
toDomainPrivateKey: (this: PrivateKeyDocument) => Domain.PrivateKey
toDomainPrivateKey: (this: PrivateKeyDocument) => SDK.Domain.PrivateKey
}
export type PrivateKeyColletion = RxCollection<
KeySchemaType,
PrivateKeyMethodTypes,
PrivateKeyDocument
KeySchemaType,
PrivateKeyMethodTypes,
PrivateKeyDocument
>
export type PrivateKeyDocument = RxDocument<
KeySchemaType,
PrivateKeyMethodTypes
KeySchemaType,
PrivateKeyMethodTypes
>

export const PrivateKeyMethods: PrivateKeyMethodTypes = {
toDomainPrivateKey: function toDomainPrivateKey (this: PrivateKeyDocument) {
toDomainPrivateKey: function toDomainPrivateKey(this: PrivateKeyDocument) {
const { type, keySpecification } = this
const curve = keySpecification.find(
(item) => item.name === KeyProperties.curve
(item) => item.name === SDK.KeyProperties.curve
)
const raw = keySpecification.find(
(item) => item.name === KeyProperties.rawKey
(item) => item.name === SDK.KeyProperties.rawKey
)
if (!(type in Domain.KeyTypes)) {
if (!(type in SDK.Domain.KeyTypes)) {
throw new Error(`Invalid KeyType ${type || 'undefined'}`)
}
if (!curve) {
throw new Error('Undefined key curve')
}

if (
curve.value !== Domain.Curve.SECP256K1 &&
curve.value !== Domain.Curve.ED25519 &&
curve.value !== Domain.Curve.X25519
curve.value !== SDK.Domain.Curve.SECP256K1 &&
curve.value !== SDK.Domain.Curve.ED25519 &&
curve.value !== SDK.Domain.Curve.X25519
) {
throw new Error(`Invalid key curve ${curve.value}`)
}
Expand All @@ -100,59 +95,59 @@ export const PrivateKeyMethods: PrivateKeyMethodTypes = {
}

/* istanbul ignore else -- @preserve */
if (curve.value === Domain.Curve.SECP256K1) {
if (curve.value === SDK.Domain.Curve.SECP256K1) {
const index = keySpecification.find(
(item) => item.name === KeyProperties.index
(item) => item.name === SDK.KeyProperties.index
)
const seed = keySpecification.find(
(item) => item.name === KeyProperties.seed
(item) => item.name === SDK.KeyProperties.seed
)

const privateKey = new Secp256k1PrivateKey(
const privateKey = new SDK.Secp256k1PrivateKey(
Buffer.from(raw.value, 'hex')
)

privateKey.keySpecification.set(Domain.KeyProperties.rawKey, raw.value)
privateKey.keySpecification.set(SDK.Domain.KeyProperties.rawKey, raw.value)

privateKey.keySpecification.set(
Domain.KeyProperties.curve,
Domain.Curve.SECP256K1
SDK.Domain.KeyProperties.curve,
SDK.Domain.Curve.SECP256K1
)

if (index) {
privateKey.keySpecification.set(
Domain.KeyProperties.index,
SDK.Domain.KeyProperties.index,
index.value
)
}

if (seed) {
privateKey.keySpecification.set(
Domain.KeyProperties.seed,
SDK.Domain.KeyProperties.seed,
seed.value
)
}

return privateKey
} else if (curve.value === Domain.Curve.ED25519) {
const privateKey = new Ed25519PrivateKey(Buffer.from(raw.value, 'hex'))
} else if (curve.value === SDK.Domain.Curve.ED25519) {
const privateKey = new SDK.Ed25519PrivateKey(Buffer.from(raw.value, 'hex'))

privateKey.keySpecification.set(Domain.KeyProperties.rawKey, raw.value)
privateKey.keySpecification.set(SDK.Domain.KeyProperties.rawKey, raw.value)

privateKey.keySpecification.set(
Domain.KeyProperties.curve,
Domain.Curve.ED25519
SDK.Domain.KeyProperties.curve,
SDK.Domain.Curve.ED25519
)

return privateKey
} else if (curve.value === Domain.Curve.X25519) {
const privateKey = new X25519PrivateKey(Buffer.from(raw.value, 'hex'))
} else if (curve.value === SDK.Domain.Curve.X25519) {
const privateKey = new SDK.X25519PrivateKey(Buffer.from(raw.value, 'hex'))

privateKey.keySpecification.set(Domain.KeyProperties.rawKey, raw.value)
privateKey.keySpecification.set(SDK.Domain.KeyProperties.rawKey, raw.value)

privateKey.keySpecification.set(
Domain.KeyProperties.curve,
Domain.Curve.X25519
SDK.Domain.KeyProperties.curve,
SDK.Domain.Curve.X25519
)

return privateKey
Expand Down
6 changes: 4 additions & 2 deletions packages/database/tests/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import {
import SDK from "@atala/prism-wallet-sdk";
const {
Ed25519KeyPair,
Ed25519PrivateKey,
Secp256k1KeyPair,
Secp256k1PrivateKey,
X25519KeyPair,
X25519PrivateKey,
Domain,
} from "@atala/prism-wallet-sdk";
} = SDK;

const secpPrivateKey = new Secp256k1PrivateKey(
new Uint8Array([
45, 182, 188, 189, 107, 229, 136, 180, 199, 177, 110, 84, 98, 140, 121, 84,
Expand Down
Loading

0 comments on commit b21f7b8

Please sign in to comment.