File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ export const extractProjectIdFromAccessKey = ( accessKey : string ) : number => {
2+ // Convert URL-safe base64 string to standard base64 string
3+ const base64String = accessKey . replace ( / - / g, '+' ) . replace ( / _ / g, '/' ) ;
4+ // Decode the base64 string to a binary string
5+ const binaryString = atob ( base64String ) ;
6+
7+ // Convert the binary string to a byte array (Uint8Array)
8+ const byteArray = new Uint8Array ( binaryString . length ) ;
9+ for ( let i = 0 ; i < binaryString . length ; i ++ ) {
10+ byteArray [ i ] = binaryString . charCodeAt ( i ) ;
11+ }
12+
13+ if ( byteArray [ 0 ] !== 1 ) {
14+ throw new Error ( 'UnsupportedVersion' ) ;
15+ }
16+
17+ // Extract the project ID from bytes 2 to 9 (8 bytes)
18+ const projectIdBytes = byteArray . slice ( 1 , 9 ) ;
19+ const projectId = projectIdBytes [ 7 ] | projectIdBytes [ 6 ] << 8 | projectIdBytes [ 5 ] << 16 | projectIdBytes [ 4 ] << 24 |
20+ projectIdBytes [ 3 ] << 32 | projectIdBytes [ 2 ] << 40 | projectIdBytes [ 1 ] << 48 | projectIdBytes [ 0 ] << 56 ;
21+
22+ return projectId ;
23+ }
Original file line number Diff line number Diff line change 1+ export * from './access-key'
12export * from './base64'
23export * from './big-number'
34export * from './digest'
Original file line number Diff line number Diff line change 1+ import { expect } from 'chai'
2+ import { extractProjectIdFromAccessKey } from '@0xsequence/utils'
3+
4+ describe ( 'access-key' , function ( ) {
5+ it ( 'extractProjectIdFromAccessKey' , ( ) => {
6+ const accessKey = 'AQAAAAAAADVH8R2AGuQhwQ1y8NaEf1T7PJM'
7+
8+ const projectId = extractProjectIdFromAccessKey ( accessKey )
9+ expect ( projectId ) . to . equal ( 13639 )
10+ } )
11+ } )
You can’t perform that action at this time.
0 commit comments