Skip to content

Commit

Permalink
Add Skynet support
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjan committed Apr 5, 2022
1 parent ef1b28e commit 479acec
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"bn.js": "^4.11.9",
"elliptic": "6.5.4",
"hash.js": "1.1.7",
"js-base64": "^3.7.2",
"js-sha3": "0.8.0",
"scrypt-js": "3.0.1",
"solc": "0.7.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/providers/lib/base-provider.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion packages/providers/lib/base-provider.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/providers/lib/base-provider.js.map

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions packages/providers/src.ts/base-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Listener, Log, Provider, TransactionReceipt, TransactionRequest, TransactionResponse
} from "@ethersproject/abstract-provider";
import { Base58 } from "@ethersproject/basex";
import { encode as base64Encode } from "@ethersproject/base64";
import { BigNumber, BigNumberish } from "@ethersproject/bignumber";
import { arrayify, BytesLike, concat, hexConcat, hexDataLength, hexDataSlice, hexlify, hexValue, hexZeroPad, isHexString } from "@ethersproject/bytes";
import { HashZero } from "@ethersproject/constants";
Expand Down Expand Up @@ -657,6 +658,24 @@ export class Resolver implements EnsResolver {
}
}

// Skynet (34 bytes that are base64-encoded)
const skynet = hexBytes.match(/^0x90b2c605([0-9a-f]*)$/)
if (skynet) {
if (skynet[1].length === (34 * 2)) {
const buf = Buffer.from(skynet[1], 'hex')
let skylink = base64Encode(buf)

// Skylinks have to be encoded using a URI safe alphabet
// see https://datatracker.ietf.org/doc/html/rfc4648#section-5
skylink = skylink
.replace(/=/g, '')
.replace(/[+\/]/g, (m0) => { return m0 == '+' ? '-' : '_'; }
);

return "sia:/\/" + skylink
}
}

return logger.throwError(`invalid or unsupported content hash data`, Logger.errors.UNSUPPORTED_OPERATION, {
operation: "getContentHash()",
data: hexBytes
Expand Down

0 comments on commit 479acec

Please sign in to comment.