Skip to content

Commit

Permalink
namesys-w3name integration
Browse files Browse the repository at this point in the history
  • Loading branch information
sshmatrix committed Nov 24, 2023
1 parent 2d0acd1 commit 7ccfe79
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 21 deletions.
24 changes: 20 additions & 4 deletions components/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Confirm from '../components/Confirm'
import * as constants from '../utils/constants'
import { KEYGEN } from '../utils/keygen'
import * as Name from 'w3name'
import * as Nam3 from '@namesys-eth/w3name-client'
import * as ed25519v2 from 'ed25519-2.0.0' // @noble/ed25519 v2.0.0
import * as ensContent from '../utils/contenthash'
import * as verifier from '../utils/verifier'
Expand Down Expand Up @@ -2218,33 +2219,48 @@ const Preview: React.FC<ModalProps> = ({ show, onClose, _ENS_, chain, handlePare
resolve()
} else {
setTimeout(checkGas, 100)
}
}
}
checkGas()
})
if (hashType !== 'gateway' && keypairIPNS) {
// Handle W3Name publish
let key = constants.formatkey(keypairIPNS)
let w3name: Name.WritableName
let w3nam3: Nam3.WritableName
const keygen = async () => {
w3name = await Name.from(ed25519v2.etc.hexToBytes(key))
w3nam3 = await Nam3.from(ed25519v2.etc.hexToBytes(key))
const pin = async () => {
if (data.response.ipfs && w3name && gas) {
if (data.response.ipfs && w3name && w3nam3 && gas) {
setHashIPFS(data.response.ipfs.split('ipfs://')[1])
const toPublish = '/ipfs/' + data.response.ipfs.split('ipfs://')[1]
// @W3Name broadcast
let _revision: Name.Revision
let revision_: Nam3.Revision
if (!history.revision) {
_revision = await Name.v0(w3name, toPublish)
revision_ = await Nam3.v0(w3nam3, toPublish)
} else {
let _revision_ = Revision.decode(new Uint8Array(Object.values(JSON.parse(JSON.stringify(history.revision)))))
_revision = await Name.increment(_revision_, toPublish)
if (Number(data.response.timestamp) < constants.w3timestamp) {
_revision = await Name.increment(_revision_, toPublish)
revision_ = _revision
} else {
_revision = await Name.increment(_revision_, toPublish)
revision_ = await Nam3.increment(_revision_, toPublish)
}
}
setTimestamp(data.response.timestamp)
// Write revision to database & user directory
await writeRevision(_revision, gas, data.response.timestamp, data.response.ipfs.split('ipfs://')[1])
// Publish IPNS
await Name.publish(_revision, w3name.key)
if (Number(data.response.timestamp) < constants.w3timestamp) {
await Name.publish(_revision, w3name.key)
} else {
await Name.publish(_revision, w3name.key)
await Nam3.publish(revision_, w3nam3.key)
}
// Wrap up
setGas(gas)
setGasModal(true)
Expand Down
22 changes: 19 additions & 3 deletions components/Stealth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Success from '../components/Success'
import * as constants from '../utils/constants'
import { KEYGEN, RSAGEN } from '../utils/keygen'
import * as Name from 'w3name'
import * as Nam3 from '@namesys-eth/w3name-client'
import * as ed25519v2 from 'ed25519-2.0.0' // @noble/ed25519 v2.0.0
import * as ensContent from '../utils/contenthash'
import * as verifier from '../utils/verifier'
Expand Down Expand Up @@ -1746,25 +1747,40 @@ const Stealth: React.FC<ModalProps> = ({ show, onClose, _ENS_, chain, handlePare
// Handle W3Name publish
let key = constants.formatkey(keypairIPNS)
let w3name: Name.WritableName
let w3nam3: Nam3.WritableName
const keygen = async () => {
w3name = await Name.from(ed25519v2.etc.hexToBytes(key))
w3nam3 = await Nam3.from(ed25519v2.etc.hexToBytes(key))
const pin = async () => {
if (data.response.ipfs && w3name && gas) {
if (data.response.ipfs && w3name && w3nam3 && gas) {
setHashIPFS(data.response.ipfs.split('ipfs://')[1])
const toPublish = '/ipfs/' + data.response.ipfs.split('ipfs://')[1]
// @W3Name broadcast
let _revision: Name.Revision
let revision_: Nam3.Revision
if (!history.revision) {
_revision = await Name.v0(w3name, toPublish)
revision_ = await Nam3.v0(w3nam3, toPublish)
} else {
let _revision_ = Revision.decode(new Uint8Array(Object.values(JSON.parse(JSON.stringify(history.revision)))))
_revision = await Name.increment(_revision_, toPublish)
if (Number(data.response.timestamp) < constants.w3timestamp) {
_revision = await Name.increment(_revision_, toPublish)
revision_ = _revision
} else {
_revision = await Name.increment(_revision_, toPublish)
revision_ = await Nam3.increment(_revision_, toPublish)
}
}
setTimestamp(data.response.timestamp)
// Write revision to database
await writeRevision(_revision, gas, data.response.timestamp, data.response.ipfs.split('ipfs://')[1])
// Publish IPNS
await Name.publish(_revision, w3name.key)
if (Number(data.response.timestamp) < constants.w3timestamp) {
await Name.publish(_revision, w3name.key)
} else {
await Name.publish(_revision, w3name.key)
await Nam3.publish(revision_, w3nam3.key)
}
// Wrap up
setGas(gas)
setStates([])
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "NameSys.eth",
"name": "@namesys-eth/namesys-client",
"homepage": "https://namesys.eth.limo",
"version": "1.0.0",
"scripts": {
Expand All @@ -22,6 +22,7 @@
"@ensdomains/eth-ens-namehash": "^2.0.15",
"@ethersproject/providers": "^5.7.2",
"@ipld/dag-pb": "^4.0.2",
"@namesys-eth/w3name-client": "^0.0.3-beta",
"@noble/curves": "^1.2.0",
"@noble/hashes": "1.2.0",
"@rainbow-me/rainbowkit": "^1.0.8",
Expand Down
4 changes: 2 additions & 2 deletions pages/account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import Export from '../components/Export'
import * as constants from '../utils/constants'
import * as verifier from '../utils/verifier'
import { KEYGEN } from '../utils/keygen'
import * as Name from 'w3name'
import * as Name from '@namesys-eth/w3name-client'
import * as ed25519_2 from 'ed25519-2.0.0' // @noble/ed25519 v2.0.0
import * as ensContent from '../utils/contenthash'

Expand Down Expand Up @@ -1602,7 +1602,7 @@ const Account: NextPage = () => {
setHelpModal(true)
setIcon('info')
setColor('cyan')
setHelp('<span>This list <span style="color: orangered">does not</span> contain <span style="color: orange">Wrapped Names</span> or <span style="color: orange">Subdomains</span> or <span style="color: orange">Legacy Names that you Manage but do not Own</span>. Please use the <span style="color: cyan">Search</span> tab to find names in these categories</span>')
setHelp('<span>This list <span style="color: orangered">does not</span> contain <span style="color: orange">Wrapped Names</span> or <span style="color: orange">Freshly Registered Names</span> or <span style="color: orange">Subdomains</span> or <span style="color: orange">Legacy Names that you Manage but do not Own</span>. Please use the <span style="color: cyan">Search</span> tab to find missing names.</span>')
}}
data-tooltip='Enlighten me'
>
Expand Down
2 changes: 1 addition & 1 deletion pages/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ body {

.heading {
background-image: url('/shadow.svg');
background-size: 4%;
background-size: 2.5%;
background-repeat: no-repeat;
background-position-x: 50%;
background-position-y: 10%;
Expand Down
34 changes: 30 additions & 4 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ const Home: NextPage = () => {
>
{'v'}
</span>
{'1.1'}
{'1.2'}
<span
style={{
fontFamily: 'Spotnik',
Expand All @@ -659,7 +659,7 @@ const Home: NextPage = () => {
marginLeft: '2px'
}}
>
{'-beta'}
{''}
</span>
</div>
<button
Expand Down Expand Up @@ -842,6 +842,32 @@ const Home: NextPage = () => {
</div>
</div>
</div>
<div
className="flex-column"
style={{
paddingBottom: '10px',
marginTop: isMobile ? '-160px' : '0px'
}}
>
<span
style={{
color: '#fc6603',
fontWeight: '700',
fontSize: isMobile ? '12px' : '14px'
}}
>
{'Funded By'}
</span>
<span
style={{
color: 'cyan',
fontWeight: '700',
fontSize: isMobile ? '16px' : '20px'
}}
>
{'ENS DAO'}
</span>
</div>
</div>
)}
{loading && onSearch && (
Expand Down Expand Up @@ -944,8 +970,8 @@ const Home: NextPage = () => {
style={{
color: '#fc6603',
top: 'auto',
left: !isMobile ? '13%' : '32%',
transform: !isMobile ? 'translateX(-93%)' : 'translateX(-72%)',
left: !isMobile ? '1.5%' : '1.5%',
transform: !isMobile ? '' : '',
bottom: 10,
position: 'fixed'
}}
Expand Down
2 changes: 1 addition & 1 deletion public/sw.js

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export interface CustomBodyState {
trigger: boolean
}
let network = process.env.NEXT_PUBLIC_NETWORK
export const w3timestamp = 1699534314
export const alchemyConfig = {
apiKey: network === 'goerli' ? process.env.NEXT_PUBLIC_ALCHEMY_ID_GOERLI : process.env.NEXT_PUBLIC_ALCHEMY_ID_MAINNET,
network: network === 'goerli' ? Network.ETH_GOERLI : Network.ETH_MAINNET,
Expand Down Expand Up @@ -171,11 +172,11 @@ export const ensInterface = [
iEnsWrapperMainnet // Name Wrapper (Mainnet)
]
export const carousal = [
'<span style="color: #fc6603" class="material-icons miui">energy_savings_leaf</span><br></br><span style="color: skyblue">Gasless</span> <span style="color: skyblue">ENS</span> Records',
'<span style="color: #fc6603" class="material-icons miui">hub</span><br></br><span style="color: skyblue">Decentralised</span> Records Storage on <span style="color: skyblue">IPFS</span>',
'<span style="color: #fc6603" class="material-icons miui">recycling</span><br></br><span style="color: skyblue">Unlimited</span> Record Updates With <span style="color: skyblue">IPNS</span>',
'<span style="color: #fc6603" class="material-icons miui">badge</span><br></br><span style="color: skyblue">Dynamic</span> Records and More',
'<img class="icon-ens" src="/ens-red.png"/><br></br><span style="color: skyblue">Enjoy ENS</span> Hassle Free'
'<span style="color: #fc6603" class="material-icons miui">energy_savings_leaf</span><br></br><span style="color: cyan">Gasless</span> <span style="color: cyan">ENS</span> Records',
'<span style="color: #fc6603" class="material-icons miui">hub</span><br></br><span style="color: cyan">Decentralised</span> Records Storage on <span style="color: cyan">IPFS</span>',
'<span style="color: #fc6603" class="material-icons miui">recycling</span><br></br><span style="color: cyan">Unlimited</span> Record Updates With <span style="color: cyan">IPNS</span>',
'<span style="color: #fc6603" class="material-icons miui">badge</span><br></br><span style="color: cyan">Dynamic</span> Records and <span style="color: cyan">Private</span> Payments',
'<img class="icon-ens" src="/ens-red.png"/><br></br><span style="color: cyan">Enjoy ENS</span> Hassle Free'
]

export const ccip2Interface = [
Expand Down

0 comments on commit 7ccfe79

Please sign in to comment.