Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: updated testnet contract address for linked-resource #22

Merged
merged 1 commit into from
Jan 9, 2024
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"release": "release-it"
},
"dependencies": {
"@ayanworks/polygon-did-registry-contract": "2.0.1-alpha.1",
"@ayanworks/polygon-did-registry-contract": "2.0.1-alpha.3",
"did-resolver": "^4.1.0",
"ethers": "^5.1.0"
},
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const networkConfig = {
testnet: {
URL: 'https://rpc-mumbai.maticvigil.com/',
CONTRACT_ADDRESS: '0x8B335A167DA81CCef19C53eE629cf2F6291F2255',
CONTRACT_ADDRESS: '0x12513116875BB3E4F098Ce74624739Ee51bAf023',
},
mainnet: {
URL: 'https://polygon-rpc.com',
Expand Down
12 changes: 7 additions & 5 deletions src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ import { parseDid, validateDid } from './utils/did'
*/
export function getResolver(): Record<string, DIDResolver> {
async function resolve(did: string): Promise<DIDResolutionResult> {
const didDocumentMetadata = {}
try {
const isValidDid = validateDid(did)
if (!isValidDid) {
throw new Error('invalid did provided')
}

const parsedDid = parseDid(did)

const provider = new providers.JsonRpcProvider(parsedDid.networkUrl)
const registry = new Contract(
parsedDid.contractAddress,
Expand All @@ -31,13 +29,17 @@ export function getResolver(): Record<string, DIDResolver> {
parsedDid.didAddress,
)

if (!didDocument) {
if (!didDocument[0]) {
throw new Error(`The DID document for the given DID was not found!`)
}
// TODO: return only the did document instead of array

return {
didDocument: JSON.parse(didDocument[0]),
didDocumentMetadata,
didDocumentMetadata: {
linkedResourceMetadata: didDocument[1].map((element: string) => {
return JSON.parse(element)
}),
},
didResolutionMetadata: { contentType: 'application/did+ld+json' },
}
} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/test.data.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export const testDid =
'did:polygon:testnet:0x794b781493AeD65b9ceBD680716fec257e118993'
'did:polygon:testnet:0x13cd23928Ae515b86592C630f56C138aE4c7B79a'

export const url = 'https://rpc-mumbai.maticvigil.com/'

export const contractAddress = '0x8B335A167DA81CCef19C53eE629cf2F6291F2255'
export const contractAddress = '0x12513116875BB3E4F098Ce74624739Ee51bAf023'

export const DIDS = [
{
Expand Down
Loading