Class PaperKeyEncoding
Encoder / Decoder for PaperKeys
Defined in: PaperKeyEncoding.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Create a PaperKey encoder/decoder
|
Method Attributes | Method Name and Description |
---|---|
decodeSegment(segment, str)
Decode an 8 byte segment from 12 input characters.
|
|
<static> |
PaperKeyEncoding.dumpKey(data)
Dump a key
|
encodeSegment(segment, data)
Encode an 8 byte segment in human readable form.
|
|
<static> |
PaperKeyEncoding.formatSegment(str)
Format a segment by splitting the input after each 4 characters and inserting " - "
|
Method Detail
{ByteString}
decodeSegment(segment, str)
Decode an 8 byte segment from 12 input characters.
Characters not in the alphabet are ignored.
Throws GPError with GPError.INVALID_LENGTH if the input does not contain at least 12 usable characters.
Throws GPError with GPError.SIGNATURE_FAILED if the check digit based validation fails.
Throws GPError with GPError.INVALID_DATA if the segment number does not match the expected value.
- Parameters:
- {Number} segment
- {String} str
- the user input
- Returns:
- the 8 byte segment
<static>
{String}
PaperKeyEncoding.dumpKey(data)
Dump a key
- Parameters:
- {ByteString} data
- the key value (length must be a multiple of 8)
- Returns:
- the formatted key with 3 groups of 4 digits per line
{String}
encodeSegment(segment, data)
Encode an 8 byte segment in human readable form.
Based on BASE64 encoding with visually confusable characters replaced.
I is replaced by !
O is replaced by *
l is replaced by %
A LUHN-64 character is appended.
A segment identifier is encoded in 2 bit at the end of the encoded 64 bit string.
- Parameters:
- {Number} segment
- {ByteString} data
- Returns:
- the encoded string
<static>
{String}
PaperKeyEncoding.formatSegment(str)
Format a segment by splitting the input after each 4 characters and inserting " - "
- Parameters:
- {String} str
- the unformatted string
- Returns:
- the formatted string