This file contains hidden or 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 { data } = await axios.post( | |
| "/login", | |
| { | |
| address, | |
| signature, | |
| }, | |
| { | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| }, |
This file contains hidden or 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
| 'use strict'; | |
| const headers = { | |
| 'Access-Control-Allow-Origin': '*', | |
| 'Access-Control-Allow-Credentials': true, | |
| }; | |
| module.exports.handler = async (event) => { | |
| const { | |
| queryStringParameters: { name }, | |
| } = event; |
This file contains hidden or 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
| Hello: | |
| handler: src/hello/index.handler | |
| events: | |
| - http: | |
| path: hello | |
| method: get | |
| cors: true | |
| authorizer: aws_iam |
This file contains hidden or 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
| 'use strict'; | |
| const AWS = require('aws-sdk'); | |
| const dynamo = new AWS.DynamoDB(); | |
| const dynamoClient = new AWS.DynamoDB.DocumentClient(); | |
| const cognitoidentity = new AWS.CognitoIdentity(); | |
| const crypto = require('crypto'); | |
| const Web3 = require('web3'); | |
| const headers = { |
This file contains hidden or 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
| functions: | |
| Login: | |
| handler: src/login/index.handler | |
| events: | |
| - http: | |
| path: login | |
| method: post | |
| cors: true | |
This file contains hidden or 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 getCredentials = (identityId, cognitoOpenIdToken) => { | |
| const params = { | |
| IdentityId: identityId, | |
| Logins: {}, | |
| }; | |
| params.Logins['cognito-identity.amazonaws.com'] = cognitoOpenIdToken; | |
| return cognitoidentity.getCredentialsForIdentity(params).promise(); | |
| }; |
This file contains hidden or 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 Web3 = require('web3'); | |
| const getIdToken = (address) => { | |
| const param = { | |
| IdentityPoolId: process.env.IDENTITY_POOL_ID, | |
| Logins: {}, | |
| }; | |
| param.Logins[process.env.DEVELOPER_PROVIDER_NAME] = address; | |
| return cognitoidentity.getOpenIdTokenForDeveloperIdentity(param).promise(); | |
| }; |
This file contains hidden or 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
| CognitoIdentityPool: | |
| Type: AWS::Cognito::IdentityPool | |
| Properties: | |
| AllowUnauthenticatedIdentities: false | |
| IdentityPoolName: "${self:service.name}IdentityPool" | |
| DeveloperProviderName: "${self:custom.customProviderName}" | |
| CognitoAuthorizedRole: | |
| Type: "AWS::IAM::Role" | |
| Properties: |
This file contains hidden or 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 validateSig = async (address, signature, nonce) => { | |
| const message = `Welcome message, nonce: ${nonce}`; | |
| const hash = web3.utils.sha3(message); | |
| const signing_address = await web3.eth.accounts.recover(hash, signature); | |
| return signing_address.toLowerCase() === address.toLowerCase(); | |
| }; |
This file contains hidden or 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
| iamRoleStatements: | |
| - Effect: "Allow" | |
| Action: | |
| - "dynamodb:GetItem" | |
| - "dynamodb:PutItem" | |
| - "dynamodb:UpdateItem" | |
| - "dynamodb:ExecuteStatement" | |
| - "dynamodb:PartiQLSelect" | |
| Resource: | |
| - "Fn::GetAtt": [UserTable, Arn] |