Skip to content

Commit

Permalink
remove token authentication from gun-eth
Browse files Browse the repository at this point in the history
  • Loading branch information
scobru committed Oct 19, 2024
1 parent 9bdf470 commit a6b29da
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 132 deletions.
14 changes: 1 addition & 13 deletions packages/gun-eth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,7 @@ Learn more about plugin implementation [here](https://github.com/amark/gun/wiki/
```javascript
gun.shine("optimismSepolia", nodeId, data, callback);
```

- `setToken(token)`: Sets a custom token for Gun operations.

```javascript
gun.setToken("yourCustomToken");
```

- `getToken()`: Retrieves the current custom token.

```javascript
const currentToken = gun.getToken();
```


## SHINE

SHINE (Secure Hash Integrity Network Ethereum) provides a mechanism for verifying data integrity using Ethereum and Gun.js.
Expand Down
2 changes: 1 addition & 1 deletion packages/gun-eth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gun-eth",
"version": "1.3.1",
"version": "1.3.2",
"description": "A GunDB plugin for Ethereum, and Web3",
"main": "./src/index.js",
"scripts": {
Expand Down
33 changes: 0 additions & 33 deletions packages/gun-eth/src/gun-eth.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@

let SHINE_OPTIMISM_SEPOLIA = "0x43D838b683F772F08f321E5FA265ad3e333BE9C2";
let SHINE_CONTRACT_ADDRESS;
let customToken = "";
let rpcUrl = "";
let privateKey = "";

Expand Down Expand Up @@ -220,38 +219,6 @@
return this;
};

/**
* Sets a custom token for Gun operations.
* @param {string} token - The token to be set.
* @returns {Gun} The Gun instance for chaining.
*/
Gun.chain.setToken = function (token) {
if (typeof token === "string" && token.length > 0) {
customToken = token;
console.log("Token set successfully:", token);
} else {
console.error("Invalid token. Must be a non-empty string.");
}
return this;
};

/**
* Retrieves the current custom token.
* @returns {string} The current custom token.
*/
Gun.chain.getToken = function () {
return customToken;
};

// Add custom token to all 'put' operations
Gun.on("put", function (msg) {
const to = this.to;
msg.headers = {
token: customToken,
};
to.next(msg);
});

/**
* Verifies an Ethereum signature.
* @param {string} message - The original message that was signed.
Expand Down
33 changes: 0 additions & 33 deletions packages/gun-eth/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const SHINE_ABI = SHINE.abi;
const SHINE_OPTIMISM_SEPOLIA = SHINE.address;

let SHINE_CONTRACT_ADDRESS;
let customToken = "";

let rpcUrl = "";
let privateKey = "";
Expand Down Expand Up @@ -49,38 +48,6 @@ Gun.chain.setStandaloneConfig = function (newRpcUrl, newPrivateKey) {
return this;
};

/**
* Sets a custom token for Gun operations.
* @param {string} token - The token to be set.
* @returns {Gun} The Gun instance for chaining.
*/
Gun.chain.setToken = function (token) {
if (typeof token === "string" && token.length > 0) {
customToken = token;
console.log("Token set successfully:", token);
} else {
console.error("Invalid token. Must be a non-empty string.");
}
return this;
};

/**
* Retrieves the current custom token.
* @returns {string} The current custom token.
*/
Gun.chain.getToken = function () {
return customToken;
};

// Add custom token to all 'put' operations
Gun.on("put", function (msg) {
const to = this.to;
msg.headers = {
token: customToken,
};
to.next(msg);
});

/**
* Verifies an Ethereum signature.
* @param {string} message - The original message that was signed.
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"express-rate-limit": "^7.4.0",
"gun": "^0.2020.1240",
"gun-avatar": "^1.9.4",
"gun-eth": "^1.2.14",
"gun-eth": "^1.3.2",
"ip": "^2.0.1",
"js-sha256": "^0.11.0",
"js-sha3": "^0.9.3",
Expand Down
3 changes: 2 additions & 1 deletion packages/svelte/src/lib/components/gun/graph/Graph.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import { fade } from 'svelte/transition';
import { browser } from '$app/environment';
let colorDeep: import("color-hash").ColorHash;
let colorDeep;
if(browser) {
colorDeep = useColor("deep");
}
Expand Down
78 changes: 33 additions & 45 deletions packages/svelte/src/lib/gun/colors.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,45 @@
/**
* Deterministic colors derived from pub keys, hashes or any other string data
* @module Color
* @group UI
* */

import { browser } from '$app/environment';

let ColorHash: any;

if (browser) {
ColorHash = (await import('color-hash')).default;
function loadColorHash() {
if (browser) {
import('color-hash').then(module => {
ColorHash = module.default;
initializeColors();
});
}
}

/**
* @typedef {'light' | 'regular' | 'deep' | 'dark'} Palette
*/

const color: Record<string, any> = {};

if (browser) {
color.light = new ColorHash({
saturation: [0.05, 0.08, 0.22],
lightness: [0.85, 0.87, 0.9],
});
color.pale = new ColorHash({
saturation: [0.05, 0.42, 0.52],
lightness: [0.75, 0.77, 0.9],
});
color.regular = new ColorHash({
saturation: [0.1, 0.5, 0.7],
lightness: [0.3, 0.5, 0.7],
});
color.deep = new ColorHash({
saturation: [0.5, 0.6, 0.7],
lightness: [0.2, 0.35, 0.4],
});
color.dark = new ColorHash({
saturation: [0.02, 0.5, 0.6],
lightness: [0.18, 0.2, 0.5],
});
function initializeColors() {
if (ColorHash) {
color.light = new ColorHash({
saturation: [0.05, 0.08, 0.22],
lightness: [0.85, 0.87, 0.9],
});
color.pale = new ColorHash({
saturation: [0.05, 0.42, 0.52],
lightness: [0.75, 0.77, 0.9],
});
color.regular = new ColorHash({
saturation: [0.1, 0.5, 0.7],
lightness: [0.3, 0.5, 0.7],
});
color.deep = new ColorHash({
saturation: [0.5, 0.6, 0.7],
lightness: [0.2, 0.35, 0.4],
});
color.dark = new ColorHash({
saturation: [0.02, 0.5, 0.6],
lightness: [0.18, 0.2, 0.5],
});
}
}

/**
* Get a color generator of a certain palette
* @param {Palette} [palette='deep']
* @returns {ColorHash} Color-Hash instance
* @see https://github.com/zenozeng/color-hash
* @example
* import {useColor} from '@gun-vue/composables'
* const colorDeep = useColor('deep')
* const color = colorDeep.hex('any text data')
* // color == '#e052ae'
*/
loadColorHash();

export function useColor(palette = "deep") {
if (!browser) {
return {
Expand All @@ -62,5 +50,5 @@ export function useColor(palette = "deep") {
if (typeof palette == "object") {
return new ColorHash(palette);
}
return color[palette as keyof typeof color];
return color[palette as keyof typeof color] || color.deep;
}
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2388,7 +2388,7 @@ __metadata:
express-rate-limit: ^7.4.0
gun: ^0.2020.1240
gun-avatar: ^1.9.4
gun-eth: ^1.2.14
gun-eth: ^1.3.2
ip: ^2.0.1
js-sha256: ^0.11.0
js-sha3: ^0.9.3
Expand Down Expand Up @@ -9392,13 +9392,13 @@ __metadata:
languageName: node
linkType: hard

"gun-eth@npm:^1.2.14":
version: 1.2.14
resolution: "gun-eth@npm:1.2.14"
"gun-eth@npm:^1.3.2":
version: 1.3.2
resolution: "gun-eth@npm:1.3.2"
dependencies:
ethers: ^6.0.0
gun: ^0.2020.1239
checksum: 8c7eaa7526792f28f99fe7549e8d68a53ba5bc819ec88417a89c369725971c19f65e2d89b80edeb7253c78225be9e61e6b7fdf860eef2e83f9a0342c6bd36a2e
checksum: 944dab33f8a33dfb4eda90204fea078693c1ef3dfa92eadca56e4ad57c33917c6443cf4445fa35126619edd2ea0e086bfa07554db311e9cc0ef100cd2bd707e6
languageName: node
linkType: hard

Expand Down

0 comments on commit a6b29da

Please sign in to comment.