Skip to content

Commit

Permalink
Add Skynet support (#2853, #2866).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed May 20, 2022
1 parent d06aa26 commit 13dd42c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/providers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@ethersproject/abstract-provider": "^5.6.0",
"@ethersproject/abstract-signer": "^5.6.0",
"@ethersproject/address": "^5.6.0",
"@ethersproject/base64": "^5.6.0",
"@ethersproject/basex": "^5.6.0",
"@ethersproject/bignumber": "^5.6.0",
"@ethersproject/bytes": "^5.6.0",
Expand Down
11 changes: 11 additions & 0 deletions packages/providers/src.ts/base-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Block, BlockTag, BlockWithTransactions, EventType, Filter, FilterByBlockHash, ForkEvent,
Listener, Log, Provider, TransactionReceipt, TransactionRequest, TransactionResponse
} from "@ethersproject/abstract-provider";
import { encode as base64Encode } from "@ethersproject/base64";
import { Base58 } from "@ethersproject/basex";
import { BigNumber, BigNumberish } from "@ethersproject/bignumber";
import { arrayify, BytesLike, concat, hexConcat, hexDataLength, hexDataSlice, hexlify, hexValue, hexZeroPad, isHexString } from "@ethersproject/bytes";
Expand Down Expand Up @@ -657,6 +658,16 @@ export class Resolver implements EnsResolver {
}
}

const skynet = hexBytes.match(/^0x90b2c605([0-9a-f]*)$/);
if (skynet) {
if (skynet[1].length === (34 * 2)) {
// URL Safe base64; https://datatracker.ietf.org/doc/html/rfc4648#section-5
const urlSafe: Record<string, string> = { "=": "", "+": "-", "/": "_" };
const hash = base64Encode("0x" + skynet[1]).replace(/[=+\/]/g, (a) => (urlSafe[a]));
return "sia:/\/" + hash;
}
}

return logger.throwError(`invalid or unsupported content hash data`, Logger.errors.UNSUPPORTED_OPERATION, {
operation: "getContentHash()",
data: hexBytes
Expand Down
16 changes: 16 additions & 0 deletions packages/tests/src.ts/test-providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,22 @@ describe("Resolve ENS avatar", function() {
});
});

describe("Resolve ENS content hash", function() {
[
{ title: "skynet", name: "skynet-ens.eth", value: "sia:/\/AQCRuTdTPzCyyU6I82eV7VDFVLPW82LJS9mH-chmjDlKUQ" },
{ title: "ipns", name: "stderr.eth", value: "ipns://12D3KooWB8Z5zTNUJM1U98SjAwuCSaEwx65cHkFcMu1SJSvGmMJT" },
{ title: "ipfs", name: "ricmoo.eth", value: "ipfs://QmdTPkMMBWQvL8t7yXogo7jq5pAcWg8J7RkLrDsWZHT82y" },
].forEach((test) => {
it(`Resolves avatar for ${ test.title }`, async function() {
this.timeout(60000);
const provider = ethers.getDefaultProvider("homestead", getApiKeys("homestead"));
const resolver = await provider.getResolver(test.name);
const contentHash = await resolver.getContentHash();
assert.equal(contentHash, test.value, "content hash");
});
});
});

describe("Test EIP-2544 ENS wildcards", function() {
const provider = <ethers.providers.BaseProvider>(providerFunctions[0].create("ropsten"));

Expand Down

0 comments on commit 13dd42c

Please sign in to comment.