-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Permissioned domains #3102
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
Merged
Merged
Permissioned domains #3102
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cd53966
add permissioned domain modular tutorial
oeggert 7f80874
add reviewer suggestions
oeggert b9232fc
Update _code-samples/modular-tutorials/credential-manager.js
oeggert e3c6c8d
Update docs/tutorials/javascript/compliance/create-permissioned-domai…
oeggert 2fb6579
Update docs/tutorials/javascript/compliance/create-permissioned-domai…
oeggert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
211 changes: 211 additions & 0 deletions
211
_code-samples/modular-tutorials/create-permissioned-domain.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
<html> | ||
<head> | ||
<title>Create Permissioned Domain</title> | ||
<link href='https://fonts.googleapis.com/css?family=Work Sans' rel='stylesheet'> | ||
<link href="modular-tutorials.css" rel="stylesheet"> | ||
<script src='https://unpkg.com/xrpl@4.2.5/build/xrpl-latest.js'></script> | ||
<script src="account-support.js"></script> | ||
<script src='credential-manager.js'></script> | ||
<script src='permissioned-domain-manager.js'></script> | ||
</head> | ||
|
||
<!-- ************************************************************** --> | ||
<!-- ********************** The Form ****************************** --> | ||
<!-- ************************************************************** --> | ||
|
||
<body> | ||
<h1>Create Permissioned Domain</h1> | ||
<form id="theForm"> | ||
<span class="tooltip" tooltip-data="Choose the XRPL host server for your account."> | ||
Choose your ledger instance: | ||
</span> | ||
| ||
<input type="radio" id="dn" name="server" value="wss://s.devnet.rippletest.net:51233" checked> | ||
<label for="dn">Devnet</label> | ||
| ||
<input type="radio" id="tn" name="server" value="wss://s.altnet.rippletest.net:51233"> | ||
<label for="tn">Testnet</label> | ||
<br /><br /> | ||
<table> | ||
<tr> | ||
<td> | ||
<button type="button" onClick="getNewAccount1()">Get New Account 1</button> | ||
</td> | ||
<td> | ||
<button type="button" onClick="getAccountFromSeed1()">Get Account 1 From Seed</button> | ||
</td> | ||
<td> | ||
<button type="button" onClick="getNewAccount2()">Get New Account 2</button> | ||
</td> | ||
<td> | ||
<button type="button" onClick="getAccountFromSeed2()">Get Account 2 From Seed</button> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<span class="tooltip" tooltip-data="Arbitrary human-readable name for the account."><label for="account1name">Account 1 Name</label> | ||
</span> | ||
</td> | ||
<td> | ||
<input type="text" id="account1name" size="40"></input> | ||
</td> | ||
<td> | ||
<span class="tooltip" tooltip-data="Arbitrary human-readable name for the account."> | ||
<label for="account2name">Account 2 Name</label> | ||
</span> | ||
</td> | ||
<td> | ||
<input type="text" id="account2name" size="40"></input> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<span class="tooltip" tooltip-data="Identifying address for the account."> | ||
<label for="account1address">Account 1 Address</label> | ||
</span> | ||
</td> | ||
<td> | ||
<input type="text" id="account1address" size="40"></input> | ||
</td> | ||
<td> | ||
<span class="tooltip" tooltip-data="Identifying address for the account."> | ||
<label for="account2address">Account 2 Address</label> | ||
</span> | ||
</td> | ||
<td> | ||
<input type="text" id="account2address" size="40"></input> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<span class="tooltip" tooltip-data="Seed for deriving public and private keys for the account."> | ||
<label for="account1seed">Account 1 Seed</label> | ||
</span> | ||
</td> | ||
<td> | ||
<input type="text" id="account1seed" size="40"></input> | ||
</td> | ||
<td> | ||
<span class="tooltip" tooltip-data="Seed for deriving public and private keys for the account."> | ||
<label for="account2seed">Account 2 Seed</label> | ||
</span> | ||
</td> | ||
<td> | ||
<input type="text" id="account2seed" size="40"></input> | ||
</td> | ||
</tr> | ||
</table> | ||
<hr /> | ||
<table> | ||
<tr valign="top"> | ||
<td align="right"> | ||
<span class="tooltip" tooltip-data="Name of the currently selected account."> | ||
<label for="accountNameField">Account Name</label> | ||
</span> | ||
</td> | ||
<td> | ||
<input type="text" id="accountNameField" size="40" readonly></input> | ||
<input type="radio" id="account1" name="accounts" value="account1"> | ||
<label for="account1">Account 1</label> | ||
</td> | ||
</tr> | ||
<tr valign="top"> | ||
<td align="right"> | ||
<span class="tooltip" tooltip-data="Address of the currently selected account."> | ||
<label for="accountAddressField">Account Address</label> | ||
</span> | ||
</td> | ||
<td> | ||
<input type="text" id="accountAddressField" size="40" readonly></input> | ||
<input type="radio" id="account2" name="accounts" value="account2"> | ||
<label for="account2">Account 2</label> | ||
</td> | ||
</tr> | ||
<tr valign="top"> | ||
<td align="right"> | ||
<span class="tooltip" tooltip-data="Seed of the currently selected account."> | ||
<label for="accountSeedField">Account Seed</label> | ||
</span> | ||
</td> | ||
<td> | ||
<input type="text" id="accountSeedField" size="40" readonly></input> | ||
<br> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td align="right"> | ||
<span class="tooltip" tooltip-data="XRP balance for the currently selected account."> | ||
<label for="xrpBalanceField">XRP Balance</label> | ||
</span> | ||
</td> | ||
<td> | ||
<input type="text" id="xrpBalanceField" size="40" readonly></input> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td align="right"> | ||
<span class="tooltip" tooltip-data="Account receiving the credential."> | ||
<label for="subjectField">Subject</label> | ||
</span> | ||
</td> | ||
<td> | ||
<input type="text" id="subjectField" size="40"></input> | ||
<br> | ||
</td> | ||
<td align="left" valign="top"> | ||
<button type="button" onClick="createCredential()">Create Credential</button> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td align="right"> | ||
<span class="tooltip" tooltip-data="Arbitrary data defining the type of credential this entry represents."> | ||
<lable for="credentialTypeField">Credential Type</lable> | ||
</span> | ||
</td> | ||
<td> | ||
<input type="text" id="credentialTypeField" size="40"></input> | ||
<br> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td align="right"> | ||
<span class="tooltip" tooltip-data="The ledger entry ID of an existing permissioned domain to modify. If omitted, creates a new permissioned domain."> | ||
<label for="domainIDField">Domain ID</label> | ||
</span> | ||
</td> | ||
<td> | ||
<input type="text" id="domainIDField" size="40"></input> | ||
<br> | ||
</td> | ||
<td align="left" valign="top"> | ||
<button type="button" onClick="createDomain()">Create Permissioned Domain</button> | ||
<button type="button" onClick="deleteDomain()">Delete Permissioned Domain</button> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td colspan="2"> | ||
<p align="right"> | ||
<textarea id="resultField" cols="80" rows="20"></textarea> | ||
</p> | ||
</td> | ||
<td align="left" valign="top"> | ||
<button type="button" onClick="gatherAccountInfo()">Gather Account Info</button><br/> | ||
<button type="button" onClick="distributeAccountInfo()">Distribute Account Info</button> | ||
</td> | ||
</tr> | ||
</table> | ||
</form> | ||
</body> | ||
<script> | ||
const radioButtons = document.querySelectorAll('input[type="radio"]'); | ||
radioButtons.forEach(radio => { | ||
radio.addEventListener('change', function() { | ||
if (this.value === 'account1') { | ||
populate1() | ||
} else if (this.value === 'account2') { | ||
populate2() | ||
} | ||
}); | ||
}); | ||
</script> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Create credential function | ||
async function createCredential() { | ||
|
||
let net = getNet() | ||
const client = new xrpl.Client(net) | ||
results = `\n\n===Creating Credential===\n\nConnecting to ${getNet()} ...` | ||
updateResults() | ||
await client.connect() | ||
results = `\n\nConnected.` | ||
updateResults() | ||
|
||
// Gather transaction info | ||
try { | ||
|
||
// Get account wallet from seed | ||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value) | ||
|
||
// Get subject | ||
const subject = subjectField.value | ||
|
||
// Get credential type - convert string to hex if needed | ||
let credentialType = credentialTypeField.value; | ||
if (!/^[0-9A-F]+$/i.test(credentialType)) { | ||
let hex = ''; | ||
for (let i = 0; i < credentialType.length; i++) { | ||
const charCode = credentialType.charCodeAt(i); | ||
const hexCharCode = charCode.toString(16).padStart(2, '0'); | ||
hex += hexCharCode; | ||
} | ||
credentialType = hex.toUpperCase(); | ||
} | ||
|
||
// Prepare transaction | ||
const transaction = { | ||
"TransactionType": "CredentialCreate", | ||
"Account": wallet.address, | ||
"Subject": subject, | ||
"CredentialType": credentialType | ||
} | ||
|
||
results = `\n\n===Preparing and Sending Transaction===\n\n${JSON.stringify(transaction, null, 2)}` | ||
updateResults() | ||
|
||
// Submit transaction | ||
const tx = await client.submitAndWait(transaction, {autofill: true, wallet: wallet}) | ||
|
||
if (tx.result.meta.TransactionResult == "tesSUCCESS") { | ||
// Parse for credential info | ||
const parsedResponse = JSON.parse(JSON.stringify(tx.result.meta.AffectedNodes, null, 2)) | ||
const credentialInfo = parsedResponse.find( node => node.CreatedNode && node.CreatedNode.LedgerEntryType === "Credential" ) | ||
results = `\n\n===Create Credential Result===\n\n${JSON.stringify(credentialInfo.CreatedNode, null, 2)}` | ||
} else { | ||
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` | ||
} | ||
|
||
updateResults() | ||
|
||
} catch (error) { | ||
results = `\n\n===Error===\n\n${error}` | ||
updateResults() | ||
} | ||
|
||
client.disconnect() | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use convenience functions from the
@xrplf/isomorphic
package to convert string to hex or hex back to string:stringToHex
,hexToString
.Also mentioned in
xrpl.js
reference:https://js.xrpl.org/functions/convertStringToHex.html
https://js.xrpl.org/functions/convertHexToString.html