Update for multihash anchors

This commit is contained in:
Alexis Sellier
2021-06-10 12:33:17 +02:00
parent 76e7b8dc4d
commit f35c989a13
6 changed files with 68 additions and 18 deletions
+51
View File
@@ -9,6 +9,7 @@
"ethereum-blockies": "^0.1.1",
"ethers": "^5.0.31",
"multibase": "^4.0.4",
"multihashes": "^4.0.2",
"svelte": "^3.32.3",
"svelte-routing": "^1.6.0"
},
@@ -2317,6 +2318,20 @@
"npm": ">=6.0.0"
}
},
"node_modules/multihashes": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/multihashes/-/multihashes-4.0.2.tgz",
"integrity": "sha512-xpx++1iZr4ZQHjN1mcrXS6904R36LWLxX/CBifczjtmrtCXEX623DMWOF1eiNSg+pFpiZDFVBgou/4v6ayCHSQ==",
"dependencies": {
"multibase": "^4.0.1",
"uint8arrays": "^2.1.3",
"varint": "^5.0.2"
},
"engines": {
"node": ">=12.0.0",
"npm": ">=6.0.0"
}
},
"node_modules/no-case": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/no-case/-/no-case-3.0.4.tgz",
@@ -3364,6 +3379,14 @@
"node": ">=4.2.0"
}
},
"node_modules/uint8arrays": {
"version": "2.1.5",
"resolved": "https://registry.npmjs.org/uint8arrays/-/uint8arrays-2.1.5.tgz",
"integrity": "sha512-CSR7AO+4AHUeSOnZ/NBNCElDeWfRh9bXtOck27083kc7SznmmHIhNEkEOCQOn0wvrIMjS3IH0TNLR16vuc46mA==",
"dependencies": {
"multibase": "^4.0.1"
}
},
"node_modules/unique-filename": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/unique-filename/-/unique-filename-1.1.1.tgz",
@@ -3427,6 +3450,11 @@
"builtins": "^1.0.3"
}
},
"node_modules/varint": {
"version": "5.0.2",
"resolved": "https://registry.npmjs.org/varint/-/varint-5.0.2.tgz",
"integrity": "sha512-lKxKYG6H03yCZUpAGOPOsMcGxd1RHCu1iKvEHYDPmTyq2HueGhD73ssNBqqQWfvYs04G9iUFRvmAVLW20Jw6ow=="
},
"node_modules/verror": {
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz",
@@ -5175,6 +5203,16 @@
"@multiformats/base-x": "^4.0.1"
}
},
"multihashes": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/multihashes/-/multihashes-4.0.2.tgz",
"integrity": "sha512-xpx++1iZr4ZQHjN1mcrXS6904R36LWLxX/CBifczjtmrtCXEX623DMWOF1eiNSg+pFpiZDFVBgou/4v6ayCHSQ==",
"requires": {
"multibase": "^4.0.1",
"uint8arrays": "^2.1.3",
"varint": "^5.0.2"
}
},
"no-case": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/no-case/-/no-case-3.0.4.tgz",
@@ -5933,6 +5971,14 @@
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.4.tgz",
"integrity": "sha512-V+evlYHZnQkaz8TRBuxTA92yZBPotr5H+WhQ7bD3hZUndx5tGOa1fuCgeSjxAzM1RiN5IzvadIXTVefuuwZCRg=="
},
"uint8arrays": {
"version": "2.1.5",
"resolved": "https://registry.npmjs.org/uint8arrays/-/uint8arrays-2.1.5.tgz",
"integrity": "sha512-CSR7AO+4AHUeSOnZ/NBNCElDeWfRh9bXtOck27083kc7SznmmHIhNEkEOCQOn0wvrIMjS3IH0TNLR16vuc46mA==",
"requires": {
"multibase": "^4.0.1"
}
},
"unique-filename": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/unique-filename/-/unique-filename-1.1.1.tgz",
@@ -5990,6 +6036,11 @@
"builtins": "^1.0.3"
}
},
"varint": {
"version": "5.0.2",
"resolved": "https://registry.npmjs.org/varint/-/varint-5.0.2.tgz",
"integrity": "sha512-lKxKYG6H03yCZUpAGOPOsMcGxd1RHCu1iKvEHYDPmTyq2HueGhD73ssNBqqQWfvYs04G9iUFRvmAVLW20Jw6ow=="
},
"verror": {
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz",
+1
View File
@@ -18,6 +18,7 @@
"ethereum-blockies": "^0.1.1",
"ethers": "^5.0.31",
"multibase": "^4.0.4",
"multihashes": "^4.0.2",
"svelte": "^3.32.3",
"svelte-routing": "^1.6.0"
}
+10 -8
View File
@@ -11,8 +11,7 @@ const GetProjects = `
projects(where: { org: $org }) {
id
anchor {
stateHash
stateHashFormat
stateMultihash
timestamp
}
}
@@ -81,12 +80,15 @@ export class Org {
for (const p of result.projects) {
try {
p.id = utils.formatRadicleId(ethers.utils.arrayify(p.id));
p.anchor.stateHash = utils.formatProjectHash(
ethers.utils.arrayify(p.anchor.stateHash),
p.anchor.stateHashFormat
);
projects.push(p);
const proj: Project = {
id: utils.formatRadicleId(ethers.utils.arrayify(p.id)),
anchor: {
stateHash: utils.formatProjectHash(
ethers.utils.arrayify(p.anchor.stateMultihash),
)
},
};
projects.push(proj);
} catch (e) {
console.error(e);
}
+2 -2
View File
@@ -25,7 +25,7 @@
"address": "0x59b5eee36f5fa52400A136Fd4630Ee2bF126a4C0"
},
"orgFactory": {
"address": "0xe1814B14430CF14f0950A29FF26217115B815676"
"address": "0xc074cDd9541960B0AA72D90c8bC642F6ae9C4032"
},
"orgs": {
"subgraph": "https://api.thegraph.com/subgraphs/name/radicle-dev/radicle-orgs-ropsten",
@@ -46,7 +46,7 @@
"address": "0x5592ec0cfb4dbc12d3ab100b257153436a1f0fea"
},
"orgFactory": {
"address": "0xe30aA5594FFB52B6bF5bbB21eB7e71Ac525bB028"
"address": "0x57962Eb188146A4942c44545a97478d64dc9e4A5"
},
"orgs": {
"subgraph": "https://api.thegraph.com/subgraphs/name/radicle-dev/radicle-orgs-rinkeby",
-1
View File
@@ -4,7 +4,6 @@ export interface Project {
id: string;
anchor: {
stateHash: string;
stateHashFormat: string;
};
}
+4 -7
View File
@@ -1,6 +1,7 @@
import { ethers } from "ethers";
import type { BigNumber } from "ethers";
import multibase from 'multibase';
import multihashes from 'multihashes';
import type { Config } from '@app/config';
import { assert } from '@app/error';
@@ -131,13 +132,9 @@ export function formatRadicleId(hash: Uint8Array): string {
}
// Create a project hash from a hash and format.
export function formatProjectHash(hash: Uint8Array, format: number): string {
assert(format === 0x0, "Only SHA1 commit hashes are supported");
// Remove any zero-padding from the byte array. SHA1 is 20 bytes long.
const sha1Bytes = 20;
const suffix = hash.slice(hash.length - sha1Bytes);
return ethers.utils.hexlify(suffix).replace(/^0x/, '');
export function formatProjectHash(multihash: Uint8Array): string {
const decoded = multihashes.decode(multihash);
return ethers.utils.hexlify(decoded.digest).replace(/^0x/, '');
}
// Identify an address by checking whether it's a contract or an externally-owned address.