-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
518 additions
and
426 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
186 changes: 0 additions & 186 deletions
186
packages/credential-sdk/src/types/did/document/verification-method copy.js
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,27 +1,62 @@ | ||
import withFrom from './with-from'; | ||
import { decodeFromBase58, encodeAsBase58 } from '../../utils/base-x'; | ||
import { | ||
decodeFromBase58, encodeAsBase58, isEqualToOrPrototypeOf, u8aToString, stringToU8a, maybeToJSONString, | ||
} from '../../utils'; | ||
import TypedEnum from './typed-enum'; | ||
|
||
export default function withBase58(klass) { | ||
const name = `withBase58(${klass.name})`; | ||
const obj = { | ||
[name]: class extends klass { | ||
toString() { | ||
return this.toBase58(); | ||
} | ||
|
||
toJSON() { | ||
return String(this); | ||
} | ||
|
||
static fromBase58(str) { | ||
return this.from(decodeFromBase58(str)); | ||
} | ||
|
||
toBase58() { | ||
return encodeAsBase58(this.bytes); | ||
} | ||
}, | ||
}; | ||
|
||
return withFrom(obj[name], function from(value, fromFn) { return (typeof value === 'string' ? this.fromBase58(value) : fromFn(value)); }); | ||
let res; | ||
|
||
if (!isEqualToOrPrototypeOf(TypedEnum, klass)) { | ||
const obj = { | ||
[name]: class extends klass { | ||
toString() { | ||
return this.toBase58(); | ||
} | ||
|
||
toJSON() { | ||
return String(this); | ||
} | ||
|
||
static fromBase58(str) { | ||
return this.from(decodeFromBase58(str)); | ||
} | ||
|
||
toBase58() { | ||
return encodeAsBase58(this.bytes); | ||
} | ||
}, | ||
}; | ||
|
||
res = obj[name]; | ||
} else { | ||
const obj = { | ||
[name]: class extends klass { | ||
static Class = klass.Class; | ||
|
||
static Variants = !klass.Class ? klass.Variants?.map(withBase58) : klass.Variants; | ||
|
||
toString() { | ||
return this.toBase58(); | ||
} | ||
|
||
static fromBase58(str) { | ||
return this.fromJSON(JSON.parse(u8aToString(decodeFromBase58(str)))); | ||
} | ||
|
||
toBase58() { | ||
return encodeAsBase58(this.bytes); | ||
} | ||
|
||
get bytes() { | ||
return stringToU8a(maybeToJSONString(this)); | ||
} | ||
}, | ||
}; | ||
|
||
res = obj[name]; | ||
} | ||
|
||
return withFrom(res, function from(value, fromFn) { return (typeof value === 'string' ? this.fromBase58(value) : fromFn(value)); }); | ||
} |
Oops, something went wrong.