@0xsequence/ethauth
Advanced tools
Comparing version 0.4.1 to 0.4.2
@@ -18,4 +18,4 @@ import { ethers } from 'ethers'; | ||
configValidators: (...validators: ValidatorFunc[]) => void; | ||
encodeProof: (proof: Proof) => Promise<string>; | ||
decodeProof: (proofString: string) => Promise<Proof>; | ||
encodeProof: (proof: Proof, skipValidation?: boolean) => Promise<string>; | ||
decodeProof: (proofString: string, skipValidation?: boolean) => Promise<Proof>; | ||
validateProof: (proof: Proof) => Promise<boolean>; | ||
@@ -22,0 +22,0 @@ validateProofSignature: (proof: Proof) => Promise<boolean>; |
@@ -255,61 +255,72 @@ import { ethers } from 'ethers'; | ||
}; | ||
this.encodeProof = function (proof) { return __awaiter(_this, void 0, void 0, function () { | ||
var isValid, claimsJSON, proofString; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (proof.address.length !== 42 || proof.address.slice(0, 2) !== '0x') { | ||
throw new Error('ethauth: invalid address'); | ||
} | ||
if (proof.signature === '' || proof.signature.slice(0, 2) !== '0x') { | ||
throw new Error('ethauth: invalid signature'); | ||
} | ||
if (proof.extra && proof.extra.slice(0, 2) !== '0x') { | ||
throw new Error('ethauth: invalid extra encoding, expecting hex data'); | ||
} | ||
return [4 /*yield*/, this.validateProof(proof)]; | ||
case 1: | ||
isValid = _a.sent(); | ||
if (!isValid) { | ||
throw new Error("ethauth: proof is invalid"); | ||
} | ||
claimsJSON = JSON.stringify(proof.claims); | ||
proofString = ETHAuthPrefix + '.' + | ||
proof.address.toLowerCase() + '.' + | ||
base64url.encode(claimsJSON) + '.' + | ||
proof.signature; | ||
if (proof.extra && proof.extra.length > 0) { | ||
proofString += '.' + proof.extra; | ||
} | ||
return [2 /*return*/, proofString]; | ||
} | ||
this.encodeProof = function (proof, skipValidation) { | ||
if (skipValidation === void 0) { skipValidation = false; } | ||
return __awaiter(_this, void 0, void 0, function () { | ||
var isValid, claimsJSON, proofString; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (proof.address.length !== 42 || proof.address.slice(0, 2) !== '0x') { | ||
throw new Error('ethauth: invalid address'); | ||
} | ||
if (proof.signature === '' || proof.signature.slice(0, 2) !== '0x') { | ||
throw new Error('ethauth: invalid signature'); | ||
} | ||
if (proof.extra && proof.extra.slice(0, 2) !== '0x') { | ||
throw new Error('ethauth: invalid extra encoding, expecting hex data'); | ||
} | ||
if (!(skipValidation !== true)) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this.validateProof(proof)]; | ||
case 1: | ||
isValid = _a.sent(); | ||
if (!isValid) { | ||
throw new Error("ethauth: proof is invalid"); | ||
} | ||
_a.label = 2; | ||
case 2: | ||
claimsJSON = JSON.stringify(proof.claims); | ||
proofString = ETHAuthPrefix + '.' + | ||
proof.address.toLowerCase() + '.' + | ||
base64url.encode(claimsJSON) + '.' + | ||
proof.signature; | ||
if (proof.extra && proof.extra.length > 0) { | ||
proofString += '.' + proof.extra; | ||
} | ||
return [2 /*return*/, proofString]; | ||
} | ||
}); | ||
}); | ||
}); }; | ||
this.decodeProof = function (proofString) { return __awaiter(_this, void 0, void 0, function () { | ||
var parts, prefix, address, messageBase64, signature, extra, message, claims, proof, isValid; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
parts = proofString.split('.'); | ||
if (parts.length < 4 || parts.length > 5) { | ||
throw new Error('ethauth: invalid proof string'); | ||
} | ||
prefix = parts[0], address = parts[1], messageBase64 = parts[2], signature = parts[3], extra = parts[4]; | ||
// check prefix | ||
if (prefix !== ETHAuthPrefix) { | ||
throw new Error('ethauth: not an ethauth proof'); | ||
} | ||
message = base64url.decode(messageBase64); | ||
claims = JSON.parse(message); | ||
proof = new Proof({ address: address, claims: claims, signature: signature, extra: extra }); | ||
return [4 /*yield*/, this.validateProof(proof)]; | ||
case 1: | ||
isValid = _a.sent(); | ||
if (!isValid) { | ||
throw new Error("ethauth: proof is invalid"); | ||
} | ||
return [2 /*return*/, proof]; | ||
} | ||
}; | ||
this.decodeProof = function (proofString, skipValidation) { | ||
if (skipValidation === void 0) { skipValidation = false; } | ||
return __awaiter(_this, void 0, void 0, function () { | ||
var parts, prefix, address, messageBase64, signature, extra, message, claims, proof, isValid; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
parts = proofString.split('.'); | ||
if (parts.length < 4 || parts.length > 5) { | ||
throw new Error('ethauth: invalid proof string'); | ||
} | ||
prefix = parts[0], address = parts[1], messageBase64 = parts[2], signature = parts[3], extra = parts[4]; | ||
// check prefix | ||
if (prefix !== ETHAuthPrefix) { | ||
throw new Error('ethauth: not an ethauth proof'); | ||
} | ||
message = base64url.decode(messageBase64); | ||
claims = JSON.parse(message); | ||
proof = new Proof({ address: address, claims: claims, signature: signature, extra: extra }); | ||
if (!(skipValidation !== true)) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this.validateProof(proof)]; | ||
case 1: | ||
isValid = _a.sent(); | ||
if (!isValid) { | ||
throw new Error("ethauth: proof is invalid"); | ||
} | ||
_a.label = 2; | ||
case 2: return [2 /*return*/, proof]; | ||
} | ||
}); | ||
}); | ||
}); }; | ||
}; | ||
this.validateProof = function (proof) { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -316,0 +327,0 @@ var isValidClaims, isValidSig; |
@@ -263,61 +263,72 @@ 'use strict'; | ||
}; | ||
this.encodeProof = function (proof) { return __awaiter(_this, void 0, void 0, function () { | ||
var isValid, claimsJSON, proofString; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (proof.address.length !== 42 || proof.address.slice(0, 2) !== '0x') { | ||
throw new Error('ethauth: invalid address'); | ||
} | ||
if (proof.signature === '' || proof.signature.slice(0, 2) !== '0x') { | ||
throw new Error('ethauth: invalid signature'); | ||
} | ||
if (proof.extra && proof.extra.slice(0, 2) !== '0x') { | ||
throw new Error('ethauth: invalid extra encoding, expecting hex data'); | ||
} | ||
return [4 /*yield*/, this.validateProof(proof)]; | ||
case 1: | ||
isValid = _a.sent(); | ||
if (!isValid) { | ||
throw new Error("ethauth: proof is invalid"); | ||
} | ||
claimsJSON = JSON.stringify(proof.claims); | ||
proofString = ETHAuthPrefix + '.' + | ||
proof.address.toLowerCase() + '.' + | ||
base64url__default['default'].encode(claimsJSON) + '.' + | ||
proof.signature; | ||
if (proof.extra && proof.extra.length > 0) { | ||
proofString += '.' + proof.extra; | ||
} | ||
return [2 /*return*/, proofString]; | ||
} | ||
this.encodeProof = function (proof, skipValidation) { | ||
if (skipValidation === void 0) { skipValidation = false; } | ||
return __awaiter(_this, void 0, void 0, function () { | ||
var isValid, claimsJSON, proofString; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (proof.address.length !== 42 || proof.address.slice(0, 2) !== '0x') { | ||
throw new Error('ethauth: invalid address'); | ||
} | ||
if (proof.signature === '' || proof.signature.slice(0, 2) !== '0x') { | ||
throw new Error('ethauth: invalid signature'); | ||
} | ||
if (proof.extra && proof.extra.slice(0, 2) !== '0x') { | ||
throw new Error('ethauth: invalid extra encoding, expecting hex data'); | ||
} | ||
if (!(skipValidation !== true)) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this.validateProof(proof)]; | ||
case 1: | ||
isValid = _a.sent(); | ||
if (!isValid) { | ||
throw new Error("ethauth: proof is invalid"); | ||
} | ||
_a.label = 2; | ||
case 2: | ||
claimsJSON = JSON.stringify(proof.claims); | ||
proofString = ETHAuthPrefix + '.' + | ||
proof.address.toLowerCase() + '.' + | ||
base64url__default['default'].encode(claimsJSON) + '.' + | ||
proof.signature; | ||
if (proof.extra && proof.extra.length > 0) { | ||
proofString += '.' + proof.extra; | ||
} | ||
return [2 /*return*/, proofString]; | ||
} | ||
}); | ||
}); | ||
}); }; | ||
this.decodeProof = function (proofString) { return __awaiter(_this, void 0, void 0, function () { | ||
var parts, prefix, address, messageBase64, signature, extra, message, claims, proof, isValid; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
parts = proofString.split('.'); | ||
if (parts.length < 4 || parts.length > 5) { | ||
throw new Error('ethauth: invalid proof string'); | ||
} | ||
prefix = parts[0], address = parts[1], messageBase64 = parts[2], signature = parts[3], extra = parts[4]; | ||
// check prefix | ||
if (prefix !== ETHAuthPrefix) { | ||
throw new Error('ethauth: not an ethauth proof'); | ||
} | ||
message = base64url__default['default'].decode(messageBase64); | ||
claims = JSON.parse(message); | ||
proof = new Proof({ address: address, claims: claims, signature: signature, extra: extra }); | ||
return [4 /*yield*/, this.validateProof(proof)]; | ||
case 1: | ||
isValid = _a.sent(); | ||
if (!isValid) { | ||
throw new Error("ethauth: proof is invalid"); | ||
} | ||
return [2 /*return*/, proof]; | ||
} | ||
}; | ||
this.decodeProof = function (proofString, skipValidation) { | ||
if (skipValidation === void 0) { skipValidation = false; } | ||
return __awaiter(_this, void 0, void 0, function () { | ||
var parts, prefix, address, messageBase64, signature, extra, message, claims, proof, isValid; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
parts = proofString.split('.'); | ||
if (parts.length < 4 || parts.length > 5) { | ||
throw new Error('ethauth: invalid proof string'); | ||
} | ||
prefix = parts[0], address = parts[1], messageBase64 = parts[2], signature = parts[3], extra = parts[4]; | ||
// check prefix | ||
if (prefix !== ETHAuthPrefix) { | ||
throw new Error('ethauth: not an ethauth proof'); | ||
} | ||
message = base64url__default['default'].decode(messageBase64); | ||
claims = JSON.parse(message); | ||
proof = new Proof({ address: address, claims: claims, signature: signature, extra: extra }); | ||
if (!(skipValidation !== true)) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this.validateProof(proof)]; | ||
case 1: | ||
isValid = _a.sent(); | ||
if (!isValid) { | ||
throw new Error("ethauth: proof is invalid"); | ||
} | ||
_a.label = 2; | ||
case 2: return [2 /*return*/, proof]; | ||
} | ||
}); | ||
}); | ||
}); }; | ||
}; | ||
this.validateProof = function (proof) { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -324,0 +335,0 @@ var isValidClaims, isValidSig; |
{ | ||
"name": "@0xsequence/ethauth", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"description": "ETHAuth -- self-signed authorization proofs", | ||
@@ -29,10 +29,10 @@ "repository": "https://github.com/0xsequence/ethauth.js", | ||
"@types/jest": "^26.0.18", | ||
"ethers": "^5.0.24", | ||
"ethers": "^5.0.30", | ||
"jest": "^26.6.3", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.34.2", | ||
"rollup": "^2.38.5", | ||
"rollup-plugin-typescript2": "^0.29.0", | ||
"ts-jest": "^26.4.4", | ||
"ts-jest": "^26.5.1", | ||
"ts-node": "^9.1.1", | ||
"typescript": "^4.1.2" | ||
"typescript": "^4.1.5" | ||
}, | ||
@@ -39,0 +39,0 @@ "jest": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49045
880