Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npm prefix token support #200

Closed
azu opened this issue Sep 24, 2021 · 1 comment · Fixed by #201
Closed

npm prefix token support #200

azu opened this issue Sep 24, 2021 · 1 comment · Fixed by #201
Labels
Status: PR Welcome Welcome to Pull Request Status: Proposal Request for comments

Comments

@azu
Copy link
Member

azu commented Sep 24, 2021

Summary

new npm token use npm prefix.
We should support new npm token format.

npm has a new access token format | GitHub Changelog

Basic example

(IT IS DUMMY)

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
npm_     qkJaB6MffYVzZXWqmcoF49yrUxP3wf     0LsakP

prefix     Token    CRC32

Related

GitHub Token is similar approach #153

@azu azu added Status: PR Welcome Welcome to Pull Request Status: Proposal Request for comments labels Sep 24, 2021
@azu
Copy link
Member Author

azu commented Sep 24, 2021

// https://gist.github.com/kevinyan815/f71b2f5ca3541631abd2e50f3929739b
function toBase62(n) {
    if (n === 0) {
        return '0';
    }
    const digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
    let result = '';
    while (n > 0) {
        result = digits[n % digits.length] + result;
        n = parseInt(n / digits.length, 10);
    }
    
    return result;
}

//https://stackoverflow.com/a/18639999
const crc32 = function (str) {
    const makeCRCTable = function () {
        var c;
        var crcTable = [];
        for (var n = 0; n < 256; n++) {
            c = n;
            for (var k = 0; k < 8; k++) {
                c = ((c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
            }
            crcTable[n] = c;
        }
        return crcTable;
    };
    const crcTable = makeCRCTable();
    let crc = 0 ^ (-1);
    for (let i = 0; i < str.length; i++) {
        crc = (crc >>> 8) ^ crcTable[(crc ^ str.charCodeAt(i)) & 0xFF];
    }
    return (crc ^ (-1)) >>> 0;
};

console.log(toBase62(crc32("qkJaB6MffYVzZXWqmcoF49yrUxP3wf")).padStart(6, "0")); // "0LsakP"

minimal implementation for CRC32.
I do not know that this base62 encoding does not match upper-case and lower-case.

TODO

  • npm and GitHub use same base62 table?
  • Should we make it option?

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: PR Welcome Welcome to Pull Request Status: Proposal Request for comments
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant