add sharing & copying instructions when asking contacts for help, and list all the visibleTo DIDs with an English description of their path

This commit is contained in:
2024-01-21 15:16:39 -07:00
parent dcfa8d9451
commit 1053b78ab8
6 changed files with 130 additions and 25 deletions

View File

@@ -174,21 +174,21 @@ export function isEmptyOrHiddenDid(did?: string) {
* Similar logic is found in endorser-mobile.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function testRecursivelyOnString(func: (arg0: any) => boolean, input: any) {
function testRecursivelyOnStrings(func: (arg0: any) => boolean, input: any) {
if (Object.prototype.toString.call(input) === "[object String]") {
return func(input);
} else if (input instanceof Object) {
if (!Array.isArray(input)) {
// it's an object
for (const key in input) {
if (testRecursivelyOnString(func, input[key])) {
if (testRecursivelyOnStrings(func, input[key])) {
return true;
}
}
} else {
// it's an array
for (const value of input) {
if (testRecursivelyOnString(func, value)) {
if (testRecursivelyOnStrings(func, value)) {
return true;
}
}
@@ -201,7 +201,7 @@ function testRecursivelyOnString(func: (arg0: any) => boolean, input: any) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function containsHiddenDid(obj: any) {
return testRecursivelyOnString(isHiddenDid, obj);
return testRecursivelyOnStrings(isHiddenDid, obj);
}
export function stripEndorserPrefix(claimId: string) {

View File

@@ -99,13 +99,17 @@ export const canFulfillOffer = (veriClaim: GenericServerRecord) => {
export function findAllVisibleToDids(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
input: any,
humanReadable = false,
): Record<string, Array<string>> {
if (Array.isArray(input)) {
const result: Record<string, Array<string>> = {};
for (let i = 0; i < input.length; i++) {
const inside = findAllVisibleToDids(input[i]);
const inside = findAllVisibleToDids(input[i], humanReadable);
for (const key in inside) {
result["[" + i + "]" + key] = inside[key];
const pathKey = humanReadable
? "#" + (i + 1) + " " + key
: "[" + i + "]" + key;
result[pathKey] = inside[key];
}
}
return result;
@@ -115,11 +119,15 @@ export function findAllVisibleToDids(
for (const key in input) {
if (key.endsWith("VisibleToDids")) {
const newKey = key.slice(0, -"VisibleToDids".length);
result["." + newKey] = input[key];
const pathKey = humanReadable ? newKey : "." + newKey;
result[pathKey] = input[key];
} else {
const inside = findAllVisibleToDids(input[key]);
const inside = findAllVisibleToDids(input[key], humanReadable);
for (const insideKey in inside) {
result["." + key + insideKey] = inside[insideKey];
const pathKey = humanReadable
? key + "'s " + insideKey
: "." + key + insideKey;
result[pathKey] = inside[insideKey];
}
}
}
@@ -135,7 +143,10 @@ export function findAllVisibleToDids(
pkgx +deno.land sh
deno
import * as R from 'ramda';
//import { findAllVisibleToDids } from './src/libs/util'; // doesn't work because other dependencies fail so gotta copy-and-paste function
console.log(R.equals(findAllVisibleToDids(null), {}));
console.log(R.equals(findAllVisibleToDids(9), {}));