Update with SME review comments

This commit is contained in:
Maria Shodunke
2025-04-17 11:07:19 +01:00
parent 0f9338c0b9
commit 2bcb9f67d3
6 changed files with 33 additions and 44 deletions

View File

@@ -4,7 +4,7 @@ import dotenv from "dotenv";
import inquirer from "inquirer";
import { Client, Wallet } from "xrpl";
import { lookUpCredentials } from "./look_up_credentials.js";
import { decodeHex } from "./decode_hex.js";
import { hexToString } from "@xrplf/isomorphic/dist/utils/index.js";
const XRPL_SERVER = "wss://s.devnet.rippletest.net:51233"
@@ -41,7 +41,7 @@ async function main() {
);
const choices = pendingCredentials.map((cred, i) => ({
name: `${i+1}) '${decodeHex(cred.CredentialType)}' issued by ${cred.Issuer}`,
name: `${i+1}) '${hexToString(cred.CredentialType)}' issued by ${cred.Issuer}`,
value: i,
}));
choices.unshift({ name: "0) No, quit.", value: -1 });

View File

@@ -3,13 +3,12 @@ import {
rippleTimeToISOTime,
isValidClassicAddress,
} from "xrpl";
import { stringToHex } from "@xrplf/isomorphic/dist/utils/index.js";
import { stringToHex, hexToString } from "@xrplf/isomorphic/dist/utils/index.js";
import { decodeHex } from "./decode_hex.js";
import { ValueError } from "./errors.js";
// Regex constants
const CREDENTIAL_REGEX = /^[A-Za-z0-9_.-]{1,64}$/;
const CREDENTIAL_REGEX = /^[A-Za-z0-9_.-]{1,128}$/;
const URI_REGEX = /^[A-Za-z0-9\-._~:/?#\[\]@!$&'()*+,;=%]{1,256}$/;
/**
@@ -93,8 +92,8 @@ export function credentialFromXrpl(entry) {
const { Subject, CredentialType, URI, Expiration, Flags } = entry;
return {
subject: Subject,
credential: decodeHex(CredentialType),
uri: URI ? decodeHex(URI) : undefined,
credential: hexToString(CredentialType),
uri: URI ? hexToString(URI) : undefined,
expiration: Expiration ? rippleTimeToISOTime(Expiration) : undefined,
accepted: Boolean(Flags & 0x00010000), // lsfAccepted
};

View File

@@ -1,14 +0,0 @@
export function decodeHex(sHex) {
/**
* Try decoding a hex string as ASCII; return the decoded string on success,
* or the un-decoded string prefixed by '(BIN) ' on failure.
*/
try {
const buffer = Buffer.from(sHex, "hex");
return buffer.toString("ascii");
// Could use utf-8 instead, but it has more edge cases.
// Optionally, sanitize the string for display before returning
} catch (err) {
return "(BIN) " + sHex;
}
}

View File

@@ -18,7 +18,7 @@ dotenv.config();
async function initWallet() {
let seed = process.env.ISSUER_ACCOUNT_SEED;
if (!seed) {
if (!seed || seed.startsWith("<")) {
const { seedInput } = await inquirer.prompt([
{
type: "password",
@@ -89,11 +89,11 @@ async function main() {
URI: credXrpl.uri,
Expiration: credXrpl.expiration,
};
const ccResponse = await client.submit(tx, { autofill: true, wallet });
const ccResponse = await client.submitAndWait(tx, { autofill: true, wallet });
if (ccResponse.result.engine_result === "tecDUPLICATE") {
if (ccResponse.result.meta.TransactionResult === "tecDUPLICATE") {
throw new XRPLTxError(ccResponse, 409);
} else if (ccResponse.result.engine_result !== "tesSUCCESS") {
} else if (ccResponse.result.meta.TransactionResult !== "tesSUCCESS") {
throw new XRPLTxError(ccResponse);
}
@@ -137,6 +137,7 @@ async function main() {
issuer: wallet.address,
credential_type: credential,
},
ledger_index: "validated",
});
const tx = {
@@ -146,12 +147,12 @@ async function main() {
CredentialType: credential,
};
const cdResponse = await client.submit(tx, { autofill: true, wallet });
if (cdResponse.result.engine_result === "tecNO_ENTRY") {
const cdResponse = await client.submitAndWait(tx, { autofill: true, wallet });
if (cdResponse.result.meta.TransactionResult === "tecNO_ENTRY") {
// Usually this won't happen since we just checked for the credential,
// but it's possible it got deleted since then.
throw new XRPLTxError(cdResponse, 404);
} else if (cdResponse.result.engine_result !== "tesSUCCESS") {
} else if (cdResponse.result.meta.TransactionResult !== "tesSUCCESS") {
throw new XRPLTxError(cdResponse);
}

View File

@@ -22,6 +22,7 @@ export async function lookUpCredentials(client, issuer, subject, accepted = "bot
command: "account_objects",
account,
type: "credential",
ledger_index: "validated",
};
// Fetch first page