-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #853 support beneficiary summon links * #853 shifting to base32 for ben component of summon link * #853 use summons when generating a single beneficiary link * #853 adding message to explain the single beneficiary link changes
- Loading branch information
Showing
7 changed files
with
132 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { decode, encode } from "thirty-two"; | ||
|
||
// For single beneficiary summons, the first component of the ID | ||
// is a base 32 (without padding) encoded beneficiary ID. The remaining components | ||
// are the Summon ID | ||
|
||
// throws an error if decoding fails | ||
export const Decode = (smn: string): { id: string; ben?: string } => { | ||
const guidParts = smn.split("-"); | ||
const idIncludesBen = guidParts.length === 6; | ||
if (idIncludesBen) { | ||
let benEnc = guidParts[0]; | ||
while (benEnc.length % 8 !== 0) { | ||
benEnc += "="; | ||
} | ||
return { | ||
id: guidParts.slice(1).join("-"), | ||
ben: decode(benEnc).toString(), | ||
}; | ||
} | ||
return { | ||
id: smn, | ||
}; | ||
}; | ||
|
||
export const Encode = (id: string, ben?: string): string => { | ||
if (ben) { | ||
return `${encode(ben).toString().toLowerCase().replaceAll("=", "")}-${id}`; | ||
} | ||
return id; | ||
}; |