Skip to content

Commit

Permalink
feat: update methods of signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
eruizgar91 committed Apr 22, 2024
1 parent 669accb commit 8e4324a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 25 deletions.
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1709,7 +1709,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

> 2 May 2022
- add aave service agreement to ddo when creating nft721 asset [`#248`](https://github.com/nevermined-io/sdk-js/pull/248)
- add aave service agreement to ddo when creating nft721 asset [`#248`](https://github.com/nevermined-io/sdk-js/pull/248)
- Adding v0.19.21 Changelog updates [`c93cdc5`](https://github.com/nevermined-io/sdk-js/commit/c93cdc55f139a43db4130ccb0f80924d2645a931)

#### [v0.19.21](https://github.com/nevermined-io/sdk-js/compare/v0.19.20...v0.19.21)
Expand Down Expand Up @@ -1972,7 +1972,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

> 18 January 2022
- Removing not used parameter [`#186`](https://github.com/nevermined-io/sdk-js/pull/186)
- Removing not used parameter [`#186`](https://github.com/nevermined-io/sdk-js/pull/186)
- [wip] Create agreement+pay in one transaction [`#183`](https://github.com/nevermined-io/sdk-js/pull/183)
- Adapting to contracts `v1.3.3` [`#177`](https://github.com/nevermined-io/sdk-js/pull/177)
- Adding v0.17.2 Changelog updates [`5eddda4`](https://github.com/nevermined-io/sdk-js/commit/5eddda43954e013e6e6f7344c9a877d801aacb5c)
Expand Down Expand Up @@ -2478,7 +2478,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Feature/sync develop [`#268`](https://github.com/nevermined-io/sdk-js/pull/268)
- Quick fix for non-eip1559 networks [`#266`](https://github.com/nevermined-io/sdk-js/pull/266)
- integrate Permissions and refactor search query [`#264`](https://github.com/nevermined-io/sdk-js/pull/264)
- add aave service agreement to ddo when creating nft721 asset [`#248`](https://github.com/nevermined-io/sdk-js/pull/248)
- add aave service agreement to ddo when creating nft721 asset [`#248`](https://github.com/nevermined-io/sdk-js/pull/248)
- Get the keeper version from the artifacts instead of package version [`#244`](https://github.com/nevermined-io/sdk-js/pull/244)
- replace `metadata-api` url by `marketplace-api` and sort type [`#243`](https://github.com/nevermined-io/sdk-js/pull/243)
- fixing issues with BigNumbers [`#246`](https://github.com/nevermined-io/sdk-js/pull/246)
Expand Down Expand Up @@ -2517,7 +2517,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Feature/190 add did to sec markets [`#191`](https://github.com/nevermined-io/sdk-js/pull/191)
- Adding utility methods for getting nft token uri [`#189`](https://github.com/nevermined-io/sdk-js/pull/189)
- Lint ... [`#187`](https://github.com/nevermined-io/sdk-js/pull/187)
- Removing not used parameter [`#186`](https://github.com/nevermined-io/sdk-js/pull/186)
- Removing not used parameter [`#186`](https://github.com/nevermined-io/sdk-js/pull/186)
- [wip] Create agreement+pay in one transaction [`#183`](https://github.com/nevermined-io/sdk-js/pull/183)
- Adapting to contracts `v1.3.3` [`#177`](https://github.com/nevermined-io/sdk-js/pull/177)
- Correct typo in route [`#184`](https://github.com/nevermined-io/sdk-js/pull/184)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nevermined-io/sdk",
"version": "3.0.0-rc9",
"version": "3.0.0-rc10",
"description": "Javascript SDK for connecting with Nevermined Data Platform ",
"main": "./dist/node/sdk.js",
"typings": "./dist/node/sdk.d.ts",
Expand Down
6 changes: 3 additions & 3 deletions src/models/NvmAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class NvmAccount {
public babyY?: string
public babySecret?: string
private accountSigner?: Account
private zeroDevSigner?: KernelSmartAccount<any, any, any> // ZeroDevAccountSigner<'ECDSA'> | SessionKeyProvider
private zeroDevSigner?: KernelSmartAccount<any> // ZeroDevAccountSigner<'ECDSA'> | SessionKeyProvider
public accountType: NvmAccountType = { signerType: 'local', isZeroDev: false }

/**
Expand Down Expand Up @@ -48,7 +48,7 @@ export class NvmAccount {
* @returns The nevermined account
*/
static async fromZeroDevSigner(
signer: KernelSmartAccount<any, any>, // | ZeroDevAccountSigner<'ECDSA'> | SessionKeyProvider,
signer: KernelSmartAccount<any>, // | ZeroDevAccountSigner<'ECDSA'> | SessionKeyProvider,
): Promise<NvmAccount> {
const address = signer.address
const account = new NvmAccount(address, { signerType: 'zerodev', isZeroDev: true })
Expand All @@ -71,7 +71,7 @@ export class NvmAccount {
public getType() {
return this.accountType.signerType
}
public getZeroDevSigner(): KernelSmartAccount<any, any, any> {
public getZeroDevSigner(): KernelSmartAccount<any> {
return this.zeroDevSigner
}

Expand Down
7 changes: 4 additions & 3 deletions src/nevermined/NvmApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { SubscribablePromise } from '../utils/SubscribablePromise'
import { CreateProgressStep, OrderProgressStep, UpdateProgressStep } from './ProgressSteps'
import { createEcdsaKernelAccountClient } from '@zerodev/presets/zerodev'
import { arbitrumSepolia } from 'viem/chains'
import { ENTRYPOINT_ADDRESS_V07 } from 'permissionless'
import { ENTRYPOINT_ADDRESS_V07, providerToSmartAccountSigner } from 'permissionless'

export enum NVMAppEnvironments {
Staging = 'staging',
Expand Down Expand Up @@ -160,14 +160,15 @@ export class NvmApp {

if (config && config.zeroDevProjectId) {
const signer = this.fullSDK.accounts.getAccount(account as string)
if (!signer) {
const smartAccountSigner = providerToSmartAccountSigner(config.web3Provider)
if (!smartAccountSigner) {
throw new Web3Error('Account not found')
}

const kernelClient = await createEcdsaKernelAccountClient({
chain: arbitrumSepolia,
projectId: config.zeroDevProjectId,
signer: signer.getAccountSigner(),
signer: smartAccountSigner,
paymaster: 'SPONSOR',
entryPointAddress: ENTRYPOINT_ADDRESS_V07,
})
Expand Down
9 changes: 0 additions & 9 deletions src/nevermined/utils/JwtUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { KernelSmartAccount } from '@zerodev/sdk'
import { JWSHeaderParameters, SignJWT, decodeJwt, importJWK } from 'jose'
import { Account, Hash, LocalAccount, hexToBytes, toHex } from 'viem'
import { Instantiable, InstantiableConfig } from '../../Instantiable.abstract'
Expand Down Expand Up @@ -119,14 +118,6 @@ export class JwtUtils extends Instantiable {
this.tokenCache = new Map()
}

public async getSigner(account: NvmAccount): Promise<NvmAccount | KernelSmartAccount<any, any>> {
const address = getChecksumAddress(account.getId())

return account.isZeroDev()
? account.getZeroDevSigner()
: await this.nevermined.accounts.getAccount(address)
}

public generateCacheKey(...args: string[]): string {
return args.join()
}
Expand Down
8 changes: 3 additions & 5 deletions src/nevermined/utils/SignatureUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ export class SignatureUtils extends Instantiable {
typeof account === 'string' ? this.nevermined.accounts.getAccount(account) : account

if (nvmAccount.isZeroDev()) {
const result = await nvmAccount
.getZeroDevSigner()
.signMessage({ message: text as `0x${string}` })
const result = await nvmAccount.getAccountSigner().signMessage({ message })
return result
} else if (nvmAccount.accountType.signerType === 'local') {
return (nvmAccount.getAccountSigner() as LocalAccount).signMessage({
Expand All @@ -46,7 +44,7 @@ export class SignatureUtils extends Instantiable {
typeof account === 'string' ? this.nevermined.accounts.getAccount(account) : account

if (nvmAccount.isZeroDev()) {
const signature = await nvmAccount.getZeroDevSigner().signTypedData({
const signature = await nvmAccount.getAccountSigner().signTypedData({
domain,
types: types as any,
message: value,
Expand Down Expand Up @@ -77,7 +75,7 @@ export class SignatureUtils extends Instantiable {
typeof account === 'string' ? this.nevermined.accounts.getAccount(account) : account

if (nvmAccount.isZeroDev()) {
return await nvmAccount.getZeroDevSigner().signTransaction({ data: tx })
return await nvmAccount.getAccountSigner().signTransaction({ data: tx })
// TODO: Implement ZeroDev signing
return `0x`
} else if (nvmAccount.accountType.signerType === 'local') {
Expand Down

0 comments on commit 8e4324a

Please sign in to comment.