This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from qutip import * | |
%matplotlib inline | |
import matplotlib.pyplot as plt | |
import numpy as np | |
from IPython.display import Image | |
tau = 1. | |
J = 4e-1 | |
A = 0.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0xDa514178E98109226C4890Af75f533A452133eA9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// /imports/startup/server/twoFactorAuthServer.js | |
import { Meteor } from 'meteor/meteor'; | |
import { Accounts } from 'meteor/accounts-base'; | |
import SimpleSchema from 'simpl-schema'; | |
import otplib from 'otplib'; | |
import { TwoFactorToken } from '/imports/api/methods/twoFactorAuth'; | |
// Invalidate password login attempt, if 2FA is enabled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// /imports/api/methods/twoFactorAuth.js | |
import { Meteor } from 'meteor/meteor'; | |
import { ValidatedMethod } from 'meteor/mdg:validated-method'; | |
import otplib from 'otplib'; | |
const userIsLoggedIn = (userId: string) => { | |
if (!userId) { | |
throw new Meteor.Error('users.not-authorized'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// /imports/api/methods/twoFactorAuth.js | |
import SimpleSchema from 'simpl-schema'; | |
export const TwoFactorToken = { | |
type: SimpleSchema.Integer, min: 0, max: 999999, optional: true, | |
}; | |
export const tokenIsValid = (token: string, secret: string) => { | |
if (!otplib.authenticator.check(token, secret)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Accounts } from 'meteor/accounts-base'; | |
class LoginForm extends React.Component { | |
state = { | |
email: '', | |
password: '', | |
token: '', | |
requiresTwoFactor: false, | |
loading: false, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { sign } from 'tweetnacl'; | |
import { Buffer } from 'buffer'; | |
const secretKey = Buffer.from('…', 'base64'); | |
const generateCertificateForDocument = | |
(filename: string, sha256: string, user: string, email: string, userId: string, companyId: string, createdByLedgy: boolean): string => { | |
const certificate = JSON.stringify({ | |
filename, sha256, user, email, company, createdByLedgy, userId, companyId, version: '1.0.0', | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import OTS from 'javascript-opentimestamps'; | |
import { getOtsFromCertificate, encodeOts } from './helpers.js'; | |
export const stampCertificate = async (certificate: string): Promise<string> => { | |
const ots = getOtsFromCertificate(certificate); | |
await OTS.stamp(ots); | |
return encodeOts(ots); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import OTS from 'javascript-opentimestamps'; | |
import { SHA256, getOtsFromCertificate, decodeOts } from './helpers.js'; | |
const publicKey = Buffer.from('fTrOd0HG8opCEgb+dXvNUXQmzPQqyMGC/IQinDJof1g=', 'base64'); | |
const verifyDocumentOnBlockchain = async (certificate: string, ots: string, docUrl: string) => { | |
const verifiedCertificate = sign.open(Buffer.from(certificate, 'base64'), publickKey); | |
if (!verifiedCertificate) { | |
throw new Error('WARNING: Certificate is invalid'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const hexToBytes = (hex: string): Array<number> => { | |
const bytes = []; | |
for (let c = 0; c < hex.length; c += 2) { | |
bytes.push(parseInt(hex.substr(c, 2), 16)); | |
} | |
return bytes; | |
}; | |
export const SHA256 = async (doc: ArrayBuffer): Promise<string> => ( | |
crypto ? |
OlderNewer