Skip to content
This repository was archived by the owner on Mar 10, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions apps/explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
"@ceramic-sdk/model-instance-protocol": "workspace:^",
"@ceramic-sdk/model-protocol": "workspace:^",
"@didtools/key-did": "^1.0.0",
"@mantine/core": "^7.11.2",
"@mantine/hooks": "^7.11.2",
"@mantine/core": "^7.12.2",
"@mantine/hooks": "^7.12.2",
"@tabler/icons-react": "^3.14.0",
"@tanstack/react-query": "^5.52.2",
"@tanstack/react-router": "^1.51.2",
"codeco": "^1.4.2",
"@tanstack/react-query": "^5.53.1",
"@tanstack/react-router": "^1.51.6",
"codeco": "^1.4.3",
"jotai": "^2.9.2",
"multiformats": "^13.2.2",
"react": "^18.3.1",
Expand All @@ -32,9 +32,9 @@
"devDependencies": {
"@ceramic-sdk/model-client": "workspace:^",
"@ceramic-sdk/model-instance-client": "workspace:^",
"@tanstack/router-devtools": "^1.51.2",
"@tanstack/router-plugin": "^1.51.0",
"@types/react": "^18.3.3",
"@tanstack/router-devtools": "^1.51.6",
"@tanstack/router-plugin": "^1.51.6",
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react-swc": "^3.5.0",
"postcss": "^8.4.40",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@biomejs/biome": "1.8.3",
"@jest/globals": "^29.7.0",
"@swc/cli": "^0.4.0",
"@swc/core": "^1.7.11",
"@swc/core": "^1.7.22",
"@swc/jest": "^0.2.36",
"@types/jest": "^29.5.12",
"@types/node": "^20.14.12",
Expand Down
2 changes: 1 addition & 1 deletion packages/events/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@ipld/dag-cbor": "^9.2.1",
"@ipld/dag-json": "^10.2.2",
"cartonne": "^3.0.1",
"codeco": "^1.4.2",
"codeco": "^1.4.3",
"dag-jose": "^5.1.1",
"multiformats": "^13.2.2",
"multihashes-sync": "^2.0.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/http-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
},
"dependencies": {
"@ceramic-sdk/events": "workspace:^",
"openapi-fetch": "^0.11.1"
"openapi-fetch": "^0.11.3"
},
"devDependencies": {
"cartonne": "^3.0.1",
"codeco": "^1.4.2",
"codeco": "^1.4.3",
"multiformats": "^13.2.2",
"openapi-typescript": "^7.3.0",
"openapi-typescript": "^7.3.3",
"type-fest": "^4.26.0"
},
"jest": {
Expand Down
2 changes: 1 addition & 1 deletion packages/identifiers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"dependencies": {
"@ipld/dag-cbor": "^9.2.1",
"codeco": "^1.4.2",
"codeco": "^1.4.3",
"mapmoize": "^1.2.1",
"multiformats": "^13.2.2",
"uint8arrays": "^5.1.0",
Expand Down
19 changes: 12 additions & 7 deletions packages/model-client/test/lib.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
MODEL_RESOURCE_URI,
type ModelDefinition,
} from '@ceramic-sdk/model-protocol'
import { EthereumDID } from '@ceramic-sdk/test-utils'
import { createSession, ethereum } from '@ceramic-sdk/test-utils'
import { getAuthenticatedDID } from '@didtools/key-did'

import { createInitEvent } from '../src/index.js'
Expand Down Expand Up @@ -42,14 +42,19 @@ describe('createInitEvent()', () => {
})

test('supports did:pkh', async () => {
const did = await EthereumDID.random({
domain: 'test',
resources: [MODEL_RESOURCE_URI],
})
const authMethod = await ethereum.authMethodFromRandomKey()

const [validSession, invalidSession] = await Promise.all([
did.createSession({ expirationTime: null }),
did.createSession({ expiresInSecs: 60 }),
createSession(authMethod, {
domain: 'test',
resources: [MODEL_RESOURCE_URI],
expirationTime: null,
}),
createSession(authMethod, {
domain: 'test',
resources: [MODEL_RESOURCE_URI],
expiresInSecs: 60,
}),
])

await expect(async () => {
Expand Down
23 changes: 12 additions & 11 deletions packages/model-handler/test/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
type ModelEvent,
ModelInitEventPayload,
} from '@ceramic-sdk/model-protocol'
import { EthereumDID } from '@ceramic-sdk/test-utils'
import { createSession, ethereum } from '@ceramic-sdk/test-utils'
import { asDIDString } from '@didtools/codecs'
import { createDID, getAuthenticatedDID } from '@didtools/key-did'
import { jest } from '@jest/globals'
Expand Down Expand Up @@ -105,18 +105,19 @@ describe('handleInitEvent()', () => {
})

test('supports did:pkh', async () => {
const did = await EthereumDID.random({
domain: 'test',
resources: [MODEL_RESOURCE_URI],
})
const authMethod = await ethereum.authMethodFromRandomKey()

const [validEvent, invalidEvent] = await Promise.all([
did
.createSession({ expirationTime: null })
.then((session) => createModelEvent(session.did)),
did
.createSession({ expiresInSecs: 60 })
.then((session) => createModelEvent(session.did)),
createSession(authMethod, {
domain: 'test',
resources: [MODEL_RESOURCE_URI],
expirationTime: null,
}).then((session) => createModelEvent(session.did)),
createSession(authMethod, {
domain: 'test',
resources: [MODEL_RESOURCE_URI],
expiresInSecs: 60,
}).then((session) => createModelEvent(session.did)),
])

await expect(async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/model-instance-handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@ceramic-sdk/model-instance-protocol": "workspace:^",
"ajv": "^8.17.1",
"ajv-formats": "^3.0.1",
"codeco": "^1.4.2",
"codeco": "^1.4.3",
"fast-json-patch": "^3.1.1",
"uint8arrays": "^5.1.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/model-instance-protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@ceramic-sdk/events": "workspace:^",
"@ceramic-sdk/identifiers": "workspace:^",
"@didtools/codecs": "^3.0.0",
"codeco": "^1.4.2",
"codeco": "^1.4.3",
"object-sizeof": "^2.6.4"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/model-protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@didtools/codecs": "^3.0.0",
"ajv": "^8.17.1",
"ajv-formats": "^3.0.1",
"codeco": "^1.4.2",
"codeco": "^1.4.3",
"json-ptr": "^3.1.1"
},
"devDependencies": {
Expand Down
11 changes: 10 additions & 1 deletion packages/test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,20 @@
},
"dependencies": {
"@didtools/cacao": "^3.0.1",
"@didtools/key-webauthn": "^2.0.2",
"@didtools/key-webcrypto": "^0.2.0",
"@didtools/pkh-solana": "^0.2.0",
"@noble/curves": "^1.5.0",
"@noble/hashes": "^1.4.0",
"@solana/signers": "^2.0.0-rc.1",
"caip": "^1.1.1",
"cborg": "^4.2.3",
"did-session": "^4.0.0",
"dids": "^5.0.2",
"viem": "^2.20.1"
"key-did-resolver": "^4.0.0",
"multiformats": "^13.2.2",
"uint8arrays": "^5.1.0",
"viem": "^2.21.0"
},
"devDependencies": {
"@didtools/pkh-ethereum": "^0.6.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
type Cacao,
CacaoBlock,
} from '@didtools/cacao'
import { getAuthenticatedDID } from '@didtools/key-did'
import {
type CreateJWSOptions,
DID,
Expand All @@ -16,14 +15,13 @@ import { CID } from 'multiformats/cid'
const VALID_EXPIRATION_TIME = new Date(9999, 0).toISOString()
const INVALID_EXPIRATION_TIME = new Date(2000, 0).toISOString()

export const keyDID = await getAuthenticatedDID(new Uint8Array(32))

export type CustomCreateJWSOptions = CreateJWSOptions & {
capability?: Cacao
}

export class CustomCapabilityDID extends DID {
get capability(): Cacao {
// @ts-ignore private field
return this._capability
}

Expand All @@ -32,9 +30,12 @@ export class CustomCapabilityDID extends DID {
payload: T,
options: CustomCreateJWSOptions = {},
): Promise<DagJWS> {
// @ts-ignore private field
if (this._client == null) throw new Error('No provider available')
// @ts-ignore private field
if (this._id == null) throw new Error('DID is not authenticated')
// Use capability from options when provided
// @ts-ignore private field
const capability = options.capability ?? this._capability
if (capability) {
const cacaoBlock = await CacaoBlock.fromCacao(capability)
Expand All @@ -47,7 +48,9 @@ export class CustomCapabilityDID extends DID {
options.protected = options.protected || {}
options.protected.cap = `ipfs://${capCID?.toString()}`
}
// @ts-ignore private field
const { jws } = await this._client.request('did_createJWS', {
// @ts-ignore private field
did: this._id,
...options,
payload,
Expand All @@ -70,6 +73,7 @@ export class CustomCapabilityDID extends DID {
}

export async function createCapabilityDID(
keyDID: DID,
authMethod: AuthMethod,
authParams: AuthMethodOpts = {},
): Promise<CustomCapabilityDID> {
Expand All @@ -80,9 +84,12 @@ export async function createCapabilityDID(
...authParams,
})
const did = new CustomCapabilityDID({
// @ts-ignore private field
provider: keyDID._client?.connection,
// @ts-ignore private field
resolver: keyDID._resolver,
capability,
// @ts-ignore private field
parent: keyDID._parentId,
})
await did.authenticate()
Expand All @@ -95,9 +102,13 @@ export class ExpiredCapabilityDID extends DID {
payload: T,
options: CreateJWSOptions = {},
): Promise<DagJWS> {
// @ts-ignore private field
if (this._client == null) throw new Error('No provider available')
// @ts-ignore private field
if (this._id == null) throw new Error('DID is not authenticated')
// @ts-ignore private field
if (this._capability) {
// @ts-ignore private field
const cacaoBlock = await CacaoBlock.fromCacao(this._capability)
const capCID = CID.asCID(cacaoBlock.cid)
if (!capCID) {
Expand All @@ -108,7 +119,9 @@ export class ExpiredCapabilityDID extends DID {
options.protected = options.protected || {}
options.protected.cap = `ipfs://${capCID?.toString()}`
}
// @ts-ignore private field
const { jws } = await this._client.request('did_createJWS', {
// @ts-ignore private field
did: this._id,
...options,
payload,
Expand All @@ -118,6 +131,7 @@ export class ExpiredCapabilityDID extends DID {
}

export async function createExpiredCapabilityDID(
keyDID: DID,
authMethod: AuthMethod,
authParams: AuthMethodOpts = {},
): Promise<DID> {
Expand All @@ -128,9 +142,12 @@ export async function createExpiredCapabilityDID(
...authParams,
})
const did = new ExpiredCapabilityDID({
// @ts-ignore private field
provider: keyDID._client?.connection,
// @ts-ignore private field
resolver: keyDID._resolver,
capability,
// @ts-ignore private field
parent: keyDID._parentId,
})
await did.authenticate()
Expand Down
39 changes: 39 additions & 0 deletions packages/test-utils/src/ethereum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import type { AuthMethod } from '@didtools/cacao'
import type { EIP1193Provider, Hex } from 'viem'
import { generatePrivateKey } from 'viem/accounts'

import { createProvider, getAccount } from './ethereum/provider.js'
import { createAuthMethod } from './ethereum/siwe.js'

// Default private key used for tests
const PRIVATE_KEY =
'0xe50df915de22bad5bf1abf43f78b55d64640afdcdfa6b1699a514d97662b23f7' as Hex

// Re-exports from viem
export { generatePrivateKey }
export type { EIP1193Provider, Hex }

// Re-exports useful internals
export { createAuthMethod, createProvider, getAccount }

export async function authMethodFromProvider(
provider: EIP1193Provider,
): Promise<AuthMethod> {
const accountId = await getAccount(provider)
return createAuthMethod(provider, accountId) as AuthMethod
}

export async function authMethodFromPrivateKey(
privateKey: Hex,
): Promise<AuthMethod> {
const provider = createProvider(privateKey)
return await authMethodFromProvider(provider)
}

export async function authMethodFromRandomKey(): Promise<AuthMethod> {
return await authMethodFromPrivateKey(generatePrivateKey())
}

export async function getAuthMethod(): Promise<AuthMethod> {
return await authMethodFromPrivateKey(PRIVATE_KEY)
}
Loading