From d507e4e82fb28e9da5c6a106749bd1f1782fcbbf Mon Sep 17 00:00:00 2001 From: DR497 <47689875+dr497@users.noreply.github.com> Date: Thu, 17 Feb 2022 11:13:11 +0800 Subject: [PATCH] add subdomain resolution --- package.json | 2 +- src/components/SendDialog.js | 36 ++++++++++--- src/utils/name-service/index.ts | 22 ++++---- yarn.lock | 95 +++++++++++++++++++++------------ 4 files changed, 103 insertions(+), 52 deletions(-) diff --git a/package.json b/package.json index 8b818c6..7c89399 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "private": true, "dependencies": { - "@bonfida/spl-name-service": "^0.1.12", + "@bonfida/spl-name-service": "^0.1.24", "@ledgerhq/hw-transport-webhid": "^5.51.1", "@material-ui/core": "^4.11.4", "@material-ui/icons": "^4.11.2", diff --git a/src/components/SendDialog.js b/src/components/SendDialog.js index 220d020..0c1637d 100644 --- a/src/components/SendDialog.js +++ b/src/components/SendDialog.js @@ -36,7 +36,11 @@ import { import { parseTokenAccountData } from '../utils/tokens/data'; import { Switch, Tooltip } from '@material-ui/core'; import { EthFeeEstimate } from './EthFeeEstimate'; -import { resolveDomainName, resolveTwitterHandle } from '../utils/name-service'; +import { + resolveDomainName, + resolveTwitterHandle, + getNameKey, +} from '../utils/name-service'; const WUSDC_MINT = new PublicKey( 'BXXkv6z8ykpG1yuvUDPgh732wzVHB69RnB9YgSYh3itW', @@ -65,7 +69,10 @@ export default function SendDialog({ open, onClose, publicKey, balanceInfo }) { ); // SwapInfos to ignore. - if (swapCoinInfo && swapCoinInfo.erc20Contract === '0x2b2e04bf86978b45bb2edf54aca876973bdd43c0') { + if ( + swapCoinInfo && + swapCoinInfo.erc20Contract === '0x2b2e04bf86978b45bb2edf54aca876973bdd43c0' + ) { swapCoinInfo = null; } @@ -247,12 +254,27 @@ function SendSplDialog({ onClose, publicKey, balanceInfo, onSubmitRef }) { setDomainOwner(twitterOwner); } if (destinationAddress.endsWith('.sol')) { - const domainOwner = await resolveDomainName( - wallet.connection, - destinationAddress.slice(0, -4), - ); + const name = destinationAddress.slice(0, -4); + const hasSub = name.split('.').length === 2; + + let domainOwner; + + if (hasSub) { + const sub = name.split('.')[0]; + const parentKey = await getNameKey(name.split('.')[1]); + domainOwner = await resolveDomainName( + wallet.connection, + sub, + parentKey, + ); + } else { + domainOwner = await resolveDomainName(wallet.connection, name); + } + if (!domainOwner) { - setAddressHelperText(`This domain name is not registered`); + setAddressHelperText( + `This ${hasSub ? 'subdomain' : 'domain'} name is not registered`, + ); setPassValidation(undefined); setShouldShowOverride(undefined); return; diff --git a/src/utils/name-service/index.ts b/src/utils/name-service/index.ts index 92b48d4..d1c9e75 100644 --- a/src/utils/name-service/index.ts +++ b/src/utils/name-service/index.ts @@ -6,6 +6,7 @@ import { NameRegistryState, getFilteredProgramAccounts, NAME_PROGRAM_ID, + getDNSRecordAddress, } from '@bonfida/spl-name-service'; import { useConnection } from '../connection'; import { useWallet } from '../wallet'; @@ -35,21 +36,22 @@ export const resolveTwitterHandle = async ( } }; +export const getNameKey = async (name: string, parent = SOL_TLD_AUTHORITY) => { + const hashedDomainName = await getHashedName(name); + const key = await getNameAccountKey(hashedDomainName, undefined, parent); + return key; +}; + export const resolveDomainName = async ( connection: Connection, domainName: string, + parent?: PublicKey, ): Promise => { - let hashedDomainName = await getHashedName(domainName); - let inputDomainKey = await getNameAccountKey( - hashedDomainName, - undefined, - SOL_TLD_AUTHORITY, - ); + const key = parent + ? await getDNSRecordAddress(parent, domainName) + : await getNameKey(domainName); try { - const registry = await NameRegistryState.retrieve( - connection, - inputDomainKey, - ); + const registry = await NameRegistryState.retrieve(connection, key); return registry.owner.toBase58(); } catch (err) { console.warn(err); diff --git a/yarn.lock b/yarn.lock index bd47827..b29ff9c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1339,21 +1339,21 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== -"@bonfida/spl-name-service@^0.1.12": - version "0.1.12" - resolved "https://registry.yarnpkg.com/@bonfida/spl-name-service/-/spl-name-service-0.1.12.tgz#ab186fe0c907efe66cb6818e2f429f9f4b3ab0d2" - integrity sha512-zVZiOjhZK+VZAs4aqOmxj6vplbGGwcin/gJ3Xm/gn+wV1GzgeqDkYrrDJclEpQ7WcmA4WV/Pad6tWfPtGt12/g== +"@bonfida/spl-name-service@^0.1.24": + version "0.1.24" + resolved "https://registry.yarnpkg.com/@bonfida/spl-name-service/-/spl-name-service-0.1.24.tgz#2403bbff2ff6ea6fd07f91efc74b59926e58f3ed" + integrity sha512-9+iMNPIiTC8BbdzMgqYo7UjGgi7pONv86lOMkO0yxu12/sYw2ogrhap/r+d+BWRahwL4X7jWwDpXo8im2WcyjQ== dependencies: - "@solana/spl-token" "0.1.4" - "@solana/web3.js" "^1.11.0" + "@project-serum/sol-wallet-adapter" "^0.1.5" + "@solana/spl-token" "0.1.3" + "@solana/web3.js" "^1.29.2" bip32 "^2.0.6" bn.js "^5.1.3" - borsh "^0.4.0" + borsh "^0.6.0" bs58 "4.0.1" buffer-layout "^1.2.0" core-util-is "^1.0.2" - crypto "^1.0.1" - crypto-ts "^1.0.2" + csv-parser "^3.0.0" fs "^0.0.1-security" tweetnacl "^1.0.3" webpack-dev-server "^3.11.2" @@ -2331,6 +2331,14 @@ bn.js "^5.1.2" buffer-layout "^1.2.0" +"@project-serum/sol-wallet-adapter@^0.1.5": + version "0.1.8" + resolved "https://registry.yarnpkg.com/@project-serum/sol-wallet-adapter/-/sol-wallet-adapter-0.1.8.tgz#90c6c1da793d32ed4ba3c67c5702a5bc804ef197" + integrity sha512-lKMgp7bsKpkrtBtIaEjtGuUMke0GUqFUL39Z7cjqsQpTVhkU5Ez4zHyjhXqAEORRGLFbwx/+H6HLpwppxpUDMQ== + dependencies: + bs58 "^4.0.1" + eventemitter3 "^4.0.4" + "@project-serum/swap-ui@^0.2.4": version "0.2.4" resolved "https://registry.yarnpkg.com/@project-serum/swap-ui/-/swap-ui-0.2.4.tgz#fe53d3089cf8ab3c7382bf70da763b1aff3d36d6" @@ -2428,13 +2436,13 @@ dependencies: cross-fetch "3.0.6" -"@solana/spl-token@0.1.4": - version "0.1.4" - resolved "https://registry.yarnpkg.com/@solana/spl-token/-/spl-token-0.1.4.tgz#7fc6ba82a7fbb2b0907f7ffc87709488db83ed2a" - integrity sha512-W8uSC4ysWVjbKK7lvsIHFxdMIkOCEoOm9tYY9VVpBlUIp4+K5bpPxHXUlxMiHfkKPWAxab6IGUn71VVLg8uq5Q== +"@solana/spl-token@0.1.3": + version "0.1.3" + resolved "https://registry.yarnpkg.com/@solana/spl-token/-/spl-token-0.1.3.tgz#6bf7c1a74cd95dabe8b8164e4c13b987db5be3bd" + integrity sha512-M251on5RDz8VQXoKoQPeLANEyI4qhThKLZBeUiLbFZ93KRgouGfmV5D/bUZXkLF75PlLcARIzU9ptoHOlZ6SbQ== dependencies: "@babel/runtime" "^7.10.5" - "@solana/web3.js" "^1.9.1" + "@solana/web3.js" "^1.2.2" bn.js "^5.1.0" buffer "6.0.3" buffer-layout "^1.2.0" @@ -2475,7 +2483,7 @@ tweetnacl "^1.0.0" ws "^7.0.0" -"@solana/web3.js@^1.11.0", "@solana/web3.js@^1.9.1": +"@solana/web3.js@^1.11.0": version "1.11.0" resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.11.0.tgz#1cc9a25381687c82e444ad0633f028e050a06753" integrity sha512-kmngWxntzp0HNhWInd7/3g2uqxdOrahvaHOyjilcRe+WCiC777gERz3+eIAbxIYx2zAZPjy02MZzLgoRHccZoQ== @@ -2514,6 +2522,26 @@ superstruct "^0.14.2" tweetnacl "^1.0.0" +"@solana/web3.js@^1.2.2", "@solana/web3.js@^1.29.2": + version "1.34.0" + resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.34.0.tgz#33becf2c7e87497d73406374185e54e0b7bc235d" + integrity sha512-6QvqN2DqEELvuV+5yUQM8P9fRiSG+6SzQ58HjumJqODu14r7eu5HXVWEymvKAvMLGME+0TmAdJHjw9xD5NgUWA== + dependencies: + "@babel/runtime" "^7.12.5" + "@ethersproject/sha2" "^5.5.0" + "@solana/buffer-layout" "^3.0.0" + bn.js "^5.0.0" + borsh "^0.4.0" + bs58 "^4.0.1" + buffer "6.0.1" + cross-fetch "^3.1.4" + jayson "^3.4.4" + js-sha3 "^0.8.0" + rpc-websockets "^7.4.2" + secp256k1 "^4.0.2" + superstruct "^0.14.2" + tweetnacl "^1.0.0" + "@solana/web3.js@^1.21.0", "@solana/web3.js@^1.24.0": version "1.29.3" resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.29.3.tgz#f14e736c006ee81c8b71082dcba8530937ec8706" @@ -4057,7 +4085,7 @@ bn.js@^5.0.0, bn.js@^5.1.1, bn.js@^5.1.2: resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.1.3.tgz#beca005408f642ebebea80b042b4d18d2ac0ee6b" integrity sha512-GkTiFpjFtUzU9CbMeJ5iazkCzGL3jrhzerzZIuqLABjbwRaFt33I9tUdSNryIptM+RxDet6OKm2WnLXzW51KsQ== -bn.js@^5.1.0, bn.js@^5.1.3: +bn.js@^5.1.0, bn.js@^5.1.3, bn.js@^5.2.0: version "5.2.0" resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.2.0.tgz#358860674396c6997771a9d051fcc1b57d4ae002" integrity sha512-D7iWRBvnZE8ecXiLj/9wbxH7Tk79fAh8IHaTNq1RWRixsS02W+5qS+iE9yq6RYl0asXx5tw0bLhmT5pIfbSquw== @@ -4105,6 +4133,15 @@ borsh@^0.4.0: bs58 "^4.0.0" text-encoding-utf-8 "^1.0.2" +borsh@^0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/borsh/-/borsh-0.6.0.tgz#a7c9eeca6a31ca9e0607cb49f329cb659eb791e1" + integrity sha512-sl5k89ViqsThXQpYa9XDtz1sBl3l1lI313cFUY1HKr+wvMILnb+58xpkqTNrYbelh99dY7K8usxoCusQmqix9Q== + dependencies: + bn.js "^5.2.0" + bs58 "^4.0.0" + text-encoding-utf-8 "^1.0.2" + brace-expansion@^1.1.7: version "1.1.11" resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" @@ -5139,18 +5176,6 @@ crypto-random-string@^1.0.0: resolved "https://registry.yarnpkg.com/crypto-random-string/-/crypto-random-string-1.0.0.tgz#a230f64f568310e1498009940790ec99545bca7e" integrity sha1-ojD2T1aDEOFJgAmUB5DsmVRbyn4= -crypto-ts@^1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/crypto-ts/-/crypto-ts-1.0.2.tgz#c2ae47b42f1a8affcf33bddbe3283983150c8a05" - integrity sha1-wq5HtC8aiv/PM73b4yg5gxUMigU= - dependencies: - tslib "^1.7.1" - -crypto@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/crypto/-/crypto-1.0.1.tgz#2af1b7cad8175d24c8a1b0778255794a21803037" - integrity sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig== - css-blank-pseudo@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/css-blank-pseudo/-/css-blank-pseudo-0.1.4.tgz#dfdefd3254bf8a82027993674ccf35483bfcb3c5" @@ -5404,6 +5429,13 @@ csstype@^3.0.2: resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.0.2.tgz#ee5ff8f208c8cd613b389f7b222c9801ca62b3f7" integrity sha512-ofovWglpqoqbfLNOTBNZLSbMuGrblAf1efvvArGKOZMBrIoJeu5UsAipQolkijtyQx5MtAzT/J9IHj/CEY1mJw== +csv-parser@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/csv-parser/-/csv-parser-3.0.0.tgz#b88a6256d79e090a97a1b56451f9327b01d710e7" + integrity sha512-s6OYSXAK3IdKqYO33y09jhypG/bSDHPuyCme/IdEHfWpLf/jKcpitVFyOC6UemgGk8v7Q5u2XE0vvwmanxhGlQ== + dependencies: + minimist "^1.2.0" + cyclist@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/cyclist/-/cyclist-1.0.1.tgz#596e9698fd0c80e12038c2b82d6eb1b35b6224d9" @@ -6529,7 +6561,7 @@ eventemitter3@4.0.4, eventemitter3@^4.0.0: resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.4.tgz#b5463ace635a083d018bdc7c917b4c5f10a85384" integrity sha512-rlaVLnVxtxvoyLsQQFBx53YmXHDxRIzzTLbdfxqi4yocpSjAxXwkU0cScM5JgSKMqEhrZpnvQ2D9gjylR0AimQ== -eventemitter3@^4.0.7: +eventemitter3@^4.0.4, eventemitter3@^4.0.7: version "4.0.7" resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f" integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw== @@ -13603,11 +13635,6 @@ tslib@^1.10.0, tslib@^1.8.1, tslib@^1.9.0: resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.13.0.tgz#c881e13cc7015894ed914862d276436fa9a47043" integrity sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q== -tslib@^1.7.1: - version "1.14.1" - resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" - integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== - tslib@^2.0.3: version "2.2.0" resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.2.0.tgz#fb2c475977e35e241311ede2693cee1ec6698f5c"