forked from 0xPolygonID/js-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
100 lines (90 loc) · 3.08 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible"
content="IE=edge">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<script src="./dist/umd/index.js"></script>
<title>Test</title>
</head>
<body>
Test browser
</body>
<script>
const {
LocalStoragePrivateKeyStore,
IdentityStorage,
MerkleTreeLocalStorage,
CredentialStorage,
W3CCredential,
BrowserDataSource,
BjjProvider,
KmsKeyType,
IdentityWallet,
CredentialWallet,
KMS,
core,
CredentialStatusType,
CredentialStatusResolverRegistry,
IssuerResolver,
RHSResolver,
defaultEthConnectionConfig,
OnChainResolver,
MerkleTreeIndexedDBStorage
} = PolygonIdSdk;
const run = async () => {
const keyStore = new LocalStoragePrivateKeyStore();
const bjjProvider = new BjjProvider(KmsKeyType.BabyJubJub, keyStore);
const kms = new KMS();
kms.registerKeyProvider(KmsKeyType.BabyJubJub, bjjProvider);
dataStorage = {
credential: new CredentialStorage(
new BrowserDataSource(CredentialStorage.storageKey)
),
identity: new IdentityStorage(
new BrowserDataSource(IdentityStorage.identitiesStorageKey),
new BrowserDataSource(IdentityStorage.profilesStorageKey)
),
mt: new MerkleTreeIndexedDBStorage(40),
states: {
getLatestStateById: async (issuerId) => {
return { id: BigInt(0), state: BigInt(0) };
}
}
};
const resolvers = new CredentialStatusResolverRegistry();
resolvers.register(
CredentialStatusType.SparseMerkleTreeProof,
new IssuerResolver()
);
resolvers.register(
CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
new RHSResolver(dataStorage.states)
);
resolvers.register(
CredentialStatusType.Iden3OnchainSparseMerkleTreeProof2023,
new OnChainResolver([defaultEthConnectionConfig])
)
const credWallet = new CredentialWallet(dataStorage, resolvers);
wallet = new IdentityWallet(kms, dataStorage, credWallet);
console.log(wallet);
const seedPhrase = new TextEncoder().encode('seedseedseedseedseedseedseedseed');
const { did, credential } = await wallet.createIdentity({
method: core.DidMethod.Iden3,
blockchain: core.Blockchain.Polygon,
networkId: core.NetworkId.Mumbai,
seed: seedPhrase,
revocationOpts: {
type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
id: 'http://rhs.com/node'
}
}
);
console.log(did.toString());
console.assert(did.toString() === 'did:iden3:polygon:mumbai:wzokvZ6kMoocKJuSbftdZxTD6qvayGpJb3m4FVXth');
};
run().catch(console.error);
</script>
</html>