Skip to content

Commit

Permalink
revert: changes on identifier (#11441)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Works committed Apr 28, 2024
1 parent 58f0ab5 commit c198cc3
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions packages/base/src/Identifier/identifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ export class ECKeyIdentifier extends Identifier {
)
}
declare [Symbol.toStringTag]: string
#ec: undefined
static [Symbol.hasInstance](x: any): boolean {
return toText(x)?.startsWith('ec_key:') ?? false
return typeof x === 'object' && x !== null && #ec in x
}
static {
ECKeyIdentifier.prototype[Symbol.toStringTag] = 'ECKeyIdentifier'
Expand Down Expand Up @@ -183,8 +184,9 @@ export class PostIVIdentifier extends Identifier {
return new Uint8Array(decodeArrayBuffer(x))
}
declare [Symbol.toStringTag]: string
#post_iv: undefined
static [Symbol.hasInstance](x: any): boolean {
return toText(x)?.startsWith('post_iv:') ?? false
return typeof x === 'object' && x !== null && #post_iv in x
}
static {
PostIVIdentifier.prototype[Symbol.toStringTag] = 'PostIVIdentifier'
Expand Down Expand Up @@ -232,8 +234,9 @@ export class PostIdentifier extends Identifier {
return this.postID
}
declare [Symbol.toStringTag]: string
#post: undefined
static [Symbol.hasInstance](x: any): boolean {
return toText(x)?.startsWith('post:') ?? false
return typeof x === 'object' && x !== null && #post in x
}
static {
PostIdentifier.prototype[Symbol.toStringTag] = 'PostIdentifier'
Expand Down Expand Up @@ -290,8 +293,9 @@ export class ProfileIdentifier extends Identifier {
return `person:${this.network}/${this.userId}`
}
declare [Symbol.toStringTag]: string
#profile: undefined
static [Symbol.hasInstance](x: any): boolean {
return toText(x)?.startsWith('person:') ?? false
return typeof x === 'object' && x !== null && #profile in x
}
static {
ProfileIdentifier.prototype[Symbol.toStringTag] = 'ProfileIdentifier'
Expand All @@ -311,13 +315,3 @@ function banSlash(input: string | undefined | null, source?: string) {
if (!input) return
if (input.includes('/')) throw new TypeError(`Cannot contain / in a part of identifier (${source}): ${input}`)
}

function toText(x: any) {
try {
const text = x.toText()
if (typeof text === 'string') return text
return
} catch {
return
}
}

0 comments on commit c198cc3

Please sign in to comment.