Skip to content

Commit cd53966

Browse files
committed
add permissioned domain modular tutorial
1 parent 9befa99 commit cd53966

12 files changed

+757
-0
lines changed

_code-samples/modular-tutorials/account-support.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,14 @@ async function getTokenBalance() {
206206
}
207207
} // End of getTokenBalance()
208208

209+
// *******************************************************
210+
// **************** Scroll Results ***********************
211+
// *******************************************************
212+
let results
213+
214+
async function updateResults() {
215+
resultField.value += results;
216+
resultField.scrollTop = resultField.scrollHeight;
217+
}
218+
219+
// End of updateResults()
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
<html>
2+
<head>
3+
<title>Create Permissioned Domain</title>
4+
<link href='https://fonts.googleapis.com/css?family=Work Sans' rel='stylesheet'>
5+
<link href="modular-tutorials.css" rel="stylesheet">
6+
<script src='https://unpkg.com/xrpl@4.2.5/build/xrpl-latest.js'></script>
7+
<script src="account-support.js"></script>
8+
<script src='credential-manager.js'></script>
9+
<script src='permissioned-domain-manager.js'></script>
10+
</head>
11+
12+
<!-- ************************************************************** -->
13+
<!-- ********************** The Form ****************************** -->
14+
<!-- ************************************************************** -->
15+
16+
<body>
17+
<h1>Create Permissioned Domain</h1>
18+
<form id="theForm">
19+
<span class="tooltip" tooltip-data="Choose the XRPL host server for your account.">
20+
Choose your ledger instance:
21+
</span>
22+
&nbsp;&nbsp;
23+
<input type="radio" id="dn" name="server" value="wss://s.devnet.rippletest.net:51233" checked>
24+
<label for="dn">Devnet</label>
25+
&nbsp;&nbsp;
26+
<input type="radio" id="tn" name="server" value="wss://s.altnet.rippletest.net:51233">
27+
<label for="tn">Testnet</label>
28+
<br /><br />
29+
<table>
30+
<tr>
31+
<td>
32+
<button type="button" onClick="getNewAccount1()">Get New Account 1</button>
33+
</td>
34+
<td>
35+
<button type="button" onClick="getAccountFromSeed1()">Get Account 1 From Seed</button>
36+
</td>
37+
<td>
38+
<button type="button" onClick="getNewAccount2()">Get New Account 2</button>
39+
</td>
40+
<td>
41+
<button type="button" onClick="getAccountFromSeed2()">Get Account 2 From Seed</button>
42+
</td>
43+
</tr>
44+
<tr>
45+
<td>
46+
<span class="tooltip" tooltip-data="Arbitrary human-readable name for the account."><label for="account1name">Account 1 Name</label>
47+
</span>
48+
</td>
49+
<td>
50+
<input type="text" id="account1name" size="40"></input>
51+
</td>
52+
<td>
53+
<span class="tooltip" tooltip-data="Arbitrary human-readable name for the account.">
54+
<label for="account2name">Account 2 Name</label>
55+
</span>
56+
</td>
57+
<td>
58+
<input type="text" id="account2name" size="40"></input>
59+
</td>
60+
</tr>
61+
<tr>
62+
<td>
63+
<span class="tooltip" tooltip-data="Identifying address for the account.">
64+
<label for="account1address">Account 1 Address</label>
65+
</span>
66+
</td>
67+
<td>
68+
<input type="text" id="account1address" size="40"></input>
69+
</td>
70+
<td>
71+
<span class="tooltip" tooltip-data="Identifying address for the account.">
72+
<label for="account2address">Account 2 Address</label>
73+
</span>
74+
</td>
75+
<td>
76+
<input type="text" id="account2address" size="40"></input>
77+
</td>
78+
</tr>
79+
<tr>
80+
<td>
81+
<span class="tooltip" tooltip-data="Seed for deriving public and private keys for the account.">
82+
<label for="account1seed">Account 1 Seed</label>
83+
</span>
84+
</td>
85+
<td>
86+
<input type="text" id="account1seed" size="40"></input>
87+
</td>
88+
<td>
89+
<span class="tooltip" tooltip-data="Seed for deriving public and private keys for the account.">
90+
<label for="account2seed">Account 2 Seed</label>
91+
</span>
92+
</td>
93+
<td>
94+
<input type="text" id="account2seed" size="40"></input>
95+
</td>
96+
</tr>
97+
</table>
98+
<hr />
99+
<table>
100+
<tr valign="top">
101+
<td align="right">
102+
<span class="tooltip" tooltip-data="Name of the currently selected account.">
103+
<label for="accountNameField">Account Name</label>
104+
</span>
105+
</td>
106+
<td>
107+
<input type="text" id="accountNameField" size="40" readonly></input>
108+
<input type="radio" id="account1" name="accounts" value="account1">
109+
<label for="account1">Account 1</label>
110+
</td>
111+
</tr>
112+
<tr valign="top">
113+
<td align="right">
114+
<span class="tooltip" tooltip-data="Address of the currently selected account.">
115+
<label for="accountAddressField">Account Address</label>
116+
</span>
117+
</td>
118+
<td>
119+
<input type="text" id="accountAddressField" size="40" readonly></input>
120+
<input type="radio" id="account2" name="accounts" value="account2">
121+
<label for="account2">Account 2</label>
122+
</td>
123+
</tr>
124+
<tr valign="top">
125+
<td align="right">
126+
<span class="tooltip" tooltip-data="Seed of the currently selected account.">
127+
<label for="accountSeedField">Account Seed</label>
128+
</span>
129+
</td>
130+
<td>
131+
<input type="text" id="accountSeedField" size="40" readonly></input>
132+
<br>
133+
</td>
134+
</tr>
135+
<tr>
136+
<td align="right">
137+
<span class="tooltip" tooltip-data="XRP balance for the currently selected account.">
138+
<label for="xrpBalanceField">XRP Balance</label>
139+
</span>
140+
</td>
141+
<td>
142+
<input type="text" id="xrpBalanceField" size="40" readonly></input>
143+
</td>
144+
</tr>
145+
<tr>
146+
<td align="right">
147+
<span class="tooltip" tooltip-data="Account receiving the credential.">
148+
<label for="subjectField">Subject</label>
149+
</span>
150+
</td>
151+
<td>
152+
<input type="text" id="subjectField" size="40"></input>
153+
<br>
154+
</td>
155+
<td align="left" valign="top">
156+
<button type="button" onClick="createCredential()">Create Credential</button>
157+
</td>
158+
</tr>
159+
<tr>
160+
<td align="right">
161+
<span class="tooltip" tooltip-data="Arbitrary data defining the type of credential this entry represents.">
162+
<lable for="credentialTypeField">Credential Type</lable>
163+
</span>
164+
</td>
165+
<td>
166+
<input type="text" id="credentialTypeField" size="40"></input>
167+
<br>
168+
</td>
169+
</tr>
170+
<tr>
171+
<td align="right">
172+
<span class="tooltip" tooltip-data="The ledger entry ID of an existing permissioned domain to modify. If omitted, creates a new permissioned domain.">
173+
<label for="domainIDField">Domain ID</label>
174+
</span>
175+
</td>
176+
<td>
177+
<input type="text" id="domainIDField" size="40"></input>
178+
<br>
179+
</td>
180+
<td align="left" valign="top">
181+
<button type="button" onClick="createDomain()">Create Permissioned Domain</button>
182+
<button type="button" onClick="deleteDomain()">Delete Permissioned Domain</button>
183+
</td>
184+
</tr>
185+
<tr>
186+
<td colspan="2">
187+
<p align="right">
188+
<textarea id="resultField" cols="80" rows="20"></textarea>
189+
</p>
190+
</td>
191+
<td align="left" valign="top">
192+
<button type="button" onClick="gatherAccountInfo()">Gather Account Info</button><br/>
193+
<button type="button" onClick="distributeAccountInfo()">Distribute Account Info</button>
194+
</td>
195+
</tr>
196+
</table>
197+
</form>
198+
</body>
199+
<script>
200+
const radioButtons = document.querySelectorAll('input[type="radio"]');
201+
radioButtons.forEach(radio => {
202+
radio.addEventListener('change', function() {
203+
if (this.value === 'account1') {
204+
populate1()
205+
} else if (this.value === 'account2') {
206+
populate2()
207+
}
208+
});
209+
});
210+
</script>
211+
</html>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// *******************************************************
2+
// *********** Create Credential *************************
3+
// *******************************************************
4+
5+
async function createCredential() {
6+
7+
let net = getNet()
8+
const client = new xrpl.Client(net)
9+
results = `\n\n===Creating Credential===\n\nConnecting to ${getNet()} ...`
10+
updateResults()
11+
await client.connect()
12+
results = `\n\nConnected.`
13+
updateResults()
14+
15+
try {
16+
17+
// Get account wallet from seed
18+
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
19+
20+
// Get subject
21+
const subject = subjectField.value
22+
23+
// Get credential type - convert string to hex if needed
24+
let credentialType = credentialTypeField.value;
25+
if (!/^[0-9A-F]+$/i.test(credentialType)) {
26+
let hex = '';
27+
for (let i = 0; i < credentialType.length; i++) {
28+
const charCode = credentialType.charCodeAt(i);
29+
const hexCharCode = charCode.toString(16).padStart(2, '0');
30+
hex += hexCharCode;
31+
}
32+
credentialType = hex.toUpperCase();
33+
}
34+
35+
// Prepare transaction
36+
const transaction = {
37+
"TransactionType": "CredentialCreate",
38+
"Account": wallet.address,
39+
"Subject": subject,
40+
"CredentialType": credentialType
41+
}
42+
43+
results = `\n\n===Preparing and Sending Transaction===\n\n${JSON.stringify(transaction, null, 2)}`
44+
updateResults()
45+
46+
// Submit transaction
47+
const tx = await client.submitAndWait(transaction, {autofill: true, wallet: wallet})
48+
49+
if (tx.result.meta.TransactionResult == "tesSUCCESS") {
50+
// Parse for credential info
51+
const parsedResponse = JSON.parse(JSON.stringify(tx.result.meta.AffectedNodes, null, 2))
52+
const credentialInfo = parsedResponse.find( node => node.CreatedNode && node.CreatedNode.LedgerEntryType === "Credential" )
53+
results = `\n\n===Create Credential Result===\n\n${JSON.stringify(credentialInfo.CreatedNode, null, 2)}`
54+
} else {
55+
results = `\n\n===Error===\n\n${JSON.stringify(tx.result.meta.TransactionResult, null, 2)}: Check codes at https://xrpl.org/docs/references/protocol/transactions/types/credentialcreate#error-cases`
56+
}
57+
58+
updateResults()
59+
60+
} catch (error) {
61+
results = `\n\n===Error===\n\n${error}`
62+
updateResults()
63+
}
64+
65+
client.disconnect()
66+
}

0 commit comments

Comments
 (0)