Skip to content

Commit

Permalink
Merge branch 'main' into joel.transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
joeltg committed Feb 13, 2025
2 parents c0f02f0 + 56e156f commit 15e19ea
Show file tree
Hide file tree
Showing 38 changed files with 408 additions and 347 deletions.
6 changes: 3 additions & 3 deletions examples/chat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
"@farcaster/auth-kit": "^0.6.0",
"@farcaster/frame-sdk": "^0.0.26",
"@keplr-wallet/types": "^0.11.64",
"@libp2p/interface": "^2.4.1",
"@libp2p/interface": "^2.5.0",
"@magic-ext/auth": "^4.3.2",
"@metamask/providers": "^14.0.2",
"@multiformats/multiaddr": "^12.3.4",
"@multiformats/multiaddr": "^12.3.5",
"@noble/hashes": "^1.7.1",
"@polkadot/extension-dapp": "^0.46.9",
"@terra-money/feather.js": "^2.0.4",
Expand All @@ -38,7 +38,7 @@
"ethers": "^6.13.5",
"idb": "^8.0.2",
"magic-sdk": "^21.5.0",
"multiformats": "^13.3.1",
"multiformats": "^13.3.2",
"near-api-js": "^2.1.4",
"process": "^0.11.10",
"react": "^18.3.1",
Expand Down
418 changes: 226 additions & 192 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions packages/bootstrap-peer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@
"@chainsafe/libp2p-noise": "^16.0.1",
"@chainsafe/libp2p-yamux": "^7.0.1",
"@ipld/dag-cbor": "^9.2.2",
"@libp2p/crypto": "^5.0.10",
"@libp2p/crypto": "^5.0.11",
"@libp2p/identify": "^3.0.17",
"@libp2p/interface": "^2.4.1",
"@libp2p/peer-id": "^5.0.11",
"@libp2p/ping": "^2.0.17",
"@libp2p/prometheus-metrics": "^4.3.2",
"@libp2p/websockets": "^9.1.4",
"@multiformats/multiaddr": "^12.3.4",
"@libp2p/interface": "^2.5.0",
"@libp2p/peer-id": "^5.0.12",
"@libp2p/ping": "^2.0.18",
"@libp2p/prometheus-metrics": "^4.3.5",
"@libp2p/websockets": "^9.1.5",
"@multiformats/multiaddr": "^12.3.5",
"@types/express": "^4.17.21",
"express": "^4.21.2",
"http-status-codes": "^2.3.0",
"libp2p": "^2.5.2",
"multiformats": "^13.3.1",
"libp2p": "^2.6.2",
"multiformats": "^13.3.2",
"prom-client": "^15.1.2"
}
}
4 changes: 2 additions & 2 deletions packages/chain-atp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
"@ipld/car": "^5.4.0",
"@ipld/dag-cbor": "^9.2.2",
"@ipld/dag-json": "^10.2.3",
"@libp2p/logger": "^5.1.7",
"@libp2p/logger": "^5.1.8",
"@noble/hashes": "^1.7.1",
"multiformats": "^13.3.1"
"multiformats": "^13.3.2"
},
"devDependencies": {
"@canvas-js/chain-atp": "0.14.0-next.1"
Expand Down
4 changes: 2 additions & 2 deletions packages/chain-cosmos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
"@ipld/dag-cbor": "^9.2.2",
"@ipld/dag-json": "^10.2.3",
"@keplr-wallet/types": "^0.11.64",
"@libp2p/logger": "^5.1.7",
"@libp2p/logger": "^5.1.8",
"@noble/curves": "^1.8.1",
"@noble/hashes": "^1.7.1",
"ethers": "^6.13.5",
"multiformats": "^13.3.1"
"multiformats": "^13.3.2"
}
}
6 changes: 3 additions & 3 deletions packages/chain-ethereum-viem/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"@canvas-js/signatures": "0.14.0-next.1",
"@canvas-js/utils": "0.14.0-next.1",
"@ipld/dag-json": "^10.2.3",
"@libp2p/logger": "^5.1.7",
"multiformats": "^13.3.1",
"siwe": "^2.3.2",
"@libp2p/logger": "^5.1.8",
"multiformats": "^13.3.2",
"siwe": "^3.0.0",
"viem": "^2.22.21"
}
}
14 changes: 7 additions & 7 deletions packages/chain-ethereum-viem/test/signer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ed25519 } from "@canvas-js/signatures"
import { SIWESignerViem, validateSessionData } from "@canvas-js/chain-ethereum-viem"

test("create and verify session", async (t) => {
const topic = "example:signer"
const topic = "com.example.app"
const signer = new SIWESignerViem()
const { payload: session, signer: delegateSigner } = await signer.newSession(topic)
t.notThrows(() => signer.verifySession(topic, session))
Expand All @@ -17,7 +17,7 @@ test("create and verify session", async (t) => {
})

test("create and verify session and action", async (t) => {
const topic = "example:signer"
const topic = "com.example.app"
const signer = new SIWESignerViem()
const { payload: session, signer: delegateSigner } = await signer.newSession(topic)
t.notThrows(() => signer.verifySession(topic, session))
Expand All @@ -42,7 +42,7 @@ test("create and verify session and action", async (t) => {
})

test("reject corrupt session signature", async (t) => {
const topic = "example:signer"
const topic = "com.example.app"
const signer = new SIWESignerViem()
const { payload: session } = await signer.newSession(topic)

Expand All @@ -54,11 +54,11 @@ test("reject corrupt session signature", async (t) => {
})

test("reject session signature for wrong topic", async (t) => {
const topic = "example:signer"
const topic2 = "example:signer2"
const topic1 = "com.example.app-1"
const topic2 = "com.example.app-2"
const signer = new SIWESignerViem()
const { payload: session } = await signer.newSession(topic)
const { payload: session1 } = await signer.newSession(topic1)
const { payload: session2 } = await signer.newSession(topic2)

await t.throwsAsync(async () => signer.verifySession(topic, session2))
await t.throwsAsync(async () => signer.verifySession(topic1, session2))
})
6 changes: 3 additions & 3 deletions packages/chain-ethereum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"@canvas-js/signatures": "0.14.0-next.1",
"@canvas-js/utils": "0.14.0-next.1",
"@ipld/dag-json": "^10.2.3",
"@libp2p/logger": "^5.1.7",
"@libp2p/logger": "^5.1.8",
"ethers": "^6.13.5",
"multiformats": "^13.3.1",
"siwe": "^2.3.2"
"multiformats": "^13.3.2",
"siwe": "^3.0.0"
},
"devDependencies": {
"base58-solidity": "^1.0.2"
Expand Down
21 changes: 15 additions & 6 deletions packages/chain-ethereum/src/eip712/Secp256k1DelegateSigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@ import {

import { AbiCoder } from "ethers/abi"

import type { Action, Message, Session, Snapshot, Signature, SignatureScheme, Signer } from "@canvas-js/interfaces"
import type {
Action,
Message,
Session,
Snapshot,
Signature,
SignatureScheme,
Signer,
MessageType,
} from "@canvas-js/interfaces"
import { decodeURI, encodeURI } from "@canvas-js/signatures"
import { assert, prepareMessage, signalInvalidType } from "@canvas-js/utils"

Expand All @@ -28,7 +37,7 @@ export const codecs = {
* - canvas-action-eip712
* - canvas-session-eip712
*/
export class Secp256k1DelegateSigner implements Signer<Action | Session<Eip712SessionData> | Snapshot> {
export class Secp256k1DelegateSigner implements Signer<MessageType<Eip712SessionData>> {
public static eip712ActionTypes = {
Message: [
{ name: "topic", type: "string" },
Expand Down Expand Up @@ -63,7 +72,7 @@ export class Secp256k1DelegateSigner implements Signer<Action | Session<Eip712Se
AuthorizationData: [{ name: "signature", type: "bytes" }],
} satisfies Record<string, TypedDataField[]>

public readonly scheme: SignatureScheme<Action | Session<Eip712SessionData> | Snapshot> = Secp256k1SignatureScheme
public readonly scheme: SignatureScheme<MessageType<Eip712SessionData>> = Secp256k1SignatureScheme
public readonly publicKey: string

readonly #wallet: BaseWallet
Expand All @@ -80,7 +89,7 @@ export class Secp256k1DelegateSigner implements Signer<Action | Session<Eip712Se
this.publicKey = encodeURI(Secp256k1SignatureScheme.type, publicKey)
}

public async sign(message: Message<Action | Session<Eip712SessionData> | Snapshot>): Promise<Signature> {
public async sign(message: Message<MessageType<Eip712SessionData>>): Promise<Signature> {
const { topic, clock, parents, payload } = prepareMessage(message)

if (payload.type === "action") {
Expand Down Expand Up @@ -182,10 +191,10 @@ function getAbiTypeForValue(value: any) {
throw new TypeError(`invalid type ${typeof value}: ${JSON.stringify(value)}`)
}

export const Secp256k1SignatureScheme: SignatureScheme<Action | Session<Eip712SessionData> | Snapshot> = {
export const Secp256k1SignatureScheme: SignatureScheme<MessageType<Eip712SessionData>> = {
type: "secp256k1",
codecs: [codecs.action, codecs.session],
verify(signature: Signature, message: Message<Action | Session<Eip712SessionData> | Snapshot>) {
verify(signature: Signature, message: Message<MessageType<Eip712SessionData>>) {
const { type, publicKey } = decodeURI(signature.publicKey)
assert(type === Secp256k1SignatureScheme.type)

Expand Down
12 changes: 10 additions & 2 deletions packages/chain-ethereum/src/siwf/SIWFSigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ import { verifyMessage, hexlify, getBytes } from "ethers"
import * as siwe from "siwe"
import * as json from "@ipld/dag-json"

import type { Action, Session, Snapshot, AbstractSessionData, DidIdentifier, Signer } from "@canvas-js/interfaces"
import type {
Action,
Session,
Snapshot,
AbstractSessionData,
DidIdentifier,
Signer,
MessageType,
} from "@canvas-js/interfaces"
import { AbstractSessionSigner, ed25519 } from "@canvas-js/signatures"
import { assert, DAYS } from "@canvas-js/utils"

Expand Down Expand Up @@ -75,7 +83,7 @@ export class SIWFSigner extends AbstractSessionSigner<SIWFSessionData> {
authorizationData: SIWFSessionData,
timestamp: number,
privateKey: Uint8Array,
): Promise<{ payload: Session<SIWFSessionData>; signer: Signer<Action | Session<SIWFSessionData> | Snapshot> }> {
): Promise<{ payload: Session<SIWFSessionData>; signer: Signer<MessageType<SIWFSessionData>> }> {
const signer = this.scheme.create({ type: ed25519.type, privateKey })
const did = await this.getDid()

Expand Down
14 changes: 7 additions & 7 deletions packages/chain-ethereum/test/SIWESigner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Action, Session } from "@canvas-js/interfaces"
import { SIWESessionData } from "../src/siwe/types.js"

test("create and verify session", async (t) => {
const topic = "example:signer"
const topic = "com.example.app"
const signer = new SIWESigner()
const { payload, signer: delegateSigner } = await signer.newSession(topic)
const session: Session<SIWESessionData> = payload
Expand All @@ -20,7 +20,7 @@ test("create and verify session", async (t) => {
})

test("create and verify session and action", async (t) => {
const topic = "example:signer"
const topic = "com.example.app"
const signer = new SIWESigner()
const { payload: session, signer: delegateSigner } = await signer.newSession(topic)
t.notThrows(() => signer.verifySession(topic, session))
Expand All @@ -45,7 +45,7 @@ test("create and verify session and action", async (t) => {
})

test("reject corrupt session signature", async (t) => {
const topic = "example:signer"
const topic = "com.example.app"
const signer = new SIWESigner()
const { payload: session } = await signer.newSession(topic)
// corrupt the session signature
Expand All @@ -56,11 +56,11 @@ test("reject corrupt session signature", async (t) => {
})

test("reject session signature for wrong topic", async (t) => {
const topic = "example:signer"
const topic2 = "example:signer2"
const topic1 = "com.example.app-1"
const topic2 = "com.example.app-2"
const signer = new SIWESigner()
const { payload: session } = await signer.newSession(topic)
const { payload: session1 } = await signer.newSession(topic1)
const { payload: session2 } = await signer.newSession(topic2)

await t.throwsAsync(async () => signer.verifySession(topic, session2))
await t.throwsAsync(async () => signer.verifySession(topic1, session2))
})
4 changes: 2 additions & 2 deletions packages/chain-solana/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"@canvas-js/signatures": "0.14.0-next.1",
"@canvas-js/utils": "0.14.0-next.1",
"@ipld/dag-json": "^10.2.3",
"@libp2p/logger": "^5.1.7",
"@libp2p/logger": "^5.1.8",
"@noble/curves": "^1.8.1",
"@solana/web3.js": "^1.93.0",
"multiformats": "^13.3.1"
"multiformats": "^13.3.2"
},
"devDependencies": {
"@canvas-js/chain-solana": "0.14.0-next.1"
Expand Down
4 changes: 2 additions & 2 deletions packages/chain-substrate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
"@canvas-js/signatures": "0.14.0-next.1",
"@canvas-js/utils": "0.14.0-next.1",
"@ipld/dag-json": "^10.2.3",
"@libp2p/logger": "^5.1.7",
"@libp2p/logger": "^5.1.8",
"@noble/hashes": "^1.7.1",
"@polkadot/extension-inject": "^0.46.3",
"@polkadot/keyring": "^12.6.2",
"@polkadot/util-crypto": "^12.2.1",
"multiformats": "^13.3.1"
"multiformats": "^13.3.2"
},
"devDependencies": {
"@polkadot/types": "^10.7.1"
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"@canvas-js/interfaces": "0.14.0-next.1",
"@canvas-js/network-explorer": "0.14.0-next.1",
"@ipld/dag-json": "^10.2.3",
"@libp2p/peer-id": "^5.0.11",
"@multiformats/multiaddr": "^12.3.4",
"@libp2p/peer-id": "^5.0.12",
"@multiformats/multiaddr": "^12.3.5",
"@multiformats/multiaddr-matcher": "^1.6.0",
"@noble/hashes": "^1.7.1",
"@types/websocket": "^1.0.10",
Expand All @@ -34,7 +34,7 @@
"ethers": "^6.13.5",
"express": "^4.21.2",
"http-status-codes": "^2.3.0",
"multiformats": "^13.3.1",
"multiformats": "^13.3.2",
"p-queue": "^8.1.0",
"pkg-dir": "^8.0.0",
"prom-client": "^15.1.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Argv } from "yargs"
import chalk from "chalk"
import * as json from "@ipld/dag-json"

import type { Action, Message, Session, Signature, Snapshot } from "@canvas-js/interfaces"
import type { Action, Message, MessageType, Session, Signature, Snapshot } from "@canvas-js/interfaces"
import { Canvas } from "@canvas-js/core"

import { getContractLocation } from "../utils.js"
Expand Down Expand Up @@ -52,7 +52,7 @@ export async function handler(args: Args) {
const { id, signature, message } = json.parse<{
id: string
signature: Signature
message: Message<Action | Session | Snapshot>
message: Message<MessageType>
}>(line)

try {
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as json from "@ipld/dag-json"
import { StatusCodes } from "http-status-codes"

import type { Action, Message, Session, SessionSigner, Signer } from "@canvas-js/interfaces"
import type { Action, Message, MessageType, Session, SessionSigner, Signer } from "@canvas-js/interfaces"
import { assert } from "@canvas-js/utils"

export class Client {
Expand Down Expand Up @@ -60,7 +60,7 @@ export class Client {
})
}

private async insert(delegateSigner: Signer<Action | Session>, message: Message<Action | Session>): Promise<string> {
private async insert(delegateSigner: Signer<MessageType>, message: Message<MessageType>): Promise<string> {
const signature = await delegateSigner.sign(message)

const res = await fetch(`${this.host}/api/messages`, {
Expand Down
10 changes: 5 additions & 5 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
"@ipld/dag-cbor": "^9.2.2",
"@ipld/dag-json": "^10.2.3",
"@ipld/schema": "^6.0.6",
"@libp2p/interface": "^2.4.1",
"@libp2p/logger": "^5.1.7",
"@libp2p/peer-id": "^5.0.11",
"@multiformats/multiaddr": "^12.3.4",
"@libp2p/interface": "^2.5.0",
"@libp2p/logger": "^5.1.8",
"@libp2p/peer-id": "^5.0.12",
"@multiformats/multiaddr": "^12.3.5",
"@noble/curves": "^1.8.1",
"@noble/hashes": "^1.7.1",
"@types/cors": "^2.8.17",
Expand All @@ -61,7 +61,7 @@
"express": "^4.21.2",
"express-ipld": "^0.0.1",
"http-status-codes": "^2.3.0",
"multiformats": "^13.3.1",
"multiformats": "^13.3.2",
"p-defer": "^4.0.1",
"p-queue": "^8.1.0",
"pg": "^8.13.1",
Expand Down
Loading

0 comments on commit 15e19ea

Please sign in to comment.