Skip to content

Commit

Permalink
Merge pull request #687 from nevermined-io/feat/reduce-session-key-size
Browse files Browse the repository at this point in the history
Feat/reduce session key size
  • Loading branch information
eruizgar91 authored Jul 3, 2024
2 parents f02e652 + b41026a commit 195b66b
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 13 deletions.
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,36 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [v3.0.16-rc3](https://github.com/nevermined-io/sdk-js/compare/v3.0.16-rc2...v3.0.16-rc3)

> 2 July 2024
- fix: webpack error [`d2984be`](https://github.com/nevermined-io/sdk-js/commit/d2984beeaedaea67b1c5fd3deba35eb7d050e745)
- fix: webpack error [`34fa0f7`](https://github.com/nevermined-io/sdk-js/commit/34fa0f70bad0a89aa3d36d1e168d415ba0868bb5)
- Automated CHANGELOG.md update [`adde181`](https://github.com/nevermined-io/sdk-js/commit/adde181880e815e6003a13bb67850658e7ff6278)

#### [v3.0.16-rc2](https://github.com/nevermined-io/sdk-js/compare/v3.0.16-rc1...v3.0.16-rc2)

> 1 July 2024
- Automated CHANGELOG.md update [`694ca68`](https://github.com/nevermined-io/sdk-js/commit/694ca680e3ac874fe13b3f37e7f4fda02f7369b9)
- fix: issue loading nft contract when no artifacts folder [`a285fc0`](https://github.com/nevermined-io/sdk-js/commit/a285fc07738569b1b39c35bca4c6099fa4d5c198)

#### [v3.0.16-rc1](https://github.com/nevermined-io/sdk-js/compare/v3.0.16-rc0...v3.0.16-rc1)

> 28 June 2024
- fix: bug with contracthandler [`e3d3ee6`](https://github.com/nevermined-io/sdk-js/commit/e3d3ee69038e0474ba61e1cde13892b5e8e38bca)
- Automated CHANGELOG.md update [`8a30fd3`](https://github.com/nevermined-io/sdk-js/commit/8a30fd351f1d84d0247cd4bb669572d28aac03a6)

#### [v3.0.16-rc0](https://github.com/nevermined-io/sdk-js/compare/v3.0.15...v3.0.16-rc0)

> 28 June 2024
- docs: updating documentation [skip actions] [`d1f6dfa`](https://github.com/nevermined-io/sdk-js/commit/d1f6dfa161444337fb8f4e6e633d0de7b5b6c890)
- docs: updating documentation [skip actions] [`f02e652`](https://github.com/nevermined-io/sdk-js/commit/f02e652883df2e6e6a3c21e2c22650c8fc09d69d)
- Automated CHANGELOG.md update [`3d02657`](https://github.com/nevermined-io/sdk-js/commit/3d026574f8051d1cb4151e3441edbece52bfb907)

#### [v3.0.15](https://github.com/nevermined-io/sdk-js/compare/v3.0.15-rc3...v3.0.15)

> 26 June 2024
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nevermined-io/sdk",
"version": "3.0.15",
"version": "3.0.16",
"description": "Javascript SDK for connecting with Nevermined Data Platform ",
"main": "./dist/node/sdk.js",
"typings": "./dist/node/sdk.d.ts",
Expand Down Expand Up @@ -55,7 +55,7 @@
"@turnkey/viem": "0.4.16",
"@zerodev/ecdsa-validator": "5.2.3",
"@zerodev/sdk": "5.2.11",
"@zerodev/session-key": "^5.3.0",
"@zerodev/session-key": "5.3.0",
"assert": "^2.0.0",
"cross-fetch": "^4.0.0",
"crypto-browserify": "^3.12.0",
Expand All @@ -79,6 +79,7 @@
"url": "^0.11.0",
"uuid": "^9.0.1",
"viem": "2.9.31",
"vm-browserify": "^1.1.2",
"whatwg-url": "^14.0.0"
},
"peerDependencies": {
Expand Down
18 changes: 9 additions & 9 deletions src/common/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,18 @@ export async function decryptMessage(encryptedMessage: string, privateKey: strin
}

export function serializeECIES(ecies: any) {
return btoa(
JSON.stringify({
iv: Buffer.from(ecies.iv).toString('base64'),
ephemPublicKey: Buffer.from(ecies.ephemPublicKey).toString('base64'),
ciphertext: Buffer.from(ecies.ciphertext).toString('base64'),
mac: Buffer.from(ecies.mac).toString('base64'),
}),
)
const serialized = JSON.stringify({
iv: Buffer.from(ecies.iv).toString('base64'),
ephemPublicKey: Buffer.from(ecies.ephemPublicKey).toString('base64'),
ciphertext: Buffer.from(ecies.ciphertext).toString('base64'),
mac: Buffer.from(ecies.mac).toString('base64'),
})
return Buffer.from(serialized).toString('binary')
}

export function deserializeECIES(serialized: any) {
const _obj = JSON.parse(atob(serialized))
const decoded = Buffer.from(serialized, 'binary').toString()
const _obj = JSON.parse(decoded)
return {
iv: Buffer.from(_obj.iv, 'base64'),
ephemPublicKey: Buffer.from(_obj.ephemPublicKey, 'base64'),
Expand Down
7 changes: 6 additions & 1 deletion src/keeper/ContractHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,12 @@ export class ContractHandler extends Instantiable {
if (networkName && networkName.length > 0) where = `.${networkName}`

if (artifactsFolder.startsWith('http')) {
const path = `${artifactsFolder}/${networkId}/public/${contractsVersion}/${contractName}${where}.json`
let path
if (artifactsFolder === 'https://artifacts.nevermined.network') {
path = `${artifactsFolder}/${networkId}/public/${contractsVersion}/${contractName}${where}.json`
} else {
path = `${artifactsFolder}/${contractName}${where}.json`
}
const jsonFile = await fetch(path, {
method: 'GET',
headers: { 'Content-type': 'application/json' },
Expand Down
2 changes: 2 additions & 0 deletions src/keeper/contracts/Nft1155Contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class Nft1155Contract extends NFTContractsBase {

if (address) {
const networkName = await nft.nevermined.keeper.getNetworkName()
const networkId = await nft.nevermined.keeper.getNetworkId()

// We don't have a subgraph for NFT1155 so we can only use ContractEvent
const eventEmitter = new EventHandler()
Expand All @@ -32,6 +33,7 @@ export class Nft1155Contract extends NFTContractsBase {
contractName,
artifactsFolder,
networkName,
networkId,
)

nft.contract = await getContractInstance(address, solidityABI.abi, nft.client)
Expand Down
2 changes: 2 additions & 0 deletions src/keeper/contracts/Nft721Contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class Nft721Contract extends NFTContractsBase {
const nft: Nft721Contract = new Nft721Contract(contractName)
nft.setInstanceConfig(config)
const networkName = await nft.nevermined.keeper.getNetworkName()
const networkId = await nft.nevermined.keeper.getNetworkId()

// We don't have a subgraph for NFT721 so we can only use ContractEvent
const eventEmitter = new EventHandler()
Expand All @@ -27,6 +28,7 @@ export class Nft721Contract extends NFTContractsBase {
contractName,
artifactsFolder,
networkName,
networkId,
)

nft.contract = await getContractInstance(address, solidityABI.abi, nft.nevermined.client)
Expand Down
1 change: 1 addition & 0 deletions webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = {
assert: require.resolve('assert/'),
path: require.resolve('path-browserify'),
stream: require.resolve('stream-browserify'),
vm: require.resolve("vm-browserify"),
zlib: false,
fs: false,
},
Expand Down
7 changes: 6 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2594,7 +2594,7 @@
dependencies:
semver "^7.6.0"

"@zerodev/session-key@^5.3.0":
"@zerodev/[email protected]":
version "5.3.0"
resolved "https://registry.yarnpkg.com/@zerodev/session-key/-/session-key-5.3.0.tgz#d347134a359d06ec03f6bb8378345d5d2d3f4c22"
integrity sha512-HZAFuhUiiG2bx8fqBW1LujH7Rn8zdbraipOoFXh55tDTyA3GX6M4RgiqzZPRoHMYfCYImE6ETBj0a97PjsBRHQ==
Expand Down Expand Up @@ -11260,6 +11260,11 @@ [email protected]:
isows "1.0.3"
ws "8.13.0"

vm-browserify@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/vm-browserify/-/vm-browserify-1.1.2.tgz#78641c488b8e6ca91a75f511e7a3b32a86e5dda0"
integrity sha512-2ham8XPWTONajOR0ohOKOHXkm3+gaBmGut3SRuu75xLd/RRaY6vqgh8NBYYk7+RW3u5AtzPQZG8F10LHkl0lAQ==

vscode-oniguruma@^1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/vscode-oniguruma/-/vscode-oniguruma-1.7.0.tgz#439bfad8fe71abd7798338d1cd3dc53a8beea94b"
Expand Down

0 comments on commit 195b66b

Please sign in to comment.