Skip to content

Commit

Permalink
Merge pull request #416 from ERC725Alliance/feat/more-functions
Browse files Browse the repository at this point in the history
feat: export methods for encoding/decoding dataSourceWithHash and valueContent
  • Loading branch information
CJ42 authored Apr 18, 2024
2 parents e564a6e + b1e0ed9 commit eed12b6
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 4 deletions.
66 changes: 64 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,19 @@ import { decodeData } from './lib/decodeData';
import { getDataFromExternalSources } from './lib/getDataFromExternalSources';
import { DynamicKeyPart, DynamicKeyParts } from './types/dynamicKeys';
import { getData } from './lib/getData';
import { decodeValueType, encodeValueType } from './lib/encoder';
import {
encodeDataSourceWithHash,
decodeDataSourceWithHash,
encodeValueType,
decodeValueType,
encodeValueContent,
decodeValueContent,
} from './lib/encoder';
import { internalSupportsInterface, checkPermissions } from './lib/detector';
import { decodeMappingKey } from './lib/decodeMappingKey';
import { encodePermissions, decodePermissions } from './lib/permissions';
import { AssetURLEncode } from './types/encodeData';
import { URLDataToEncode, URLDataWithHash, Verification } from './types';

export {
ERC725JSONSchema,
Expand All @@ -77,9 +86,12 @@ export { decodeData } from './lib/decodeData';
export { encodeKeyName, isDynamicKeyName } from './lib/encodeKeyName';
export { decodeMappingKey } from './lib/decodeMappingKey';
export {
encodeDataSourceWithHash,
decodeDataSourceWithHash,
encodeValueType,
decodeValueType,
encodeValueContent,
decodeValueContent,
encodeValueType,
} from './lib/encoder';
export { getDataFromExternalSources } from './lib/getDataFromExternalSources';
export { encodePermissions, decodePermissions } from './lib/permissions';
Expand Down Expand Up @@ -646,6 +658,28 @@ export class ERC725 {
return checkPermissions(requiredPermissions, grantedPermissions);
}

encodeDataSourceWithHash(
verification: undefined | Verification,
dataSource: string,
): string {
return encodeDataSourceWithHash(verification, dataSource);
}

static encodeDataSourceWithHash(
verification: undefined | Verification,
dataSource: string,
): string {
return encodeDataSourceWithHash(verification, dataSource);
}

decodeDataSourceWithHash(value: string): URLDataWithHash {
return decodeDataSourceWithHash(value);
}

static decodeDataSourceWithHash(value: string): URLDataWithHash {
return decodeDataSourceWithHash(value);
}

/**
* @param type The valueType to encode the value as
* @param value The value to encode
Expand Down Expand Up @@ -677,6 +711,34 @@ export class ERC725 {
decodeValueType(type: string, data: string) {
return decodeValueType(type, data);
}

static encodeValueContent(
valueContent: string,
value: string | number | AssetURLEncode | URLDataToEncode | boolean,
): string | false {
return encodeValueContent(valueContent, value);
}

encodeValueContent(
valueContent: string,
value: string | number | AssetURLEncode | URLDataToEncode | boolean,
): string | false {
return encodeValueContent(valueContent, value);
}

static decodeValueContent(
valueContent: string,
value: string,
): string | URLDataWithHash | number | boolean | null {
return decodeValueContent(valueContent, value);
}

decodeValueContent(
valueContent: string,
value: string,
): string | URLDataWithHash | number | boolean | null {
return decodeValueContent(valueContent, value);
}
}

export default ERC725;
4 changes: 2 additions & 2 deletions src/lib/encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const BytesNValueContentRegex = /Bytes(\d+)/;

const ALLOWED_BYTES_SIZES = [2, 4, 8, 16, 32, 64, 128, 256];

const encodeDataSourceWithHash = (
export const encodeDataSourceWithHash = (
verification: undefined | Verification,
dataSource: string,
): string => {
Expand All @@ -94,7 +94,7 @@ const encodeDataSourceWithHash = (
].join('');
};

const decodeDataSourceWithHash = (value: string): URLDataWithHash => {
export const decodeDataSourceWithHash = (value: string): URLDataWithHash => {
if (value.slice(0, 6) === '0x0000') {
// DEAL with VerifiableURI
// NOTE: A JSONURL with a 0x00000000 verification method is invalid.
Expand Down

0 comments on commit eed12b6

Please sign in to comment.