Skip to content

Commit

Permalink
Update EIP-5289: Use Base 64 (#5567)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pandapip1 authored Aug 31, 2022
1 parent c1cf810 commit 4f37566
Showing 1 changed file with 55 additions and 4 deletions.
59 changes: 55 additions & 4 deletions EIPS/eip-5289.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,67 @@ See [`IERC5289Library`](../assets/eip-5289/interfaces/IERC5289Library.sol).
To request that certain documents be signed, revert with the following reason:

```solidity
string.concat("5289:", libraryAddress1, "-", documentId1OfAddress1, "-", documentId2OfAddress1 ",", libraryAddress2, "-", documentId2, ...)
string.concat("5289:", libraryAddress1, "-", documentId1OfAddress1, "-", documentId2OfAddress1 ",", libraryAddress2, "-", documentId1OfAddress2, ...)
```

NOTE: If an address begins with one or more zeros, they may be omitted.
NOTE 2: The document IDs are represented in hexadecimal.
NOTE: If an address begins with one or more zeros, they may be omitted. Addresses are represented in base 64.
NOTE 2: The document IDs are represented in base 64.

Example:

```solidity
"5289:0x1-1-2,0xdead-7b3"
"5289:1-1-2,hEl/0-7bA"
```

#### Base 64

From RFC 4648:

```text
Table 1: The Base 64 Alphabet
Value Encoding Value Encoding Value Encoding Value Encoding
0 A 17 R 34 i 51 z
1 B 18 S 35 j 52 0
2 C 19 T 36 k 53 1
3 D 20 U 37 l 54 2
4 E 21 V 38 m 55 3
5 F 22 W 39 n 56 4
6 G 23 X 40 o 57 5
7 H 24 Y 41 p 58 6
8 I 25 Z 42 q 59 7
9 J 26 a 43 r 60 8
10 K 27 b 44 s 61 9
11 L 28 c 45 t 62 +
12 M 29 d 46 u 63 /
13 N 30 e 47 v
14 O 31 f 48 w (pad) =
15 P 32 g 49 x
16 Q 33 h 50 y
```

NOTE: Padding is NOT used.

Here is a TypeScript snippet to convert `Number` objects into base 64 strings and back.

```typescript
const digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/";

function toB64(x: Number): string {
return x
.toString(2)
.split(/(?=(?:.{6})+(?!.))/g)
.map(bin => parseInt(bin, 2))
.map(digit => digits[digit])
.join("");
}

function fromB64(x: string): Number {
return Number.parseInt(
x.split("").reduce((bin, digit) => bin + new Number(digits.indexOf(digit)).toString(2).padStart(6, '0'), ""),
2
);
}
```

### Signing a Document
Expand Down

0 comments on commit 4f37566

Please sign in to comment.