This repository was archived by the owner on Mar 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
feat: migrate-lookups-file-flow-to-ts #82
Open
Akirtovskis
wants to merge
27
commits into
stacks-archive:master
Choose a base branch
from
Akirtovskis:feature/migrate-flow-to-ts
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
254dc5f
feat: migrate-lookups-file-flow-to-ts
Akirtovskis 14923cf
fix: upd package json lock
Akirtovskis 4af2459
fix: test removing the lock file
Akirtovskis ad20a4a
Revert "fix: test removing the lock file"
Akirtovskis 5ab3fe1
Merge branch 'master' into feature/migrate-flow-to-ts
Akirtovskis 1b98458
fix: add type of owner
Akirtovskis e61d6be
Merge branch 'feature/migrate-flow-to-ts' of https://github.com/Akirt…
Akirtovskis 4d11dcb
fix: remove old file + fix import cheerio
Akirtovskis 540550d
fix: upd with the new file
Akirtovskis c135d11
fix: add ts config to babel
Akirtovskis 3501ae9
fix: add babel ts
Akirtovskis 4525102
fix: try upd flow config
Akirtovskis 63445ef
fix: add ts config to babel
Akirtovskis 41772e0
fix: upd import
Akirtovskis 933dac3
fix: enable tests
Akirtovskis 1a9b238
fix: feedback updates
Akirtovskis 3a9fdef
fix: upd tsconfig
Akirtovskis 901db61
fix: minor
Akirtovskis 2a57403
fix: minor
Akirtovskis e2b2d47
fix: upd package json
Akirtovskis 63e7be3
fix: removing cheerio types
Akirtovskis be95a7e
fix: feedback fixes
Akirtovskis b5b9909
fix: remove cheerio
Akirtovskis 6539d2e
fix: add cheerio
Akirtovskis 8cea79a
fix: add cheerio
Akirtovskis d405ba7
fix: remove cheerio
Akirtovskis 784dc8a
fix: remove unused import
Akirtovskis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,29 @@ | ||
{ | ||
"presets": [ | ||
[ "@babel/preset-env", | ||
{ "targets": { "node": 12 } } ], | ||
{ | ||
"targets": { | ||
"node": 12 | ||
} | ||
}], | ||
"@babel/preset-flow"], | ||
"overrides": [ | ||
{ | ||
"test": ["./src/**/*.ts"], | ||
"presets": [ | ||
"@babel/preset-typescript", | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"targets": { | ||
"node": 12, | ||
} | ||
} | ||
], | ||
] | ||
} | ||
], | ||
"plugins": ["istanbul"] | ||
} | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,5 @@ | |
.*/node_modules/.staging/* | ||
.*/node_modules/npm/* | ||
|
||
[include] | ||
|
||
[libs] | ||
|
||
[options] | ||
|
||
[lints] | ||
module.file_ext=.ts |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { | ||
config as bskConfig, | ||
validateProofs, | ||
resolveZoneFileToProfile, | ||
} from "blockstack"; | ||
import { validateStacksAddress } from "@stacks/transactions"; | ||
import fetch from "node-fetch"; | ||
import logger from "winston"; | ||
|
||
export async function isSubdomainRegistered(fullyQualifiedAddress: string) { | ||
try { | ||
const nameInfoUrl = | ||
bskConfig.network.blockstackAPIUrl + "/v1/names/" + fullyQualifiedAddress; | ||
const nameInfoRequest = await fetch(nameInfoUrl, {}); | ||
const { status } = nameInfoRequest; | ||
const nameInfo = await nameInfoRequest.json(); | ||
if (status == 200) { | ||
return nameInfo.status === "registered_subdomain"; | ||
} else { | ||
return false; | ||
} | ||
} catch (err) { | ||
if (err.message === "Name not found") { | ||
return false; | ||
} else if (err.message === "Bad response status: 500") { | ||
return false; // currently, the blockstack api returns 500 on subdomain lookup errors. | ||
} else { | ||
throw err; | ||
} | ||
} | ||
} | ||
|
||
export function validlySignedUpdate() { | ||
throw new Error("Not implemented"); | ||
} | ||
|
||
export async function checkProofs(owner: string, zonefile: any) { | ||
const profile = await resolveZoneFileToProfile(zonefile, owner); | ||
// ts-ignore used below to not modify the code and not add the cheerio module that is in the validate proofs fn type | ||
// @ts-ignore | ||
const proofs = await validateProofs(profile, owner); | ||
return proofs.filter((x) => x.valid); | ||
} | ||
|
||
export async function isRegistrationValid( | ||
subdomainName: string, | ||
domainName: string, | ||
owner: string, | ||
sequenceNumber: number, | ||
checkCore: boolean | ||
) { | ||
// currently, only support *new* subdomains | ||
if (sequenceNumber !== 0) { | ||
logger.debug(`seqn: ${sequenceNumber} failed validation`); | ||
return false; | ||
} | ||
|
||
// owner should be a stacks address | ||
if (!validateStacksAddress(owner)) { | ||
logger.debug(`owner: ${owner} failed validation`); | ||
return false; | ||
} | ||
|
||
// subdomain name should be a legal name | ||
const subdomainRegex = /^[a-z0-9\-_+]{1,37}$/; | ||
if (!subdomainRegex.test(subdomainName)) { | ||
logger.debug(`subdomainName: ${subdomainName} failed validation`); | ||
return false; | ||
} | ||
if (!checkCore) { | ||
return true; | ||
} | ||
|
||
// shouldn't already exist | ||
try { | ||
const isRegistered = await isSubdomainRegistered( | ||
`${subdomainName}.${domainName}` | ||
); | ||
if (isRegistered) { | ||
logger.warn(`${subdomainName}.${domainName} already exists`); | ||
} | ||
return !isRegistered; | ||
} catch (e) { | ||
logger.error(e); | ||
return false; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module "winston"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2020", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"declaration": false, | ||
"strict": true, | ||
"sourceMap": true, | ||
"esModuleInterop": false, | ||
"allowSyntheticDefaultImports": false, | ||
"useUnknownInCatchVariables": false, | ||
"resolveJsonModule": true, | ||
"skipLibCheck": true, | ||
"outDir": "lib", | ||
"noEmit": true, | ||
"baseUrl": ".", | ||
"allowJs": true | ||
}, | ||
"include": [ | ||
"src/lookups.ts", | ||
"src/types", | ||
], | ||
"exclude": [ | ||
"lib", | ||
"node_modules" | ||
] | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.