@dingrtc/token-generator
Advanced tools
+1
-1
@@ -1,1 +0,1 @@ | ||
| "use strict";const{AppToken:e}=require("./app_token"),{Service:o}=require("./service"),{AppTokenOptions:t}=require("./app_token_options");module.exports={produce:(n,i,r,s)=>{const p=new o(r,s);p.addVideoPublishPrivilege();const c=new t;c.setEngineOptions({k1:"v1",k2:"v2"});const u=Math.floor(Date.now()/1e3);let d=new e(n,i,u);d.setOptions(c),d.setService(p);return d.build()}}; | ||
| "use strict";var t=require("buffer"),e=require("crypto"),r=require("zlib");function i(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var s={};const n=e;var o={sign:function(t,e){return n.createHmac("sha256",t).update(e).digest()},generateSign:function(t,e,r){const i=Buffer.alloc(4);i.writeUInt32BE(e,0);const s=n.createHmac("sha256",i).update(t).digest(),o=Buffer.alloc(4);return o.writeUInt32BE(r,0),n.createHmac("sha256",o).update(s).digest()}},f={};let a=class{constructor(t){this.buffer=Buffer.alloc(t),this.writeOffset=0,this.readOffset=0}ensureCapacity(t){const e=this.writeOffset+t;if(e>this.buffer.length){const t=function(t,e){if(0>=t)return 0;let r=e;for(;t>r;)r*=2;return r}(e,256),r=Buffer.alloc(t);this.buffer.copy(r),this.buffer=r}}nextMultiple(t,e){if(0>=e||0>=t)return 0;let r=e;for(;t>r;)r*=2;return r}readBool(){return!!this.readInt8()}readInt8(){return this.readInt(1)}readInt32(){return this.readInt(4)}readInt(t){let e;if(4===t)e=this.buffer.readInt32BE(this.readOffset);else{if(1!==t)throw Error("Unsupported integer size");e=this.buffer.readInt8(this.readOffset)}return this.readOffset+=t,e}readString(){const t=this.readInt32(),e=this.buffer.toString("utf8",this.readOffset,this.readOffset+t);return this.readOffset+=t,e}readBytes(t){const e=this.buffer.slice(this.readOffset,this.readOffset+t);return this.readOffset+=t,e}writeBool(t){this.writeInt8(t?1:0)}writeInt8(t){this.writeInt(t,1)}writeInt32(t){this.writeInt(t,4)}writeInt(t,e){if(this.ensureCapacity(e),4===e)this.buffer.writeInt32BE(t,this.writeOffset);else{if(1!==e)throw Error("Unsupported integer size");this.buffer.writeInt8(t,this.writeOffset)}this.writeOffset+=e}writeString(t){const e=Buffer.byteLength(t,"utf-8");this.writeInt32(e),this.ensureCapacity(e),this.writeBytes(t)}writeBytes(t){const e=Buffer.byteLength(t,"utf-8");this.ensureCapacity(e),Buffer.isBuffer(t)||(t=Buffer.from(t)),t.copy(this.buffer,this.writeOffset),this.writeOffset+=e}getvalue(t=!1){if(t&&this.buffer.length>this.writeOffset){const t=Buffer.alloc(this.writeOffset);return this.buffer.copy(t),t}return this.buffer}};f.ByteBuffer=a,f.ReadonlyByteBuffer=class extends a{constructor(t){super(t.length),this.buffer=t,this.writeOffset=t.length,this.readOffset=0}writeInt(){throw Error("Unsupported write mode")}writeString(){throw Error("Unsupported write mode")}writeBytes(){throw Error("Unsupported write mode")}};var u={};const{ByteBuffer:h}=f;u.AppTokenOptions=class t{static unpack(e){if(!e.readBool())return new t;const r={},i=e.readInt32();for(let t=0;i>t;t++){const t=e.readString(),i=e.readString();r[t]=i}return new t(r)}constructor(t={}){this.engineOptions=t}setEngineOptions(t){this.engineOptions=null!=t?t:{}}pack(){const t=new h(0),e=null!==this.engineOptions;if(t.writeBool(e),e){const e=Object.entries(this.engineOptions).sort();t.writeInt32(e.length);for(const[r,i]of e){if(null==r||null==i)throw Error("Illegal engineOptions entry");t.writeString(r),t.writeString(i)}}return t.getvalue(!0)}};const c=r;var l={compress:function(t){return c.deflateSync(t)},decompress:function(t){return c.inflateSync(t)}},p={};const{ByteBuffer:w}=f;p.Service=class t{static unpack(e){const r=e.readString(),i=e.readString(),s=1==e.readInt8()?e.readInt32():null;return new t(r,i,s)}static createServiceOnlyWithUserId(t){return new this("*",t)}static createServiceOnlyWithChannelId(t){return new this(t,"*")}constructor(t,e,r=null){this.channelId=t,this.userId=e,this.privilege=r}addAudioPublishPrivilege(){this.privilege=this.privilege||1,this.privilege|=this.ENABLE_AUDIO_PRIVILEGE}addVideoPublishPrivilege(){this.privilege=this.privilege||1,this.privilege|=4}pack(){const t=new w(0);t.writeString(this.channelId),t.writeString(this.userId);const e=null!==this.privilege;return t.writeBool(e),e&&t.writeInt32(this.privilege),t.getvalue(!0)}};const{Buffer:d}=t,g=o,I=f,{AppTokenOptions:B}=u,y=l,{Service:v}=p;s.AppToken=class t{static parse(e){if(!e)throw Error("empty token");if(!e.startsWith("000"))throw Error("unsupported version");let r=y.decompress(d.from(e.slice(3),"base64"));r=new I.ReadonlyByteBuffer(r);const i=r.readInt32(),s=r.readBytes(i),n=r.readString(),o=r.readInt32(),f=r.readInt32(),a=r.readInt32(),u=v.unpack(r),h=B.unpack(r);return new t(n,null,a,o,f,u,h,s)}constructor(t,e,r,i=null,s=null,n=null,o=null,f=null){this.appId=t,this.appKey=e,this.timestamp=r,this.issueTimestamp=i||Math.floor(Date.now()/1e3),this.salt=s||Math.floor(Math.random()*this.issueTimestamp),this.service=n,this.options=o||new B,this.signature=f}setOptions(t){this.options=t||new B}setService(t){if(!t)throw Error("missing service");this.service=t}build(){if(!this.appKey)throw Error("missing secretKey");if(!this.service)throw Error("missing service");const t=g.generateSign(this.appKey,this.issueTimestamp,this.salt),e=new I.ByteBuffer(0);e.writeString(this.appId),e.writeInt32(this.issueTimestamp),e.writeInt32(this.salt),e.writeInt32(this.timestamp),e.writeBytes(this.service.pack()),e.writeBytes(this.options.pack());const r=g.sign(t,e.getvalue()),i=new I.ByteBuffer(0);return i.writeInt32(r.length),i.writeBytes(r),i.writeBytes(e.getvalue()),"000"+y.compress(i.getvalue()).toString("base64")}validate(t){if(!t)throw Error("missing secretKey");const e=g.generateSign(t,this.issueTimestamp,this.salt),r=new I.ByteBuffer(0);r.writeString(this.appId),r.writeInt32(this.issueTimestamp),r.writeInt32(this.salt),r.writeInt32(this.timestamp),r.writeBytes(this.service.pack()),r.writeBytes(this.options.pack());const i=g.sign(e,r.getvalue());return 0==d.compare(this.signature,i)}};const{AppToken:O}=s,{Service:m}=p,{AppTokenOptions:b}=u;var S={produce:(t,e,r,i)=>{const s=new m(r,i);s.addVideoPublishPrivilege();const n=new b;n.setEngineOptions({k1:"v1",k2:"v2"});const o=Math.floor(Date.now()/1e3);let f=new O(t,e,o);f.setOptions(n),f.setService(s);return f.build()}};module.exports=i(S); |
+6
-2
| { | ||
| "name": "@dingrtc/token-generator", | ||
| "version": "1.0.0-beta.1", | ||
| "version": "1.0.0-beta.2", | ||
| "description": "dingRTC token generator", | ||
@@ -8,3 +8,3 @@ "main": "./dist/index.js", | ||
| "scripts": { | ||
| "build": "rollup -c --bundleConfigAsCjs" | ||
| "build": "rollup -c" | ||
| }, | ||
@@ -18,3 +18,7 @@ "files": [ | ||
| "access": "public" | ||
| }, | ||
| "repository": "git@gitlab.alibaba-inc.com:dingtalk-iot/oneRTC.git", | ||
| "devDependencies": { | ||
| "rollup-plugin-node-builtins": "^2.1.2" | ||
| } | ||
| } |
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
7334
330.15%32
190.91%1
Infinity%