Add Skynet support (#2853, #2866).

This commit is contained in:
Richard Moore 2022-05-20 19:03:42 -04:00
parent d06aa26d74
commit 13dd42c6c3
3 changed files with 28 additions and 0 deletions

@ -17,6 +17,7 @@
"@ethersproject/abstract-provider": "^5.6.0", "@ethersproject/abstract-provider": "^5.6.0",
"@ethersproject/abstract-signer": "^5.6.0", "@ethersproject/abstract-signer": "^5.6.0",
"@ethersproject/address": "^5.6.0", "@ethersproject/address": "^5.6.0",
"@ethersproject/base64": "^5.6.0",
"@ethersproject/basex": "^5.6.0", "@ethersproject/basex": "^5.6.0",
"@ethersproject/bignumber": "^5.6.0", "@ethersproject/bignumber": "^5.6.0",
"@ethersproject/bytes": "^5.6.0", "@ethersproject/bytes": "^5.6.0",

@ -4,6 +4,7 @@ import {
Block, BlockTag, BlockWithTransactions, EventType, Filter, FilterByBlockHash, ForkEvent, Block, BlockTag, BlockWithTransactions, EventType, Filter, FilterByBlockHash, ForkEvent,
Listener, Log, Provider, TransactionReceipt, TransactionRequest, TransactionResponse Listener, Log, Provider, TransactionReceipt, TransactionRequest, TransactionResponse
} from "@ethersproject/abstract-provider"; } from "@ethersproject/abstract-provider";
import { encode as base64Encode } from "@ethersproject/base64";
import { Base58 } from "@ethersproject/basex"; import { Base58 } from "@ethersproject/basex";
import { BigNumber, BigNumberish } from "@ethersproject/bignumber"; import { BigNumber, BigNumberish } from "@ethersproject/bignumber";
import { arrayify, BytesLike, concat, hexConcat, hexDataLength, hexDataSlice, hexlify, hexValue, hexZeroPad, isHexString } from "@ethersproject/bytes"; import { arrayify, BytesLike, concat, hexConcat, hexDataLength, hexDataSlice, hexlify, hexValue, hexZeroPad, isHexString } from "@ethersproject/bytes";
@ -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, { return logger.throwError(`invalid or unsupported content hash data`, Logger.errors.UNSUPPORTED_OPERATION, {
operation: "getContentHash()", operation: "getContentHash()",
data: hexBytes data: hexBytes

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