Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,76 @@ describe("parseDocumentStoreResults", () => {
];
expect(parseDocumentStoreResults(sampleRecord, true)).toStrictEqual([]);
});

test("it should accept any numeric netId (e.g. Mantle mainnet 5000)", () => {
const addr = "0x2f60375e8144e16Adf1979936301D8341D58C36C";
const sampleRecord = [
{
name: "example.example.com.",
type: 16,
TTL: 110,
data: `"openatts net=ethereum netId=5000 addr=${addr}"`,
dnssec: false,
},
];
expect(parseDocumentStoreResults(sampleRecord, false)).toStrictEqual([
{
type: "openatts",
net: "ethereum",
netId: "5000",
addr,
dnssec: false,
},
]);
});

test("it should accept an arbitrary previously-unknown numeric netId", () => {
const addr = "0x2f60375e8144e16Adf1979936301D8341D58C36C";
const sampleRecord = [
{
name: "example.example.com.",
type: 16,
TTL: 110,
data: `"openatts net=ethereum netId=99999 addr=${addr}"`,
dnssec: false,
},
];
expect(parseDocumentStoreResults(sampleRecord, false)).toStrictEqual([
{
type: "openatts",
net: "ethereum",
netId: "99999",
addr,
dnssec: false,
},
]);
});

test("it should reject a non-numeric netId", () => {
const sampleRecord = [
{
name: "example.example.com.",
type: 16,
TTL: 110,
data: '"openatts net=ethereum netId=abc addr=0x2f60375e8144e16Adf1979936301D8341D58C36C"',
dnssec: false,
},
];
expect(parseDocumentStoreResults(sampleRecord, false)).toStrictEqual([]);
});

test("it should reject an alphanumeric netId", () => {
const sampleRecord = [
{
name: "example.example.com.",
type: 16,
TTL: 110,
data: '"openatts net=ethereum netId=1abc addr=0x2f60375e8144e16Adf1979936301D8341D58C36C"',
dnssec: false,
},
];
expect(parseDocumentStoreResults(sampleRecord, false)).toStrictEqual([]);
});
});

describe("queryDns", () => {
Expand Down
36 changes: 3 additions & 33 deletions src/records/dnsTxt.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Static, Boolean, String, Literal, Record, Union, Partial } from "runtypes";
import { Static, Boolean, String, Literal, Record, Partial } from "runtypes";

export const RecordTypesT = Literal("openatts");

Expand All @@ -8,38 +8,8 @@ export const EthereumAddressT = String.withConstraint((maybeAddress: string) =>
return /0x[a-fA-F0-9]{40}/.test(maybeAddress) || `${maybeAddress} is not a valid ethereum address`;
});

export enum EthereumNetworks {
homestead = "1",
ropsten = "3",
rinkeby = "4",
goerli = "5",
sepolia = "11155111",
polygon = "137",
polygonAmoy = "80002",
local = "1337",
xdc = "50",
xdcapothem = "51",
stabilityTestnet = "20180427",
stability = "101010",
astronTestnet = "21002",
astron = "1338",
}

export const EthereumNetworkIdT = Union(
Literal(EthereumNetworks.homestead),
Literal(EthereumNetworks.ropsten),
Literal(EthereumNetworks.rinkeby),
Literal(EthereumNetworks.goerli),
Literal(EthereumNetworks.sepolia),
Literal(EthereumNetworks.polygon),
Literal(EthereumNetworks.polygonAmoy),
Literal(EthereumNetworks.xdc),
Literal(EthereumNetworks.xdcapothem),
Literal(EthereumNetworks.stabilityTestnet),
Literal(EthereumNetworks.stability),
Literal(EthereumNetworks.local),
Literal(EthereumNetworks.astronTestnet),
Literal(EthereumNetworks.astron)
export const EthereumNetworkIdT = String.withConstraint(
(maybeNetId: string) => /^\d+$/.test(maybeNetId) || `${maybeNetId} is not a valid numeric network id`
);

export const OpenAttestationDNSTextRecordT = Record({
Expand Down
Loading