Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
ce92326c
Commit
ce92326c
authored
Feb 28, 2023
by
Will Cory
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
attestations too
parent
f80f90d6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
118 additions
and
2 deletions
+118
-2
index.ts
packages/atst/src/index.ts
+2
-0
parseAttestationBytes.ts
packages/atst/src/lib/parseAttestationBytes.ts
+1
-2
prepareWriteAttestations.spec.ts
packages/atst/src/lib/prepareWriteAttestations.spec.ts
+77
-0
prepareWriteAttestations.ts
packages/atst/src/lib/prepareWriteAttestations.ts
+38
-0
No files found.
packages/atst/src/index.ts
View file @
ce92326c
...
...
@@ -4,9 +4,11 @@ export { ATTESTATION_STATION_ADDRESS } from './constants/attestationStationAddre
export
{
readAttestation
}
from
'
./lib/readAttestation
'
export
{
readAttestations
}
from
'
./lib/readAttestations
'
export
{
prepareWriteAttestation
}
from
'
./lib/prepareWriteAttestation
'
export
{
prepareWriteAttestations
}
from
'
./lib/prepareWriteAttestations
'
export
{
writeAttestation
}
from
'
./lib/writeAttestation
'
export
{
abi
}
from
'
./lib/abi
'
export
{
parseAttestationBytes
}
from
'
./lib/parseAttestationBytes
'
export
{
stringifyAttestationBytes
}
from
'
./lib/stringifyAttestationBytes
'
// types
export
type
{
AttestationReadParams
}
from
'
./types/AttestationReadParams
'
export
type
{
WagmiBytes
}
from
'
./types/WagmiBytes
'
...
...
packages/atst/src/lib/parseAttestationBytes.ts
View file @
ce92326c
...
...
@@ -2,7 +2,6 @@ import { BigNumber } from 'ethers'
import
{
toUtf8String
}
from
'
ethers/lib/utils.js
'
import
type
{
DataTypeOption
}
from
'
../types/DataTypeOption
'
import
*
as
logger
from
'
./logger
'
import
type
{
WagmiBytes
}
from
'
../types/WagmiBytes
'
export
const
parseAttestationBytes
=
(
...
...
@@ -24,6 +23,6 @@ export const parseAttestationBytes = (
if
(
dataType
===
'
string
'
)
{
return
attestationBytes
&&
toUtf8String
(
attestationBytes
)
}
logger
.
warn
(
`unrecognized dataType
${
dataType
satisfies
never
}
`
)
console
.
warn
(
`unrecognized dataType
${
dataType
satisfies
never
}
`
)
return
attestationBytes
}
packages/atst/src/lib/prepareWriteAttestations.spec.ts
0 → 100644
View file @
ce92326c
import
{
connect
,
createClient
}
from
'
@wagmi/core
'
import
{
providers
,
Wallet
}
from
'
ethers
'
import
{
expect
,
describe
,
it
,
beforeAll
}
from
'
vitest
'
import
{
MockConnector
}
from
'
@wagmi/core/connectors/mock
'
import
{
readAttestation
}
from
'
./readAttestation
'
import
{
prepareWriteAttestations
}
from
'
./prepareWriteAttestations
'
const
creator
=
'
0x60c5C9c98bcBd0b0F2fD89B24c16e533BaA8CdA3
'
const
about
=
'
0x2335022c740d17c2837f9C884Bfe4fFdbf0A95D5
'
const
key
=
'
optimist.base-uri
'
const
chainId
=
10
const
provider
=
new
providers
.
JsonRpcProvider
(
{
url
:
'
http://localhost:8545
'
,
},
chainId
)
const
wallet
=
Wallet
.
createRandom
({
provider
})
createClient
({
provider
,
})
beforeAll
(
async
()
=>
{
await
connect
({
connector
:
new
MockConnector
({
options
:
{
chainId
,
signer
:
new
Wallet
(
wallet
.
privateKey
,
provider
),
},
}),
})
})
describe
(
prepareWriteAttestations
.
name
,
()
=>
{
it
(
'
Should correctly prepare an attestation
'
,
async
()
=>
{
const
result
=
await
prepareWriteAttestations
([
{
about
,
key
,
value
:
'
hello world
'
,
},
])
expect
(
result
.
address
).
toMatchInlineSnapshot
(
'
"0xEE36eaaD94d1Cc1d0eccaDb55C38bFfB6Be06C77"
'
)
expect
(
result
.
chainId
).
toMatchInlineSnapshot
(
'
10
'
)
expect
(
result
.
functionName
).
toMatchInlineSnapshot
(
'
"attest"
'
)
expect
(
result
.
mode
).
toMatchInlineSnapshot
(
'
"prepared"
'
)
expect
(
result
.
request
.
gasLimit
).
toMatchInlineSnapshot
(
`
{
"hex": "0xd9ce",
"type": "BigNumber",
}
`
)
})
it
(
'
should throw an error if key is longer than 32 bytes
'
,
async
()
=>
{
const
dataType
=
'
string
'
await
expect
(
readAttestation
(
creator
,
about
,
'
this is a key that is way longer than 32 bytes so this key should throw an error matching the inline snapshot
'
,
dataType
)
).
rejects
.
toThrowErrorMatchingInlineSnapshot
(
'
"Key is longer than the max length of 32 for attestation keys"
'
)
})
})
packages/atst/src/lib/prepareWriteAttestations.ts
0 → 100644
View file @
ce92326c
import
{
Address
,
prepareWriteContract
}
from
'
@wagmi/core
'
import
{
formatBytes32String
}
from
'
ethers/lib/utils.js
'
import
{
ATTESTATION_STATION_ADDRESS
}
from
'
../constants/attestationStationAddress
'
import
{
WagmiBytes
}
from
'
../types/WagmiBytes
'
import
{
abi
}
from
'
./abi
'
import
{
stringifyAttestationBytes
}
from
'
./stringifyAttestationBytes
'
type
Attestation
=
{
about
:
Address
key
:
string
value
:
string
|
WagmiBytes
|
number
|
boolean
}
export
const
prepareWriteAttestations
=
async
(
attestations
:
Attestation
[],
chainId
=
10
,
contractAddress
:
Address
=
ATTESTATION_STATION_ADDRESS
)
=>
{
const
formattedAttestations
=
attestations
.
map
((
attestation
)
=>
{
const
formattedKey
=
formatBytes32String
(
attestation
.
key
)
as
WagmiBytes
const
formattedValue
=
stringifyAttestationBytes
(
attestation
.
value
)
as
WagmiBytes
return
{
about
:
attestation
.
about
,
key
:
formattedKey
,
val
:
formattedValue
,
}
as
const
})
return
prepareWriteContract
({
address
:
contractAddress
,
abi
,
functionName
:
'
attest
'
,
chainId
,
args
:
[
formattedAttestations
],
})
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment